mirror of https://github.com/XTLS/Xray-core
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.
39 lines
796 B
39 lines
796 B
package log_test |
|
|
|
import ( |
|
"os" |
|
"strings" |
|
"testing" |
|
"time" |
|
|
|
"github.com/xtls/xray-core/common" |
|
"github.com/xtls/xray-core/common/buf" |
|
. "github.com/xtls/xray-core/common/log" |
|
) |
|
|
|
func TestFileLogger(t *testing.T) { |
|
f, err := os.CreateTemp("", "vtest") |
|
common.Must(err) |
|
path := f.Name() |
|
common.Must(f.Close()) |
|
defer os.Remove(path) |
|
|
|
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() |
|
|
|
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)) |
|
} |
|
}
|
|
|