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

37 lines
1.0 KiB
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()
2016-01-18 06:31:27 -05:00
Access(serial.StringLiteral("test_from"), serial.StringLiteral("test_to"), AccessAccepted, serial.StringLiteral("test_reason"))
2015-10-10 17:41:45 -04:00
<-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
}