mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 01:08:33 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
39
common/log/logger_test.go
Normal file
39
common/log/logger_test.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package log_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/xtls/xray-core/v1/common"
|
||||
"github.com/xtls/xray-core/v1/common/buf"
|
||||
. "github.com/xtls/xray-core/v1/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()
|
||||
|
||||
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))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue