mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
more test cases
This commit is contained in:
parent
1f8fcb558d
commit
b3fd320be7
40
common/log/logger_test.go
Normal file
40
common/log/logger_test.go
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package log_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"v2ray.com/core/common"
|
||||||
|
"v2ray.com/core/common/buf"
|
||||||
|
. "v2ray.com/core/common/log"
|
||||||
|
. "v2ray.com/ext/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFileLogger(t *testing.T) {
|
||||||
|
assert := With(t)
|
||||||
|
|
||||||
|
f, err := ioutil.TempFile("", "vtest")
|
||||||
|
assert(err, IsNil)
|
||||||
|
path := f.Name()
|
||||||
|
common.Must(f.Close())
|
||||||
|
|
||||||
|
creator, err := CreateFileLogWriter(path)
|
||||||
|
assert(err, IsNil)
|
||||||
|
|
||||||
|
handler := NewLogger(creator)
|
||||||
|
handler.Handle(&GeneralMessage{Content: "Test Log"})
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
|
||||||
|
common.Must(common.Close(handler))
|
||||||
|
|
||||||
|
f, err = os.Open(path)
|
||||||
|
assert(err, IsNil)
|
||||||
|
|
||||||
|
b, err := buf.ReadAllToBytes(f)
|
||||||
|
assert(err, IsNil)
|
||||||
|
assert(string(b), HasSubstring, "Test Log")
|
||||||
|
|
||||||
|
common.Must(f.Close())
|
||||||
|
}
|
28
common/serial/string_test.go
Normal file
28
common/serial/string_test.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package serial_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "v2ray.com/core/common/serial"
|
||||||
|
. "v2ray.com/ext/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestToString(t *testing.T) {
|
||||||
|
assert := With(t)
|
||||||
|
|
||||||
|
s := "a"
|
||||||
|
data := []struct {
|
||||||
|
Value interface{}
|
||||||
|
String string
|
||||||
|
}{
|
||||||
|
{Value: s, String: s},
|
||||||
|
{Value: &s, String: s},
|
||||||
|
{Value: errors.New("t"), String: "t"},
|
||||||
|
{Value: []byte{'b', 'c'}, String: "[62,63]"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range data {
|
||||||
|
assert(ToString(c.Value), Equals, c.String)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user