1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-15 16:56:08 -05:00
v2fly/common/log/logger_test.go
Darien Raymond 5e25741742
update tests
2018-07-13 14:36:09 +02:00

40 lines
775 B
Go

package log_test
import (
"io/ioutil"
"os"
"strings"
"testing"
"time"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
. "v2ray.com/core/common/log"
)
func TestFileLogger(t *testing.T) {
f, err := ioutil.TempFile("", "vtest")
common.Must(err)
path := f.Name()
common.Must(f.Close())
creator, err := CreateFileLogWriter(path)
common.Must(err)
handler := NewLogger(creator)
handler.Handle(&GeneralMessage{Content: "Test Log"})
time.Sleep(2 * time.Second)
common.Must(common.Close(handler))
f, err = os.Open(path)
common.Must(err)
defer f.Close() // nolint: errcheck
b, err := buf.ReadAllToBytes(f)
common.Must(err)
if !strings.Contains(string(b), "Test Log") {
t.Fatal("Expect log text contains 'Test Log', but actually: ", string(b))
}
}