1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-10 06:16:53 -05:00
v2fly/common/log/logger_test.go

39 lines
788 B
Go
Raw Normal View History

2018-02-19 17:01:00 -05:00
package log_test
import (
"os"
2018-07-13 08:36:09 -04:00
"strings"
2018-02-19 17:01:00 -05:00
"testing"
"time"
"github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/buf"
. "github.com/v2fly/v2ray-core/v5/common/log"
2018-02-19 17:01:00 -05:00
)
func TestFileLogger(t *testing.T) {
f, err := os.CreateTemp("", "vtest")
2018-07-13 08:36:09 -04:00
common.Must(err)
2018-02-19 17:01:00 -05:00
path := f.Name()
common.Must(f.Close())
creator, err := CreateFileLogWriter(path)
2018-07-13 08:36:09 -04:00
common.Must(err)
2018-02-19 17:01:00 -05:00
handler := NewLogger(creator)
handler.Handle(&GeneralMessage{Content: "Test Log"})
time.Sleep(2 * time.Second)
common.Must(common.Close(handler))
f, err = os.Open(path)
2018-07-13 08:36:09 -04:00
common.Must(err)
defer f.Close()
2018-02-19 17:01:00 -05:00
b, err := buf.ReadAllToBytes(f)
2018-07-13 08:36:09 -04:00
common.Must(err)
if !strings.Contains(string(b), "Test Log") {
t.Fatal("Expect log text contains 'Test Log', but actually: ", string(b))
}
2018-02-19 17:01:00 -05:00
}