unit testing cases update for package gredis/glog

This commit is contained in:
John Guo
2021-08-01 09:45:46 +08:00
parent 2472dd5fac
commit 2b5244a54b
2 changed files with 36 additions and 44 deletions

View File

@ -139,21 +139,11 @@ func Test_Instance(t *testing.T) {
func Test_Error(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
//config1 := &gredis.Config{
// Host: "127.0.0.2",
// Port: 6379,
// Db: 1,
// ConnectTimeout: time.Second,
//}
//redis := gredis.New(config1)
//_, err := redis.Do("info")
//t.AssertNE(err, nil)
config1 := &gredis.Config{
Host: "127.0.0.1",
Port: 6379,
Db: 1,
Pass: "666666",
Host: "192.111.0.2",
Port: 6379,
Db: 1,
ConnectTimeout: time.Second,
}
redis := gredis.New(config1)
_, err := redis.Do("info")

View File

@ -115,36 +115,38 @@ func Test_Stack(t *testing.T) {
})
}
//func Test_StackWithFilter(t *testing.T) {
// gtest.C(t, func(t *gtest.T) {
// path := gfile.TempDir(gtime.TimestampNanoStr())
// file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
//
// err := gfile.Mkdir(path)
// t.Assert(err, nil)
// defer gfile.Remove(path)
//
// Path(path).File(file).StackWithFilter("none").Stdout(false).Error(1, 2, 3)
// content := gfile.GetContents(gfile.Join(path, file))
// t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 1)
// t.Assert(gstr.Count(content, "1 2 3"), 1)
// t.Assert(gstr.Count(content, "Stack"), 1)
// })
// gtest.C(t, func(t *gtest.T) {
// path := gfile.TempDir(gtime.TimestampNanoStr())
// file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
//
// err := gfile.Mkdir(path)
// t.Assert(err, nil)
// defer gfile.Remove(path)
//
// Path(path).File(file).StackWithFilter("gogf").Stdout(false).Error(1, 2, 3)
// content := gfile.GetContents(gfile.Join(path, file))
// t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 1)
// t.Assert(gstr.Count(content, "1 2 3"), 1)
// t.Assert(gstr.Count(content, "Stack"), 0)
// })
//}
func Test_StackWithFilter(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
t.Assert(err, nil)
defer gfile.Remove(path)
Path(path).File(file).StackWithFilter("none").Stdout(false).Error(1, 2, 3)
content := gfile.GetContents(gfile.Join(path, file))
t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 1)
t.Assert(gstr.Count(content, "1 2 3"), 1)
t.Assert(gstr.Count(content, "Stack"), 1)
fmt.Println("Content:")
fmt.Println(content)
})
gtest.C(t, func(t *gtest.T) {
path := gfile.TempDir(gtime.TimestampNanoStr())
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path)
t.Assert(err, nil)
defer gfile.Remove(path)
Path(path).File(file).StackWithFilter("gogf").Stdout(false).Error(1, 2, 3)
content := gfile.GetContents(gfile.Join(path, file))
t.Assert(gstr.Count(content, defaultLevelPrefixes[LEVEL_ERRO]), 1)
t.Assert(gstr.Count(content, "1 2 3"), 1)
t.Assert(gstr.Count(content, "Stack"), 0)
})
}
func Test_Header(t *testing.T) {
gtest.C(t, func(t *gtest.T) {