1
0
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:
Darien Raymond 2018-02-19 23:01:00 +01:00
parent 1f8fcb558d
commit b3fd320be7
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 68 additions and 0 deletions

40
common/log/logger_test.go Normal file
View 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())
}

View 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)
}
}