1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-08 20:19:10 -04:00
v2fly/common/log/access_test.go

37 lines
972 B
Go
Raw Normal View History

2015-10-10 17:41:45 -04:00
package log
import (
"io/ioutil"
"os"
"testing"
"time"
2015-12-05 15:10:14 -05:00
"github.com/v2ray/v2ray-core/common/serial"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
2015-10-10 17:41:45 -04:00
)
func TestAccessLog(t *testing.T) {
v2testing.Current(t)
2015-10-10 17:41:45 -04:00
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)
2015-12-05 15:10:14 -05:00
accessLoggerInstance.(*fileLogWriter).close()
accessLoggerInstance = &noOpLogWriter{}
2015-10-10 17:41:45 -04:00
content, err := ioutil.ReadFile(filename)
assert.Error(err).IsNil()
2015-12-05 15:10:14 -05:00
contentStr := serial.StringLiteral(content)
assert.String(contentStr).Contains(serial.StringLiteral("test_from"))
assert.String(contentStr).Contains(serial.StringLiteral("test_to"))
assert.String(contentStr).Contains(serial.StringLiteral("test_reason"))
assert.String(contentStr).Contains(serial.StringLiteral("accepted"))
2015-10-10 17:41:45 -04:00
}