You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/common/log/logger_test.go

40 lines
775 B

7 years ago
package log_test
import (
"io/ioutil"
"os"
6 years ago
"strings"
7 years ago
"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")
6 years ago
common.Must(err)
7 years ago
path := f.Name()
common.Must(f.Close())
creator, err := CreateFileLogWriter(path)
6 years ago
common.Must(err)
7 years ago
handler := NewLogger(creator)
handler.Handle(&GeneralMessage{Content: "Test Log"})
time.Sleep(2 * time.Second)
common.Must(common.Close(handler))
f, err = os.Open(path)
6 years ago
common.Must(err)
defer f.Close() // nolint: errcheck
7 years ago
b, err := buf.ReadAllToBytes(f)
6 years ago
common.Must(err)
if !strings.Contains(string(b), "Test Log") {
t.Fatal("Expect log text contains 'Test Log', but actually: ", string(b))
}
7 years ago
}