1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-09 11:51:02 -05:00
v2fly/common/log/access_test.go

35 lines
848 B
Go
Raw Normal View History

2015-10-10 17:41:45 -04:00
package log
import (
"io/ioutil"
"os"
"strings"
"testing"
"time"
"github.com/v2ray/v2ray-core/testing/unit"
)
func TestAccessLog(t *testing.T) {
assert := unit.Assert(t)
filename := "/tmp/test_access_log.log"
InitAccessLogger(filename)
_, err := os.Stat(filename)
assert.Error(err).IsNil()
Access("test_from", "test_to", AccessAccepted, "test_reason")
<-time.After(2 * time.Second)
accessLoggerInstance.(*fileAccessLogger).close()
accessLoggerInstance = &noOpAccessLogger{}
content, err := ioutil.ReadFile(filename)
assert.Error(err).IsNil()
assert.Bool(strings.Contains(string(content), "test_from")).IsTrue()
assert.Bool(strings.Contains(string(content), "test_to")).IsTrue()
assert.Bool(strings.Contains(string(content), "test_reason")).IsTrue()
assert.Bool(strings.Contains(string(content), "accepted")).IsTrue()
}