1
0
mirror of https://github.com/gogf/gf.git synced 2025-04-05 11:18:50 +08:00

t.Assert(err, nil) -> t.AssertNil(err)

This commit is contained in:
John Guo 2022-03-10 11:36:40 +08:00
parent eca3583845
commit 546b6b1724
118 changed files with 779 additions and 779 deletions

View File

@ -576,7 +576,7 @@ func TestArray_Json(t *testing.T) {
var a3 garray.Array var a3 garray.Array
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Slice(), s1) t.Assert(a3.Slice(), s1)
}) })
// value. // value.
@ -595,7 +595,7 @@ func TestArray_Json(t *testing.T) {
var a3 garray.Array var a3 garray.Array
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Slice(), s1) t.Assert(a3.Slice(), s1)
}) })
// pointer // pointer
@ -609,11 +609,11 @@ func TestArray_Json(t *testing.T) {
"Scores": []int{99, 100, 98}, "Scores": []int{99, 100, 98},
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
user := new(User) user := new(User)
err = json.UnmarshalUseNumber(b, user) err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Name, data["Name"]) t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, data["Scores"]) t.Assert(user.Scores, data["Scores"])
}) })
@ -628,11 +628,11 @@ func TestArray_Json(t *testing.T) {
"Scores": []int{99, 100, 98}, "Scores": []int{99, 100, 98},
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
user := new(User) user := new(User)
err = json.UnmarshalUseNumber(b, user) err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Name, data["Name"]) t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, data["Scores"]) t.Assert(user.Scores, data["Scores"])
}) })
@ -720,7 +720,7 @@ func TestArray_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"array": g.Slice{1, 2, 3}, "array": g.Slice{1, 2, 3},
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
}) })

View File

@ -619,7 +619,7 @@ func TestIntArray_Json(t *testing.T) {
var a3 garray.IntArray var a3 garray.IntArray
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Slice(), s1) t.Assert(a3.Slice(), s1)
}) })
// array value // array value
@ -637,7 +637,7 @@ func TestIntArray_Json(t *testing.T) {
var a3 garray.IntArray var a3 garray.IntArray
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Slice(), s1) t.Assert(a3.Slice(), s1)
}) })
// array pointer // array pointer
@ -651,11 +651,11 @@ func TestIntArray_Json(t *testing.T) {
"Scores": []int{99, 100, 98}, "Scores": []int{99, 100, 98},
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
user := new(User) user := new(User)
err = json.UnmarshalUseNumber(b, user) err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Name, data["Name"]) t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, data["Scores"]) t.Assert(user.Scores, data["Scores"])
}) })
@ -670,11 +670,11 @@ func TestIntArray_Json(t *testing.T) {
"Scores": []int{99, 100, 98}, "Scores": []int{99, 100, 98},
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
user := new(User) user := new(User)
err = json.UnmarshalUseNumber(b, user) err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Name, data["Name"]) t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, data["Scores"]) t.Assert(user.Scores, data["Scores"])
}) })
@ -752,7 +752,7 @@ func TestIntArray_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"array": []byte(`[1,2,3]`), "array": []byte(`[1,2,3]`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
}) })
@ -763,7 +763,7 @@ func TestIntArray_UnmarshalValue(t *testing.T) {
// "name": "john", // "name": "john",
// "array": g.Slice{1, 2, 3}, // "array": g.Slice{1, 2, 3},
// }, &v) // }, &v)
// t.Assert(err, nil) // t.AssertNil(err)
// t.Assert(v.Name, "john") // t.Assert(v.Name, "john")
// t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) // t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
// }) // })

View File

@ -619,7 +619,7 @@ func TestStrArray_Json(t *testing.T) {
var a3 garray.StrArray var a3 garray.StrArray
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Slice(), s1) t.Assert(a3.Slice(), s1)
}) })
// array value // array value
@ -637,7 +637,7 @@ func TestStrArray_Json(t *testing.T) {
var a3 garray.StrArray var a3 garray.StrArray
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Slice(), s1) t.Assert(a3.Slice(), s1)
}) })
// array pointer // array pointer
@ -651,11 +651,11 @@ func TestStrArray_Json(t *testing.T) {
"Scores": []string{"A+", "A", "A"}, "Scores": []string{"A+", "A", "A"},
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
user := new(User) user := new(User)
err = json.UnmarshalUseNumber(b, user) err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Name, data["Name"]) t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, data["Scores"]) t.Assert(user.Scores, data["Scores"])
}) })
@ -670,11 +670,11 @@ func TestStrArray_Json(t *testing.T) {
"Scores": []string{"A+", "A", "A"}, "Scores": []string{"A+", "A", "A"},
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
user := new(User) user := new(User)
err = json.UnmarshalUseNumber(b, user) err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Name, data["Name"]) t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, data["Scores"]) t.Assert(user.Scores, data["Scores"])
}) })
@ -751,7 +751,7 @@ func TestStrArray_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"array": []byte(`["1","2","3"]`), "array": []byte(`["1","2","3"]`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"}) t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"})
}) })
@ -762,7 +762,7 @@ func TestStrArray_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"array": g.SliceStr{"1", "2", "3"}, "array": g.SliceStr{"1", "2", "3"},
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"}) t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"})
}) })

View File

@ -661,7 +661,7 @@ func TestSortedArray_Json(t *testing.T) {
var a3 garray.SortedArray var a3 garray.SortedArray
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Slice(), s1) t.Assert(a3.Slice(), s1)
t.Assert(a3.Interfaces(), s1) t.Assert(a3.Interfaces(), s1)
}) })
@ -681,7 +681,7 @@ func TestSortedArray_Json(t *testing.T) {
var a3 garray.SortedArray var a3 garray.SortedArray
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Slice(), s1) t.Assert(a3.Slice(), s1)
t.Assert(a3.Interfaces(), s1) t.Assert(a3.Interfaces(), s1)
}) })
@ -696,11 +696,11 @@ func TestSortedArray_Json(t *testing.T) {
"Scores": []int{99, 100, 98}, "Scores": []int{99, 100, 98},
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
user := new(User) user := new(User)
err = json.UnmarshalUseNumber(b, user) err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Name, data["Name"]) t.Assert(user.Name, data["Name"])
t.AssertNE(user.Scores, nil) t.AssertNE(user.Scores, nil)
t.Assert(user.Scores.Len(), 3) t.Assert(user.Scores.Len(), 3)
@ -732,11 +732,11 @@ func TestSortedArray_Json(t *testing.T) {
"Scores": []int{99, 100, 98}, "Scores": []int{99, 100, 98},
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
user := new(User) user := new(User)
err = json.UnmarshalUseNumber(b, user) err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Name, data["Name"]) t.Assert(user.Name, data["Name"])
t.AssertNE(user.Scores, nil) t.AssertNE(user.Scores, nil)
t.Assert(user.Scores.Len(), 3) t.Assert(user.Scores.Len(), 3)
@ -830,7 +830,7 @@ func TestSortedArray_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"array": []byte(`[2,3,1]`), "array": []byte(`[2,3,1]`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
}) })
@ -841,7 +841,7 @@ func TestSortedArray_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"array": g.Slice{2, 3, 1}, "array": g.Slice{2, 3, 1},
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
}) })

View File

@ -561,7 +561,7 @@ func TestSortedIntArray_Json(t *testing.T) {
var a3 garray.SortedIntArray var a3 garray.SortedIntArray
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Slice(), s1) t.Assert(a3.Slice(), s1)
}) })
// array value // array value
@ -580,7 +580,7 @@ func TestSortedIntArray_Json(t *testing.T) {
var a3 garray.SortedIntArray var a3 garray.SortedIntArray
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Slice(), s1) t.Assert(a3.Slice(), s1)
}) })
// array pointer // array pointer
@ -594,11 +594,11 @@ func TestSortedIntArray_Json(t *testing.T) {
"Scores": []int{99, 100, 98}, "Scores": []int{99, 100, 98},
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
user := new(User) user := new(User)
err = json.UnmarshalUseNumber(b, user) err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Name, data["Name"]) t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, []int{98, 99, 100}) t.Assert(user.Scores, []int{98, 99, 100})
}) })
@ -613,11 +613,11 @@ func TestSortedIntArray_Json(t *testing.T) {
"Scores": []int{99, 100, 98}, "Scores": []int{99, 100, 98},
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
user := new(User) user := new(User)
err = json.UnmarshalUseNumber(b, user) err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Name, data["Name"]) t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, []int{98, 99, 100}) t.Assert(user.Scores, []int{98, 99, 100})
}) })
@ -695,7 +695,7 @@ func TestSortedIntArray_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"array": []byte(`[2,3,1]`), "array": []byte(`[2,3,1]`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
}) })
@ -706,7 +706,7 @@ func TestSortedIntArray_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"array": g.Slice{2, 3, 1}, "array": g.Slice{2, 3, 1},
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3}) t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
}) })

View File

@ -583,7 +583,7 @@ func TestSortedStrArray_Json(t *testing.T) {
var a3 garray.SortedStrArray var a3 garray.SortedStrArray
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Slice(), s1) t.Assert(a3.Slice(), s1)
t.Assert(a3.Interfaces(), s1) t.Assert(a3.Interfaces(), s1)
}) })
@ -604,7 +604,7 @@ func TestSortedStrArray_Json(t *testing.T) {
var a3 garray.SortedStrArray var a3 garray.SortedStrArray
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Slice(), s1) t.Assert(a3.Slice(), s1)
t.Assert(a3.Interfaces(), s1) t.Assert(a3.Interfaces(), s1)
}) })
@ -619,11 +619,11 @@ func TestSortedStrArray_Json(t *testing.T) {
"Scores": []string{"A+", "A", "A"}, "Scores": []string{"A+", "A", "A"},
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
user := new(User) user := new(User)
err = json.UnmarshalUseNumber(b, user) err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Name, data["Name"]) t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, []string{"A", "A", "A+"}) t.Assert(user.Scores, []string{"A", "A", "A+"})
}) })
@ -638,11 +638,11 @@ func TestSortedStrArray_Json(t *testing.T) {
"Scores": []string{"A+", "A", "A"}, "Scores": []string{"A+", "A", "A"},
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
user := new(User) user := new(User)
err = json.UnmarshalUseNumber(b, user) err = json.UnmarshalUseNumber(b, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Name, data["Name"]) t.Assert(user.Name, data["Name"])
t.Assert(user.Scores, []string{"A", "A", "A+"}) t.Assert(user.Scores, []string{"A", "A", "A+"})
}) })
@ -719,7 +719,7 @@ func TestSortedStrArray_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"array": []byte(`["1","3","2"]`), "array": []byte(`["1","3","2"]`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"}) t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"})
}) })
@ -730,7 +730,7 @@ func TestSortedStrArray_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"array": g.SliceStr{"1", "3", "2"}, "array": g.SliceStr{"1", "3", "2"},
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"}) t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"})
}) })

View File

@ -709,20 +709,20 @@ func TestList_Json(t *testing.T) {
a := []interface{}{"a", "b", "c"} a := []interface{}{"a", "b", "c"}
l := New() l := New()
b, err := json.Marshal(a) b, err := json.Marshal(a)
t.Assert(err, nil) t.AssertNil(err)
err = json.UnmarshalUseNumber(b, l) err = json.UnmarshalUseNumber(b, l)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(l.FrontAll(), a) t.Assert(l.FrontAll(), a)
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
var l List var l List
a := []interface{}{"a", "b", "c"} a := []interface{}{"a", "b", "c"}
b, err := json.Marshal(a) b, err := json.Marshal(a)
t.Assert(err, nil) t.AssertNil(err)
err = json.UnmarshalUseNumber(b, &l) err = json.UnmarshalUseNumber(b, &l)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(l.FrontAll(), a) t.Assert(l.FrontAll(), a)
}) })
} }
@ -739,7 +739,7 @@ func TestList_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"list": []byte(`[1,2,3]`), "list": []byte(`[1,2,3]`),
}, &tlist) }, &tlist)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(tlist.Name, "john") t.Assert(tlist.Name, "john")
t.Assert(tlist.List.FrontAll(), []interface{}{1, 2, 3}) t.Assert(tlist.List.FrontAll(), []interface{}{1, 2, 3})
}) })
@ -750,7 +750,7 @@ func TestList_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"list": []interface{}{1, 2, 3}, "list": []interface{}{1, 2, 3},
}, &tlist) }, &tlist)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(tlist.Name, "john") t.Assert(tlist.Name, "john")
t.Assert(tlist.List.FrontAll(), []interface{}{1, 2, 3}) t.Assert(tlist.List.FrontAll(), []interface{}{1, 2, 3})
}) })

View File

@ -253,11 +253,11 @@ func Test_AnyAnyMap_Json(t *testing.T) {
"k2": "v2", "k2": "v2",
} }
b, err := json.Marshal(gconv.Map(data)) b, err := json.Marshal(gconv.Map(data))
t.Assert(err, nil) t.AssertNil(err)
m := gmap.New() m := gmap.New()
err = json.UnmarshalUseNumber(b, m) err = json.UnmarshalUseNumber(b, m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k1"), data["k1"])
t.Assert(m.Get("k2"), data["k2"]) t.Assert(m.Get("k2"), data["k2"])
}) })
@ -267,11 +267,11 @@ func Test_AnyAnyMap_Json(t *testing.T) {
"k2": "v2", "k2": "v2",
} }
b, err := json.Marshal(gconv.Map(data)) b, err := json.Marshal(gconv.Map(data))
t.Assert(err, nil) t.AssertNil(err)
var m gmap.Map var m gmap.Map
err = json.UnmarshalUseNumber(b, &m) err = json.UnmarshalUseNumber(b, &m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k1"), data["k1"])
t.Assert(m.Get("k2"), data["k2"]) t.Assert(m.Get("k2"), data["k2"])
}) })
@ -342,7 +342,7 @@ func TestAnyAnyMap_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"map": []byte(`{"k1":"v1","k2":"v2"}`), "map": []byte(`{"k1":"v1","k2":"v2"}`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get("k1"), "v1") t.Assert(v.Map.Get("k1"), "v1")
@ -358,7 +358,7 @@ func TestAnyAnyMap_UnmarshalValue(t *testing.T) {
"k2": "v2", "k2": "v2",
}, },
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get("k1"), "v1") t.Assert(v.Map.Get("k1"), "v1")

View File

@ -242,11 +242,11 @@ func Test_IntAnyMap_Json(t *testing.T) {
2: "v2", 2: "v2",
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
m := gmap.NewIntAnyMap() m := gmap.NewIntAnyMap()
err = json.UnmarshalUseNumber(b, m) err = json.UnmarshalUseNumber(b, m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get(1), data[1]) t.Assert(m.Get(1), data[1])
t.Assert(m.Get(2), data[2]) t.Assert(m.Get(2), data[2])
}) })
@ -317,7 +317,7 @@ func TestIntAnyMap_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"map": []byte(`{"1":"v1","2":"v2"}`), "map": []byte(`{"1":"v1","2":"v2"}`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get(1), "v1") t.Assert(v.Map.Get(1), "v1")
@ -333,7 +333,7 @@ func TestIntAnyMap_UnmarshalValue(t *testing.T) {
2: "v2", 2: "v2",
}, },
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get(1), "v1") t.Assert(v.Map.Get(1), "v1")

View File

@ -248,11 +248,11 @@ func Test_IntIntMap_Json(t *testing.T) {
2: 20, 2: 20,
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
m := gmap.NewIntIntMap() m := gmap.NewIntIntMap()
err = json.UnmarshalUseNumber(b, m) err = json.UnmarshalUseNumber(b, m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get(1), data[1]) t.Assert(m.Get(1), data[1])
t.Assert(m.Get(2), data[2]) t.Assert(m.Get(2), data[2])
}) })
@ -323,7 +323,7 @@ func TestIntIntMap_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"map": []byte(`{"1":1,"2":2}`), "map": []byte(`{"1":1,"2":2}`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get(1), "1") t.Assert(v.Map.Get(1), "1")
@ -339,7 +339,7 @@ func TestIntIntMap_UnmarshalValue(t *testing.T) {
2: 2, 2: 2,
}, },
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get(1), "1") t.Assert(v.Map.Get(1), "1")

View File

@ -246,11 +246,11 @@ func Test_IntStrMap_Json(t *testing.T) {
2: "v2", 2: "v2",
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
m := gmap.NewIntStrMap() m := gmap.NewIntStrMap()
err = json.UnmarshalUseNumber(b, m) err = json.UnmarshalUseNumber(b, m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get(1), data[1]) t.Assert(m.Get(1), data[1])
t.Assert(m.Get(2), data[2]) t.Assert(m.Get(2), data[2])
}) })
@ -321,7 +321,7 @@ func TestIntStrMap_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"map": []byte(`{"1":"v1","2":"v2"}`), "map": []byte(`{"1":"v1","2":"v2"}`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get(1), "v1") t.Assert(v.Map.Get(1), "v1")
@ -337,7 +337,7 @@ func TestIntStrMap_UnmarshalValue(t *testing.T) {
2: "v2", 2: "v2",
}, },
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get(1), "v1") t.Assert(v.Map.Get(1), "v1")

View File

@ -240,11 +240,11 @@ func Test_StrAnyMap_Json(t *testing.T) {
"k2": "v2", "k2": "v2",
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
m := gmap.NewStrAnyMap() m := gmap.NewStrAnyMap()
err = json.UnmarshalUseNumber(b, m) err = json.UnmarshalUseNumber(b, m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k1"), data["k1"])
t.Assert(m.Get("k2"), data["k2"]) t.Assert(m.Get("k2"), data["k2"])
}) })
@ -254,11 +254,11 @@ func Test_StrAnyMap_Json(t *testing.T) {
"k2": "v2", "k2": "v2",
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
var m gmap.StrAnyMap var m gmap.StrAnyMap
err = json.UnmarshalUseNumber(b, &m) err = json.UnmarshalUseNumber(b, &m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k1"), data["k1"])
t.Assert(m.Get("k2"), data["k2"]) t.Assert(m.Get("k2"), data["k2"])
}) })
@ -329,7 +329,7 @@ func TestStrAnyMap_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"map": []byte(`{"k1":"v1","k2":"v2"}`), "map": []byte(`{"k1":"v1","k2":"v2"}`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get("k1"), "v1") t.Assert(v.Map.Get("k1"), "v1")
@ -345,7 +345,7 @@ func TestStrAnyMap_UnmarshalValue(t *testing.T) {
"k2": "v2", "k2": "v2",
}, },
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get("k1"), "v1") t.Assert(v.Map.Get("k1"), "v1")

View File

@ -244,11 +244,11 @@ func Test_StrIntMap_Json(t *testing.T) {
"k2": 2, "k2": 2,
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
m := gmap.NewStrIntMap() m := gmap.NewStrIntMap()
err = json.UnmarshalUseNumber(b, m) err = json.UnmarshalUseNumber(b, m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k1"), data["k1"])
t.Assert(m.Get("k2"), data["k2"]) t.Assert(m.Get("k2"), data["k2"])
}) })
@ -258,11 +258,11 @@ func Test_StrIntMap_Json(t *testing.T) {
"k2": 2, "k2": 2,
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
var m gmap.StrIntMap var m gmap.StrIntMap
err = json.UnmarshalUseNumber(b, &m) err = json.UnmarshalUseNumber(b, &m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k1"), data["k1"])
t.Assert(m.Get("k2"), data["k2"]) t.Assert(m.Get("k2"), data["k2"])
}) })
@ -333,7 +333,7 @@ func TestStrIntMap_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"map": []byte(`{"k1":1,"k2":2}`), "map": []byte(`{"k1":1,"k2":2}`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get("k1"), 1) t.Assert(v.Map.Get("k1"), 1)
@ -349,7 +349,7 @@ func TestStrIntMap_UnmarshalValue(t *testing.T) {
"k2": 2, "k2": 2,
}, },
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get("k1"), 1) t.Assert(v.Map.Get("k1"), 1)

View File

@ -241,11 +241,11 @@ func Test_StrStrMap_Json(t *testing.T) {
"k2": "v2", "k2": "v2",
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
m := gmap.NewStrStrMap() m := gmap.NewStrStrMap()
err = json.UnmarshalUseNumber(b, m) err = json.UnmarshalUseNumber(b, m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k1"), data["k1"])
t.Assert(m.Get("k2"), data["k2"]) t.Assert(m.Get("k2"), data["k2"])
}) })
@ -255,11 +255,11 @@ func Test_StrStrMap_Json(t *testing.T) {
"k2": "v2", "k2": "v2",
} }
b, err := json.Marshal(data) b, err := json.Marshal(data)
t.Assert(err, nil) t.AssertNil(err)
var m gmap.StrStrMap var m gmap.StrStrMap
err = json.UnmarshalUseNumber(b, &m) err = json.UnmarshalUseNumber(b, &m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k1"), data["k1"])
t.Assert(m.Get("k2"), data["k2"]) t.Assert(m.Get("k2"), data["k2"])
}) })
@ -330,7 +330,7 @@ func TestStrStrMap_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"map": []byte(`{"k1":"v1","k2":"v2"}`), "map": []byte(`{"k1":"v1","k2":"v2"}`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get("k1"), "v1") t.Assert(v.Map.Get("k1"), "v1")
@ -346,7 +346,7 @@ func TestStrStrMap_UnmarshalValue(t *testing.T) {
"k2": "v2", "k2": "v2",
}, },
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get("k1"), "v1") t.Assert(v.Map.Get("k1"), "v1")

View File

@ -201,11 +201,11 @@ func Test_ListMap_Json(t *testing.T) {
"k2": "v2", "k2": "v2",
} }
b, err := json.Marshal(gconv.Map(data)) b, err := json.Marshal(gconv.Map(data))
t.Assert(err, nil) t.AssertNil(err)
m := gmap.NewListMap() m := gmap.NewListMap()
err = json.UnmarshalUseNumber(b, m) err = json.UnmarshalUseNumber(b, m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k1"), data["k1"])
t.Assert(m.Get("k2"), data["k2"]) t.Assert(m.Get("k2"), data["k2"])
}) })
@ -216,11 +216,11 @@ func Test_ListMap_Json(t *testing.T) {
"k2": "v2", "k2": "v2",
} }
b, err := json.Marshal(gconv.Map(data)) b, err := json.Marshal(gconv.Map(data))
t.Assert(err, nil) t.AssertNil(err)
var m gmap.ListMap var m gmap.ListMap
err = json.UnmarshalUseNumber(b, &m) err = json.UnmarshalUseNumber(b, &m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k1"), data["k1"])
t.Assert(m.Get("k2"), data["k2"]) t.Assert(m.Get("k2"), data["k2"])
}) })
@ -312,7 +312,7 @@ func TestListMap_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"map": []byte(`{"1":"v1","2":"v2"}`), "map": []byte(`{"1":"v1","2":"v2"}`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get("1"), "v1") t.Assert(v.Map.Get("1"), "v1")
@ -328,7 +328,7 @@ func TestListMap_UnmarshalValue(t *testing.T) {
2: "v2", 2: "v2",
}, },
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get("1"), "v1") t.Assert(v.Map.Get("1"), "v1")

View File

@ -185,11 +185,11 @@ func Test_TreeMap_Json(t *testing.T) {
"k2": "v2", "k2": "v2",
} }
b, err := json.Marshal(gconv.Map(data)) b, err := json.Marshal(gconv.Map(data))
t.Assert(err, nil) t.AssertNil(err)
m := gmap.NewTreeMap(gutil.ComparatorString) m := gmap.NewTreeMap(gutil.ComparatorString)
err = json.UnmarshalUseNumber(b, m) err = json.UnmarshalUseNumber(b, m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k1"), data["k1"])
t.Assert(m.Get("k2"), data["k2"]) t.Assert(m.Get("k2"), data["k2"])
}) })
@ -199,11 +199,11 @@ func Test_TreeMap_Json(t *testing.T) {
"k2": "v2", "k2": "v2",
} }
b, err := json.Marshal(gconv.Map(data)) b, err := json.Marshal(gconv.Map(data))
t.Assert(err, nil) t.AssertNil(err)
var m gmap.TreeMap var m gmap.TreeMap
err = json.UnmarshalUseNumber(b, &m) err = json.UnmarshalUseNumber(b, &m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m.Get("k1"), data["k1"]) t.Assert(m.Get("k1"), data["k1"])
t.Assert(m.Get("k2"), data["k2"]) t.Assert(m.Get("k2"), data["k2"])
}) })
@ -221,7 +221,7 @@ func TestTreeMap_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"map": []byte(`{"k1":"v1","k2":"v2"}`), "map": []byte(`{"k1":"v1","k2":"v2"}`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get("k1"), "v1") t.Assert(v.Map.Get("k1"), "v1")
@ -237,7 +237,7 @@ func TestTreeMap_UnmarshalValue(t *testing.T) {
"k2": "v2", "k2": "v2",
}, },
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Map.Size(), 2) t.Assert(v.Map.Size(), 2)
t.Assert(v.Map.Get("k1"), "v1") t.Assert(v.Map.Get("k1"), "v1")

View File

@ -336,7 +336,7 @@ func TestSet_Json(t *testing.T) {
var a3 gset.Set var a3 gset.Set
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Contains("a"), true) t.Assert(a3.Contains("a"), true)
t.Assert(a3.Contains("b"), true) t.Assert(a3.Contains("b"), true)
t.Assert(a3.Contains("c"), true) t.Assert(a3.Contains("c"), true)
@ -438,7 +438,7 @@ func TestSet_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"set": []byte(`["k1","k2","k3"]`), "set": []byte(`["k1","k2","k3"]`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Set.Size(), 3) t.Assert(v.Set.Size(), 3)
t.Assert(v.Set.Contains("k1"), true) t.Assert(v.Set.Contains("k1"), true)
@ -453,7 +453,7 @@ func TestSet_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"set": g.Slice{"k1", "k2", "k3"}, "set": g.Slice{"k1", "k2", "k3"},
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Set.Size(), 3) t.Assert(v.Set.Size(), 3)
t.Assert(v.Set.Contains("k1"), true) t.Assert(v.Set.Contains("k1"), true)

View File

@ -368,7 +368,7 @@ func TestIntSet_Json(t *testing.T) {
var a3 gset.IntSet var a3 gset.IntSet
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a2.Contains(1), true) t.Assert(a2.Contains(1), true)
t.Assert(a2.Contains(2), true) t.Assert(a2.Contains(2), true)
t.Assert(a2.Contains(3), true) t.Assert(a2.Contains(3), true)
@ -402,7 +402,7 @@ func TestIntSet_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"set": []byte(`[1,2,3]`), "set": []byte(`[1,2,3]`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Set.Size(), 3) t.Assert(v.Set.Size(), 3)
t.Assert(v.Set.Contains(1), true) t.Assert(v.Set.Contains(1), true)
@ -417,7 +417,7 @@ func TestIntSet_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"set": g.Slice{1, 2, 3}, "set": g.Slice{1, 2, 3},
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Set.Size(), 3) t.Assert(v.Set.Size(), 3)
t.Assert(v.Set.Contains(1), true) t.Assert(v.Set.Contains(1), true)

View File

@ -414,7 +414,7 @@ func TestStrSet_Json(t *testing.T) {
var a3 gset.StrSet var a3 gset.StrSet
err := json.UnmarshalUseNumber(b2, &a3) err := json.UnmarshalUseNumber(b2, &a3)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a3.Contains("a"), true) t.Assert(a3.Contains("a"), true)
t.Assert(a3.Contains("b"), true) t.Assert(a3.Contains("b"), true)
t.Assert(a3.Contains("c"), true) t.Assert(a3.Contains("c"), true)
@ -453,7 +453,7 @@ func TestStrSet_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"set": []byte(`["1","2","3"]`), "set": []byte(`["1","2","3"]`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Set.Size(), 3) t.Assert(v.Set.Size(), 3)
t.Assert(v.Set.Contains("1"), true) t.Assert(v.Set.Contains("1"), true)
@ -468,7 +468,7 @@ func TestStrSet_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"set": g.SliceStr{"1", "2", "3"}, "set": g.SliceStr{"1", "2", "3"},
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Set.Size(), 3) t.Assert(v.Set.Size(), 3)
t.Assert(v.Set.Contains("1"), true) t.Assert(v.Set.Contains("1"), true)

View File

@ -56,16 +56,16 @@ func Test_Bool_JSON(t *testing.T) {
var err error var err error
i := gtype.NewBool() i := gtype.NewBool()
err = json.UnmarshalUseNumber([]byte("true"), &i) err = json.UnmarshalUseNumber([]byte("true"), &i)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i.Val(), true) t.Assert(i.Val(), true)
err = json.UnmarshalUseNumber([]byte("false"), &i) err = json.UnmarshalUseNumber([]byte("false"), &i)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i.Val(), false) t.Assert(i.Val(), false)
err = json.UnmarshalUseNumber([]byte("1"), &i) err = json.UnmarshalUseNumber([]byte("1"), &i)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i.Val(), true) t.Assert(i.Val(), true)
err = json.UnmarshalUseNumber([]byte("0"), &i) err = json.UnmarshalUseNumber([]byte("0"), &i)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i.Val(), false) t.Assert(i.Val(), false)
}) })
@ -79,7 +79,7 @@ func Test_Bool_JSON(t *testing.T) {
i2 := gtype.NewBool() i2 := gtype.NewBool()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), i.Val()) t.Assert(i2.Val(), i.Val())
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
@ -92,7 +92,7 @@ func Test_Bool_JSON(t *testing.T) {
i2 := gtype.NewBool() i2 := gtype.NewBool()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), i.Val()) t.Assert(i2.Val(), i.Val())
}) })
} }
@ -108,7 +108,7 @@ func Test_Bool_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "true", "var": "true",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), true) t.Assert(v.Var.Val(), true)
}) })
@ -118,7 +118,7 @@ func Test_Bool_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "false", "var": "false",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), false) t.Assert(v.Var.Val(), false)
}) })

View File

@ -54,7 +54,7 @@ func Test_Byte_JSON(t *testing.T) {
var err error var err error
i := gtype.NewByte() i := gtype.NewByte()
err = json.UnmarshalUseNumber([]byte("49"), &i) err = json.UnmarshalUseNumber([]byte("49"), &i)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i.Val(), "49") t.Assert(i.Val(), "49")
}) })
} }
@ -70,7 +70,7 @@ func Test_Byte_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "2", "var": "2",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), "2") t.Assert(v.Var.Val(), "2")
}) })

View File

@ -40,7 +40,7 @@ func Test_Bytes_JSON(t *testing.T) {
i2 := gtype.NewBytes() i2 := gtype.NewBytes()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), b) t.Assert(i2.Val(), b)
}) })
} }
@ -56,7 +56,7 @@ func Test_Bytes_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "123", "var": "123",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), "123") t.Assert(v.Var.Val(), "123")
}) })

View File

@ -42,7 +42,7 @@ func Test_Float32_JSON(t *testing.T) {
i2 := gtype.NewFloat32() i2 := gtype.NewFloat32()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), v) t.Assert(i2.Val(), v)
}) })
} }
@ -58,7 +58,7 @@ func Test_Float32_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "123.456", "var": "123.456",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), "123.456") t.Assert(v.Var.Val(), "123.456")
}) })

View File

@ -40,7 +40,7 @@ func Test_Float64_JSON(t *testing.T) {
i2 := gtype.NewFloat64() i2 := gtype.NewFloat64()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), v) t.Assert(i2.Val(), v)
}) })
} }
@ -56,7 +56,7 @@ func Test_Float64_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "123.456", "var": "123.456",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), "123.456") t.Assert(v.Var.Val(), "123.456")
}) })

View File

@ -53,7 +53,7 @@ func Test_Int32_JSON(t *testing.T) {
i2 := gtype.NewInt32() i2 := gtype.NewInt32()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), v) t.Assert(i2.Val(), v)
}) })
} }
@ -69,7 +69,7 @@ func Test_Int32_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "123", "var": "123",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), "123") t.Assert(v.Var.Val(), "123")
}) })

View File

@ -52,7 +52,7 @@ func Test_Int64_JSON(t *testing.T) {
i2 := gtype.NewInt64() i2 := gtype.NewInt64()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), i) t.Assert(i2.Val(), i)
}) })
} }
@ -68,7 +68,7 @@ func Test_Int64_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "123", "var": "123",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), "123") t.Assert(v.Var.Val(), "123")
}) })

View File

@ -52,7 +52,7 @@ func Test_Int_JSON(t *testing.T) {
i2 := gtype.NewInt() i2 := gtype.NewInt()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), v) t.Assert(i2.Val(), v)
}) })
} }
@ -68,7 +68,7 @@ func Test_Int_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "123", "var": "123",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), "123") t.Assert(v.Var.Val(), "123")
}) })

View File

@ -42,7 +42,7 @@ func Test_Interface_JSON(t *testing.T) {
i2 := gtype.New() i2 := gtype.New()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), s) t.Assert(i2.Val(), s)
}) })
} }
@ -58,7 +58,7 @@ func Test_Interface_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "123", "var": "123",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), "123") t.Assert(v.Var.Val(), "123")
}) })

View File

@ -40,7 +40,7 @@ func Test_String_JSON(t *testing.T) {
i2 := gtype.NewString() i2 := gtype.NewString()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), s) t.Assert(i2.Val(), s)
}) })
} }
@ -56,7 +56,7 @@ func Test_String_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "123", "var": "123",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), "123") t.Assert(v.Var.Val(), "123")
}) })

View File

@ -52,7 +52,7 @@ func Test_Uint32_JSON(t *testing.T) {
i2 := gtype.NewUint32() i2 := gtype.NewUint32()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), i) t.Assert(i2.Val(), i)
}) })
} }
@ -68,7 +68,7 @@ func Test_Uint32_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "123", "var": "123",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), "123") t.Assert(v.Var.Val(), "123")
}) })

View File

@ -56,7 +56,7 @@ func Test_Uint64_JSON(t *testing.T) {
i2 := gtype.NewUint64() i2 := gtype.NewUint64()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), i) t.Assert(i2.Val(), i)
}) })
} }
@ -72,7 +72,7 @@ func Test_Uint64_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "123", "var": "123",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), "123") t.Assert(v.Var.Val(), "123")
}) })

View File

@ -51,7 +51,7 @@ func Test_Uint_JSON(t *testing.T) {
i2 := gtype.NewUint() i2 := gtype.NewUint()
err := json.UnmarshalUseNumber(b2, &i2) err := json.UnmarshalUseNumber(b2, &i2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(i2.Val(), i) t.Assert(i2.Val(), i)
}) })
} }
@ -67,7 +67,7 @@ func Test_Uint_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "123", "var": "123",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.Val(), "123") t.Assert(v.Var.Val(), "123")
}) })

View File

@ -253,7 +253,7 @@ func Test_UnmarshalJson(t *testing.T) {
"name": "john", "name": "john",
"var": "v", "var": "v",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.String(), "v") t.Assert(v.Var.String(), "v")
}) })
@ -267,7 +267,7 @@ func Test_UnmarshalJson(t *testing.T) {
"name": "john", "name": "john",
"var": "v", "var": "v",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.String(), "v") t.Assert(v.Var.String(), "v")
}) })
@ -284,7 +284,7 @@ func Test_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "v", "var": "v",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.String(), "v") t.Assert(v.Var.String(), "v")
}) })
@ -298,7 +298,7 @@ func Test_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"var": "v", "var": "v",
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Var.String(), "v") t.Assert(v.Var.String(), "v")
}) })

View File

@ -40,10 +40,10 @@ func TestVar_Json(t *testing.T) {
s := "i love gf" s := "i love gf"
v := gvar.New(nil) v := gvar.New(nil)
b, err := json.Marshal(s) b, err := json.Marshal(s)
t.Assert(err, nil) t.AssertNil(err)
err = json.UnmarshalUseNumber(b, v) err = json.UnmarshalUseNumber(b, v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.String(), s) t.Assert(v.String(), s)
}) })
@ -51,10 +51,10 @@ func TestVar_Json(t *testing.T) {
var v gvar.Var var v gvar.Var
s := "i love gf" s := "i love gf"
b, err := json.Marshal(s) b, err := json.Marshal(s)
t.Assert(err, nil) t.AssertNil(err)
err = json.UnmarshalUseNumber(b, &v) err = json.UnmarshalUseNumber(b, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.String(), s) t.Assert(v.String(), s)
}) })
} }

View File

@ -55,7 +55,7 @@ func TestVar_Var_Attribute_Struct(t *testing.T) {
"uid": gvar.New(1), "uid": gvar.New(1),
"name": gvar.New("john"), "name": gvar.New("john"),
}, user) }, user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Uid, 1) t.Assert(user.Uid, 1)
t.Assert(user.Name, "john") t.Assert(user.Name, "john")
}) })
@ -70,7 +70,7 @@ func TestVar_Var_Attribute_Struct(t *testing.T) {
"uid": gvar.New(1), "uid": gvar.New(1),
"name": gvar.New("john"), "name": gvar.New("john"),
}, &user) }, &user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user.Uid, 1) t.Assert(user.Uid, 1)
t.Assert(user.Name, "john") t.Assert(user.Name, "john")
}) })

View File

@ -41,19 +41,19 @@ var (
func TestEncrypt(t *testing.T) { func TestEncrypt(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
data, err := gaes.Encrypt(content, key_16) data, err := gaes.Encrypt(content, key_16)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(data, []byte(content_16)) t.Assert(data, []byte(content_16))
data, err = gaes.Encrypt(content, key_24) data, err = gaes.Encrypt(content, key_24)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(data, []byte(content_24)) t.Assert(data, []byte(content_24))
data, err = gaes.Encrypt(content, key_32) data, err = gaes.Encrypt(content, key_32)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(data, []byte(content_32)) t.Assert(data, []byte(content_32))
data, err = gaes.Encrypt(content, key_16, iv) data, err = gaes.Encrypt(content, key_16, iv)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(data, []byte(content_16_iv)) t.Assert(data, []byte(content_16_iv))
data, err = gaes.Encrypt(content, key_32, iv) data, err = gaes.Encrypt(content, key_32, iv)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(data, []byte(content_32_iv)) t.Assert(data, []byte(content_32_iv))
}) })
} }
@ -61,23 +61,23 @@ func TestEncrypt(t *testing.T) {
func TestDecrypt(t *testing.T) { func TestDecrypt(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
decrypt, err := gaes.Decrypt([]byte(content_16), key_16) decrypt, err := gaes.Decrypt([]byte(content_16), key_16)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(decrypt, content) t.Assert(decrypt, content)
decrypt, err = gaes.Decrypt([]byte(content_24), key_24) decrypt, err = gaes.Decrypt([]byte(content_24), key_24)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(decrypt, content) t.Assert(decrypt, content)
decrypt, err = gaes.Decrypt([]byte(content_32), key_32) decrypt, err = gaes.Decrypt([]byte(content_32), key_32)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(decrypt, content) t.Assert(decrypt, content)
decrypt, err = gaes.Decrypt([]byte(content_16_iv), key_16, iv) decrypt, err = gaes.Decrypt([]byte(content_16_iv), key_16, iv)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(decrypt, content) t.Assert(decrypt, content)
decrypt, err = gaes.Decrypt([]byte(content_32_iv), key_32, iv) decrypt, err = gaes.Decrypt([]byte(content_32_iv), key_32, iv)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(decrypt, content) t.Assert(decrypt, content)
decrypt, err = gaes.Decrypt([]byte(content_32_iv), keys, iv) decrypt, err = gaes.Decrypt([]byte(content_32_iv), keys, iv)
@ -134,7 +134,7 @@ func TestEncryptCFB(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
var padding int = 0 var padding int = 0
data, err := gaes.EncryptCFB(content, key_16, &padding, iv) data, err := gaes.EncryptCFB(content, key_16, &padding, iv)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(padding, padding_size) t.Assert(padding, padding_size)
t.Assert(data, []byte(content_16_cfb)) t.Assert(data, []byte(content_16_cfb))
}) })
@ -143,7 +143,7 @@ func TestEncryptCFB(t *testing.T) {
func TestDecryptCFB(t *testing.T) { func TestDecryptCFB(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
decrypt, err := gaes.DecryptCFB([]byte(content_16_cfb), key_16, padding_size, iv) decrypt, err := gaes.DecryptCFB([]byte(content_16_cfb), key_16, padding_size, iv)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(decrypt, content) t.Assert(decrypt, content)
}) })
} }

View File

@ -65,7 +65,7 @@ func TestEncryptFile(t *testing.T) {
file, err := os.Create(path) file, err := os.Create(path)
defer os.Remove(path) defer os.Remove(path)
defer file.Close() defer file.Close()
t.Assert(err, nil) t.AssertNil(err)
_, _ = file.Write([]byte("Hello Go Frame")) _, _ = file.Write([]byte("Hello Go Frame"))
encryptFile, _ := gmd5.EncryptFile(path) encryptFile, _ := gmd5.EncryptFile(path)
t.AssertEQ(encryptFile, result) t.AssertEQ(encryptFile, result)

View File

@ -48,7 +48,7 @@ func TestEncryptFile(t *testing.T) {
file, err := os.Create(path) file, err := os.Create(path)
defer os.Remove(path) defer os.Remove(path)
defer file.Close() defer file.Close()
t.Assert(err, nil) t.AssertNil(err)
_, _ = file.Write([]byte("Hello Go Frame")) _, _ = file.Write([]byte("Hello Go Frame"))
encryptFile, _ := gsha1.EncryptFile(path) encryptFile, _ := gsha1.EncryptFile(path)
t.AssertEQ(encryptFile, result) t.AssertEQ(encryptFile, result)

View File

@ -353,20 +353,20 @@ PRIMARY KEY (id)
"id": i, "id": i,
"name": fmt.Sprintf(`name_%d`, i), "name": fmt.Sprintf(`name_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Detail. // Detail.
_, err = db.Insert(ctx, tableUserDetail, g.Map{ _, err = db.Insert(ctx, tableUserDetail, g.Map{
"uid": i, "uid": i,
"address": fmt.Sprintf(`address_%d`, i), "address": fmt.Sprintf(`address_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Scores. // Scores.
for j := 1; j <= 5; j++ { for j := 1; j <= 5; j++ {
_, err = db.Insert(ctx, tableUserScores, g.Map{ _, err = db.Insert(ctx, tableUserScores, g.Map{
"uid": i, "uid": i,
"score": j, "score": j,
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
} }
} }
@ -553,20 +553,20 @@ PRIMARY KEY (id)
"id": i, "id": i,
"name": fmt.Sprintf(`name_%d`, i), "name": fmt.Sprintf(`name_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Detail. // Detail.
_, err = db.Insert(ctx, tableUserDetail, g.Map{ _, err = db.Insert(ctx, tableUserDetail, g.Map{
"uid": i, "uid": i,
"address": fmt.Sprintf(`address_%d`, i), "address": fmt.Sprintf(`address_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Scores. // Scores.
for j := 1; j <= 5; j++ { for j := 1; j <= 5; j++ {
_, err = db.Insert(ctx, tableUserScores, g.Map{ _, err = db.Insert(ctx, tableUserScores, g.Map{
"uid": i, "uid": i,
"score": j, "score": j,
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
} }
} }
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
@ -668,20 +668,20 @@ PRIMARY KEY (id)
"id": i, "id": i,
"name": fmt.Sprintf(`name_%d`, i), "name": fmt.Sprintf(`name_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Detail. // Detail.
_, err = db.Insert(ctx, tableUserDetail, g.Map{ _, err = db.Insert(ctx, tableUserDetail, g.Map{
"uid": i, "uid": i,
"address": fmt.Sprintf(`address_%d`, i), "address": fmt.Sprintf(`address_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Scores. // Scores.
for j := 1; j <= 5; j++ { for j := 1; j <= 5; j++ {
_, err = db.Insert(ctx, tableUserScores, g.Map{ _, err = db.Insert(ctx, tableUserScores, g.Map{
"uid": i, "uid": i,
"score": j, "score": j,
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
} }
} }
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
@ -809,20 +809,20 @@ PRIMARY KEY (id)
"id": i, "id": i,
"name": fmt.Sprintf(`name_%d`, i), "name": fmt.Sprintf(`name_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Detail. // Detail.
_, err = db.Insert(ctx, tableUserDetail, g.Map{ _, err = db.Insert(ctx, tableUserDetail, g.Map{
"uid": i, "uid": i,
"address": fmt.Sprintf(`address_%d`, i), "address": fmt.Sprintf(`address_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Scores. // Scores.
for j := 1; j <= 5; j++ { for j := 1; j <= 5; j++ {
_, err = db.Insert(ctx, tableUserScores, g.Map{ _, err = db.Insert(ctx, tableUserScores, g.Map{
"uid": i, "uid": i,
"score": j, "score": j,
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
} }
} }
@ -945,20 +945,20 @@ PRIMARY KEY (id)
"id": i, "id": i,
"name": fmt.Sprintf(`name_%d`, i), "name": fmt.Sprintf(`name_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Detail. // Detail.
_, err = db.Insert(ctx, tableUserDetail, g.Map{ _, err = db.Insert(ctx, tableUserDetail, g.Map{
"uid": i, "uid": i,
"address": fmt.Sprintf(`address_%d`, i), "address": fmt.Sprintf(`address_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Scores. // Scores.
for j := 1; j <= 5; j++ { for j := 1; j <= 5; j++ {
_, err = db.Insert(ctx, tableUserScores, g.Map{ _, err = db.Insert(ctx, tableUserScores, g.Map{
"uid": i, "uid": i,
"score": j, "score": j,
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
} }
} }
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
@ -1065,20 +1065,20 @@ PRIMARY KEY (id)
"id": i, "id": i,
"name": fmt.Sprintf(`name_%d`, i), "name": fmt.Sprintf(`name_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Detail. // Detail.
_, err = db.Insert(ctx, tableUserDetail, g.Map{ _, err = db.Insert(ctx, tableUserDetail, g.Map{
"uid": i, "uid": i,
"address": fmt.Sprintf(`address_%d`, i), "address": fmt.Sprintf(`address_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Scores. // Scores.
for j := 1; j <= 5; j++ { for j := 1; j <= 5; j++ {
_, err = db.Insert(ctx, tableUserScores, g.Map{ _, err = db.Insert(ctx, tableUserScores, g.Map{
"uid": i, "uid": i,
"score": j, "score": j,
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
} }
} }
db.SetDebug(true) db.SetDebug(true)
@ -1184,20 +1184,20 @@ PRIMARY KEY (id)
"id": i, "id": i,
"name": fmt.Sprintf(`name_%d`, i), "name": fmt.Sprintf(`name_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Detail. // Detail.
_, err = db.Insert(ctx, tableUserDetail, g.Map{ _, err = db.Insert(ctx, tableUserDetail, g.Map{
"uid": i, "uid": i,
"address": fmt.Sprintf(`address_%d`, i), "address": fmt.Sprintf(`address_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Scores. // Scores.
for j := 1; j <= 5; j++ { for j := 1; j <= 5; j++ {
_, err = db.Insert(ctx, tableUserScores, g.Map{ _, err = db.Insert(ctx, tableUserScores, g.Map{
"uid": i, "uid": i,
"score": j, "score": j,
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
} }
} }
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
@ -1299,20 +1299,20 @@ PRIMARY KEY (id)
"id": i, "id": i,
"name": fmt.Sprintf(`name_%d`, i), "name": fmt.Sprintf(`name_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Detail. // Detail.
_, err = db.Insert(ctx, tableUserDetail, g.Map{ _, err = db.Insert(ctx, tableUserDetail, g.Map{
"uid": i, "uid": i,
"address": fmt.Sprintf(`address_%d`, i), "address": fmt.Sprintf(`address_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Scores. // Scores.
for j := 1; j <= 5; j++ { for j := 1; j <= 5; j++ {
_, err = db.Insert(ctx, tableUserScores, g.Map{ _, err = db.Insert(ctx, tableUserScores, g.Map{
"uid": i, "uid": i,
"score": j, "score": j,
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
} }
} }
@ -1439,20 +1439,20 @@ PRIMARY KEY (id)
"id": i, "id": i,
"name": fmt.Sprintf(`name_%d`, i), "name": fmt.Sprintf(`name_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Detail. // Detail.
_, err = db.Insert(ctx, tableUserDetail, g.Map{ _, err = db.Insert(ctx, tableUserDetail, g.Map{
"uid": i, "uid": i,
"address": fmt.Sprintf(`address_%d`, i), "address": fmt.Sprintf(`address_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Scores. // Scores.
for j := 1; j <= 5; j++ { for j := 1; j <= 5; j++ {
_, err = db.Insert(ctx, tableUserScores, g.Map{ _, err = db.Insert(ctx, tableUserScores, g.Map{
"uid": i, "uid": i,
"score": j, "score": j,
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
} }
} }
@ -1585,20 +1585,20 @@ PRIMARY KEY (id)
"id": i, "id": i,
"name": fmt.Sprintf(`name_%d`, i), "name": fmt.Sprintf(`name_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Detail. // Detail.
_, err = db.Insert(ctx, tableUserDetail, g.Map{ _, err = db.Insert(ctx, tableUserDetail, g.Map{
"uid": i, "uid": i,
"address": fmt.Sprintf(`address_%d`, i), "address": fmt.Sprintf(`address_%d`, i),
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
// Scores. // Scores.
for j := 1; j <= 5; j++ { for j := 1; j <= 5; j++ {
_, err = db.Insert(ctx, tableUserScores, g.Map{ _, err = db.Insert(ctx, tableUserScores, g.Map{
"uid": i, "uid": i,
"score": j, "score": j,
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
} }
} }

View File

@ -2067,7 +2067,7 @@ func Test_Model_OmitEmpty(t *testing.T) {
"id": 1, "id": 1,
"name": "", "name": "",
}).Save() }).Save()
t.Assert(err, nil) t.AssertNil(err)
}) })
} }
@ -2096,14 +2096,14 @@ func Test_Model_OmitNil(t *testing.T) {
"id": 1, "id": 1,
"name": "", "name": "",
}).Save() }).Save()
t.Assert(err, nil) t.AssertNil(err)
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
_, err := db.Model(table).OmitNilWhere().Data(g.Map{ _, err := db.Model(table).OmitNilWhere().Data(g.Map{
"id": 1, "id": 1,
"name": "", "name": "",
}).Save() }).Save()
t.Assert(err, nil) t.AssertNil(err)
}) })
} }

View File

@ -30,11 +30,11 @@ func TestConn_DoWithTimeout(t *testing.T) {
defer conn.Close(ctx) defer conn.Close(ctx)
_, err = conn.Do(ctx, "set", "test", "123") _, err = conn.Do(ctx, "set", "test", "123")
t.Assert(err, nil) t.AssertNil(err)
defer conn.Do(ctx, "del", "test") defer conn.Do(ctx, "del", "test")
r, err := conn.Do(ctx, "get", "test") r, err := conn.Do(ctx, "get", "test")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r.String(), "123") t.Assert(r.String(), "123")
}) })
} }

View File

@ -46,16 +46,16 @@ func Test_Do(t *testing.T) {
defer redis.Close(ctx) defer redis.Close(ctx)
_, err = redis.Do(ctx, "SET", "k", "v") _, err = redis.Do(ctx, "SET", "k", "v")
t.Assert(err, nil) t.AssertNil(err)
r, err := redis.Do(ctx, "GET", "k") r, err := redis.Do(ctx, "GET", "k")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r, []byte("v")) t.Assert(r, []byte("v"))
_, err = redis.Do(ctx, "DEL", "k") _, err = redis.Do(ctx, "DEL", "k")
t.Assert(err, nil) t.AssertNil(err)
r, err = redis.Do(ctx, "GET", "k") r, err = redis.Do(ctx, "GET", "k")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r, nil) t.Assert(r, nil)
}) })
} }
@ -74,16 +74,16 @@ func Test_Conn(t *testing.T) {
key := gconv.String(gtime.TimestampNano()) key := gconv.String(gtime.TimestampNano())
value := []byte("v") value := []byte("v")
r, err := conn.Do(ctx, "SET", key, value) r, err := conn.Do(ctx, "SET", key, value)
t.Assert(err, nil) t.AssertNil(err)
r, err = conn.Do(ctx, "GET", key) r, err = conn.Do(ctx, "GET", key)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r, value) t.Assert(r, value)
_, err = conn.Do(ctx, "DEL", key) _, err = conn.Do(ctx, "DEL", key)
t.Assert(err, nil) t.AssertNil(err)
r, err = conn.Do(ctx, "GET", key) r, err = conn.Do(ctx, "GET", key)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r, nil) t.Assert(r, nil)
}) })
} }
@ -102,16 +102,16 @@ func Test_Instance(t *testing.T) {
defer conn.Close(ctx) defer conn.Close(ctx)
_, err = conn.Do(ctx, "SET", "k", "v") _, err = conn.Do(ctx, "SET", "k", "v")
t.Assert(err, nil) t.AssertNil(err)
r, err := conn.Do(ctx, "GET", "k") r, err := conn.Do(ctx, "GET", "k")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r, []byte("v")) t.Assert(r, []byte("v"))
_, err = conn.Do(ctx, "DEL", "k") _, err = conn.Do(ctx, "DEL", "k")
t.Assert(err, nil) t.AssertNil(err)
r, err = conn.Do(ctx, "GET", "k") r, err = conn.Do(ctx, "GET", "k")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r, nil) t.Assert(r, nil)
}) })
} }
@ -153,10 +153,10 @@ func Test_Error(t *testing.T) {
defer redis.Close(ctx) defer redis.Close(ctx)
_, err = redis.Do(ctx, "SET", "k", "v") _, err = redis.Do(ctx, "SET", "k", "v")
t.Assert(err, nil) t.AssertNil(err)
v, err := redis.Do(ctx, "GET", "k") v, err := redis.Do(ctx, "GET", "k")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.String(), "v") t.Assert(v.String(), "v")
conn, err := redis.Conn(ctx) conn, err := redis.Conn(ctx)
@ -197,17 +197,17 @@ func Test_Bool(t *testing.T) {
}() }()
_, err = redis.Do(ctx, "SET", "key-true", true) _, err = redis.Do(ctx, "SET", "key-true", true)
t.Assert(err, nil) t.AssertNil(err)
_, err = redis.Do(ctx, "SET", "key-false", false) _, err = redis.Do(ctx, "SET", "key-false", false)
t.Assert(err, nil) t.AssertNil(err)
r, err := redis.Do(ctx, "GET", "key-true") r, err := redis.Do(ctx, "GET", "key-true")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r.Bool(), true) t.Assert(r.Bool(), true)
r, err = redis.Do(ctx, "GET", "key-false") r, err = redis.Do(ctx, "GET", "key-false")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r.Bool(), false) t.Assert(r.Bool(), false)
}) })
} }
@ -223,10 +223,10 @@ func Test_Int(t *testing.T) {
defer redis.Do(ctx, "DEL", key) defer redis.Do(ctx, "DEL", key)
_, err = redis.Do(ctx, "SET", key, 1) _, err = redis.Do(ctx, "SET", key, 1)
t.Assert(err, nil) t.AssertNil(err)
r, err := redis.Do(ctx, "GET", key) r, err := redis.Do(ctx, "GET", key)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r.Int(), 1) t.Assert(r.Int(), 1)
}) })
} }
@ -242,10 +242,10 @@ func Test_HSet(t *testing.T) {
defer redis.Do(ctx, "DEL", key) defer redis.Do(ctx, "DEL", key)
_, err = redis.Do(ctx, "HSET", key, "name", "john") _, err = redis.Do(ctx, "HSET", key, "name", "john")
t.Assert(err, nil) t.AssertNil(err)
r, err := redis.Do(ctx, "HGETALL", key) r, err := redis.Do(ctx, "HGETALL", key)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r.Strings(), g.ArrayStr{"name", "john"}) t.Assert(r.Strings(), g.ArrayStr{"name", "john"})
}) })
} }
@ -262,12 +262,12 @@ func Test_HGetAll1(t *testing.T) {
defer redis.Do(ctx, "DEL", key) defer redis.Do(ctx, "DEL", key)
_, err = redis.Do(ctx, "HSET", key, "id", 100) _, err = redis.Do(ctx, "HSET", key, "id", 100)
t.Assert(err, nil) t.AssertNil(err)
_, err = redis.Do(ctx, "HSET", key, "name", "john") _, err = redis.Do(ctx, "HSET", key, "name", "john")
t.Assert(err, nil) t.AssertNil(err)
r, err := redis.Do(ctx, "HGETALL", key) r, err := redis.Do(ctx, "HGETALL", key)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r.Map(), g.MapStrAny{ t.Assert(r.Map(), g.MapStrAny{
"id": 100, "id": 100,
"name": "john", "name": "john",
@ -287,12 +287,12 @@ func Test_HGetAll2(t *testing.T) {
defer redis.Do(ctx, "DEL", key) defer redis.Do(ctx, "DEL", key)
_, err = redis.Do(ctx, "HSET", key, "id", 100) _, err = redis.Do(ctx, "HSET", key, "id", 100)
t.Assert(err, nil) t.AssertNil(err)
_, err = redis.Do(ctx, "HSET", key, "name", "john") _, err = redis.Do(ctx, "HSET", key, "name", "john")
t.Assert(err, nil) t.AssertNil(err)
result, err := redis.Do(ctx, "HGETALL", key) result, err := redis.Do(ctx, "HGETALL", key)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(gconv.Uint(result.MapStrVar()["id"]), 100) t.Assert(gconv.Uint(result.MapStrVar()["id"]), 100)
t.Assert(result.MapStrVar()["id"].Uint(), 100) t.Assert(result.MapStrVar()["id"].Uint(), 100)
@ -317,9 +317,9 @@ func Test_HMSet(t *testing.T) {
defer redis.Do(ctx, "DEL", key) defer redis.Do(ctx, "DEL", key)
_, err = redis.Do(ctx, "HMSET", append(g.Slice{key}, gutil.MapToSlice(data)...)...) _, err = redis.Do(ctx, "HMSET", append(g.Slice{key}, gutil.MapToSlice(data)...)...)
t.Assert(err, nil) t.AssertNil(err)
v, err := redis.Do(ctx, "HMGET", key, "name") v, err := redis.Do(ctx, "HMGET", key, "name")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Slice(), g.Slice{data["name"]}) t.Assert(v.Slice(), g.Slice{data["name"]})
}) })
// struct // struct
@ -344,9 +344,9 @@ func Test_HMSet(t *testing.T) {
defer redis.Do(ctx, "DEL", key) defer redis.Do(ctx, "DEL", key)
_, err = redis.Do(ctx, "HMSET", append(g.Slice{key}, gutil.StructToSlice(data)...)...) _, err = redis.Do(ctx, "HMSET", append(g.Slice{key}, gutil.StructToSlice(data)...)...)
t.Assert(err, nil) t.AssertNil(err)
v, err := redis.Do(ctx, "HMGET", key, "name") v, err := redis.Do(ctx, "HMGET", key, "name")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Slice(), g.Slice{data.Name}) t.Assert(v.Slice(), g.Slice{data.Name})
}) })
} }
@ -374,10 +374,10 @@ func Test_Auto_Marshal(t *testing.T) {
} }
_, err = redis.Do(ctx, "SET", key, user) _, err = redis.Do(ctx, "SET", key, user)
t.Assert(err, nil) t.AssertNil(err)
r, err := redis.Do(ctx, "GET", key) r, err := redis.Do(ctx, "GET", key)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r.Map(), g.MapStrAny{ t.Assert(r.Map(), g.MapStrAny{
"Id": user.Id, "Id": user.Id,
"Name": user.Name, "Name": user.Name,
@ -418,14 +418,14 @@ func Test_Auto_MarshalSlice(t *testing.T) {
) )
_, err = redis.Do(ctx, "SET", key, users1) _, err = redis.Do(ctx, "SET", key, users1)
t.Assert(err, nil) t.AssertNil(err)
result, err = redis.Do(ctx, "GET", key) result, err = redis.Do(ctx, "GET", key)
t.Assert(err, nil) t.AssertNil(err)
var users2 []User var users2 []User
err = result.Structs(&users2) err = result.Structs(&users2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(users2, users1) t.Assert(users2, users1)
}) })
} }

View File

@ -70,12 +70,12 @@ func Test_File(t *testing.T) {
expect := "dGVzdA==" expect := "dGVzdA=="
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
b, err := gbase64.EncodeFile(path) b, err := gbase64.EncodeFile(path)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(b), expect) t.Assert(string(b), expect)
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
s, err := gbase64.EncodeFileToString(path) s, err := gbase64.EncodeFileToString(path)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(s, expect) t.Assert(s, expect)
}) })
} }

View File

@ -50,13 +50,13 @@ func Test_Gzip_UnGzip_File(t *testing.T) {
// Compress. // Compress.
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
err := gcompress.GzipFile(srcPath, dstPath1, 9) err := gcompress.GzipFile(srcPath, dstPath1, 9)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(dstPath1) defer gfile.Remove(dstPath1)
t.Assert(gfile.Exists(dstPath1), true) t.Assert(gfile.Exists(dstPath1), true)
// Decompress. // Decompress.
err = gcompress.UnGzipFile(dstPath1, dstPath2) err = gcompress.UnGzipFile(dstPath1, dstPath2)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(dstPath2) defer gfile.Remove(dstPath2)
t.Assert(gfile.Exists(dstPath2), true) t.Assert(gfile.Exists(dstPath2), true)

View File

@ -52,7 +52,7 @@ func Test_ZipPath(t *testing.T) {
t.Assert(gfile.Exists(dstPath), false) t.Assert(gfile.Exists(dstPath), false)
err := gcompress.ZipPath(srcPath1+","+srcPath2, dstPath) err := gcompress.ZipPath(srcPath1+","+srcPath2, dstPath)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(gfile.Exists(dstPath), true) t.Assert(gfile.Exists(dstPath), true)
defer gfile.Remove(dstPath) defer gfile.Remove(dstPath)
@ -60,7 +60,7 @@ func Test_ZipPath(t *testing.T) {
tempDirPath := gfile.Temp(gtime.TimestampNanoStr()) tempDirPath := gfile.Temp(gtime.TimestampNanoStr())
t.Assert(gfile.Mkdir(tempDirPath), nil) t.Assert(gfile.Mkdir(tempDirPath), nil)
err = gcompress.UnZipFile(dstPath, tempDirPath) err = gcompress.UnZipFile(dstPath, tempDirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(tempDirPath) defer gfile.Remove(tempDirPath)
t.Assert( t.Assert(
@ -85,7 +85,7 @@ func Test_ZipPath(t *testing.T) {
t.Assert(gfile.Exists(dstPath), false) t.Assert(gfile.Exists(dstPath), false)
err := gcompress.ZipPath(srcPath1+","+srcPath2, dstPath) err := gcompress.ZipPath(srcPath1+","+srcPath2, dstPath)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(gfile.Exists(dstPath), true) t.Assert(gfile.Exists(dstPath), true)
defer gfile.Remove(dstPath) defer gfile.Remove(dstPath)
@ -93,7 +93,7 @@ func Test_ZipPath(t *testing.T) {
tempDirPath := gfile.Temp(gtime.TimestampNanoStr()) tempDirPath := gfile.Temp(gtime.TimestampNanoStr())
t.Assert(gfile.Mkdir(tempDirPath), nil) t.Assert(gfile.Mkdir(tempDirPath), nil)
err = gcompress.UnZipFile(dstPath, tempDirPath) err = gcompress.UnZipFile(dstPath, tempDirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(tempDirPath) defer gfile.Remove(tempDirPath)
t.Assert( t.Assert(
@ -113,20 +113,20 @@ func Test_ZipPath(t *testing.T) {
pwd := gfile.Pwd() pwd := gfile.Pwd()
err := gfile.Chdir(srcPath) err := gfile.Chdir(srcPath)
defer gfile.Chdir(pwd) defer gfile.Chdir(pwd)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(gfile.Exists(dstPath), false) t.Assert(gfile.Exists(dstPath), false)
err = gcompress.ZipPath(srcPath, dstPath) err = gcompress.ZipPath(srcPath, dstPath)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(gfile.Exists(dstPath), true) t.Assert(gfile.Exists(dstPath), true)
defer gfile.Remove(dstPath) defer gfile.Remove(dstPath)
tempDirPath := gfile.Temp(gtime.TimestampNanoStr()) tempDirPath := gfile.Temp(gtime.TimestampNanoStr())
err = gfile.Mkdir(tempDirPath) err = gfile.Mkdir(tempDirPath)
t.Assert(err, nil) t.AssertNil(err)
err = gcompress.UnZipFile(dstPath, tempDirPath) err = gcompress.UnZipFile(dstPath, tempDirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(tempDirPath) defer gfile.Remove(tempDirPath)
t.Assert( t.Assert(
@ -149,22 +149,22 @@ func Test_ZipPath(t *testing.T) {
pwd := gfile.Pwd() pwd := gfile.Pwd()
err := gfile.Chdir(srcPath) err := gfile.Chdir(srcPath)
defer gfile.Chdir(pwd) defer gfile.Chdir(pwd)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(gfile.Exists(dstPath), false) t.Assert(gfile.Exists(dstPath), false)
err = gcompress.ZipPath(srcPath1+", "+srcPath2, dstPath) err = gcompress.ZipPath(srcPath1+", "+srcPath2, dstPath)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(gfile.Exists(dstPath), true) t.Assert(gfile.Exists(dstPath), true)
defer gfile.Remove(dstPath) defer gfile.Remove(dstPath)
tempDirPath := gfile.Temp(gtime.TimestampNanoStr()) tempDirPath := gfile.Temp(gtime.TimestampNanoStr())
err = gfile.Mkdir(tempDirPath) err = gfile.Mkdir(tempDirPath)
t.Assert(err, nil) t.AssertNil(err)
zipContent := gfile.GetBytes(dstPath) zipContent := gfile.GetBytes(dstPath)
t.AssertGT(len(zipContent), 0) t.AssertGT(len(zipContent), 0)
err = gcompress.UnZipContent(zipContent, tempDirPath) err = gcompress.UnZipContent(zipContent, tempDirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(tempDirPath) defer gfile.Remove(tempDirPath)
t.Assert( t.Assert(
@ -188,22 +188,22 @@ func Test_ZipPathWriter(t *testing.T) {
pwd := gfile.Pwd() pwd := gfile.Pwd()
err := gfile.Chdir(srcPath) err := gfile.Chdir(srcPath)
defer gfile.Chdir(pwd) defer gfile.Chdir(pwd)
t.Assert(err, nil) t.AssertNil(err)
writer := bytes.NewBuffer(nil) writer := bytes.NewBuffer(nil)
t.Assert(writer.Len(), 0) t.Assert(writer.Len(), 0)
err = gcompress.ZipPathWriter(srcPath1+", "+srcPath2, writer) err = gcompress.ZipPathWriter(srcPath1+", "+srcPath2, writer)
t.Assert(err, nil) t.AssertNil(err)
t.AssertGT(writer.Len(), 0) t.AssertGT(writer.Len(), 0)
tempDirPath := gfile.Temp(gtime.TimestampNanoStr()) tempDirPath := gfile.Temp(gtime.TimestampNanoStr())
err = gfile.Mkdir(tempDirPath) err = gfile.Mkdir(tempDirPath)
t.Assert(err, nil) t.AssertNil(err)
zipContent := writer.Bytes() zipContent := writer.Bytes()
t.AssertGT(len(zipContent), 0) t.AssertGT(len(zipContent), 0)
err = gcompress.UnZipContent(zipContent, tempDirPath) err = gcompress.UnZipContent(zipContent, tempDirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(tempDirPath) defer gfile.Remove(tempDirPath)
t.Assert( t.Assert(

View File

@ -47,7 +47,7 @@ func Test_SpecialCharsMapOrStruct_Map(t *testing.T) {
"Content": "<div>C</div>", "Content": "<div>C</div>",
} }
err := ghtml.SpecialCharsMapOrStruct(a) err := ghtml.SpecialCharsMapOrStruct(a)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a["Title"], `&lt;h1&gt;T&lt;/h1&gt;`) t.Assert(a["Title"], `&lt;h1&gt;T&lt;/h1&gt;`)
t.Assert(a["Content"], `&lt;div&gt;C&lt;/div&gt;`) t.Assert(a["Content"], `&lt;div&gt;C&lt;/div&gt;`)
}) })
@ -57,7 +57,7 @@ func Test_SpecialCharsMapOrStruct_Map(t *testing.T) {
"Content": "<div>C</div>", "Content": "<div>C</div>",
} }
err := ghtml.SpecialCharsMapOrStruct(a) err := ghtml.SpecialCharsMapOrStruct(a)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a["Title"], `&lt;h1&gt;T&lt;/h1&gt;`) t.Assert(a["Title"], `&lt;h1&gt;T&lt;/h1&gt;`)
t.Assert(a["Content"], `&lt;div&gt;C&lt;/div&gt;`) t.Assert(a["Content"], `&lt;div&gt;C&lt;/div&gt;`)
}) })
@ -74,7 +74,7 @@ func Test_SpecialCharsMapOrStruct_Struct(t *testing.T) {
Content: "<div>C</div>", Content: "<div>C</div>",
} }
err := ghtml.SpecialCharsMapOrStruct(a) err := ghtml.SpecialCharsMapOrStruct(a)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(a.Title, `&lt;h1&gt;T&lt;/h1&gt;`) t.Assert(a.Title, `&lt;h1&gt;T&lt;/h1&gt;`)
t.Assert(a.Content, `&lt;div&gt;C&lt;/div&gt;`) t.Assert(a.Content, `&lt;div&gt;C&lt;/div&gt;`)
}) })

View File

@ -97,7 +97,7 @@ func TestToJson(t *testing.T) {
} }
iniMap, err := gini.Decode([]byte(iniContent)) iniMap, err := gini.Decode([]byte(iniContent))
t.Assert(err, nil) t.AssertNil(err)
t.Assert(iniMap["addr"].(map[string]interface{})["ip"], json.Get("addr.ip").String()) t.Assert(iniMap["addr"].(map[string]interface{})["ip"], json.Get("addr.ip").String())
t.Assert(iniMap["addr"].(map[string]interface{})["port"], json.Get("addr.port").String()) t.Assert(iniMap["addr"].(map[string]interface{})["port"], json.Get("addr.port").String())

View File

@ -36,7 +36,7 @@ func Test_ToJson(t *testing.T) {
jsonContent := `{"dataSetId":2001,"fieldInfos":{"duration":{"id":80079,"value":"59"},"om_level":{"id":2409,"value":"4"}},"id":"g0936lt1u0f","modifyFieldInfos":{"om_level":{"id":2409,"new":"4","old":""}},"timeStamp":1584599734}` jsonContent := `{"dataSetId":2001,"fieldInfos":{"duration":{"id":80079,"value":"59"},"om_level":{"id":2409,"value":"4"}},"id":"g0936lt1u0f","modifyFieldInfos":{"om_level":{"id":2409,"new":"4","old":""}},"timeStamp":1584599734}`
var info MediaRequestModifyInfo var info MediaRequestModifyInfo
err := gjson.DecodeTo(jsonContent, &info) err := gjson.DecodeTo(jsonContent, &info)
t.Assert(err, nil) t.AssertNil(err)
content := gjson.New(info).MustToJsonString() content := gjson.New(info).MustToJsonString()
t.Assert(gstr.Contains(content, `"feed_id":""`), true) t.Assert(gstr.Contains(content, `"feed_id":""`), true)
t.Assert(gstr.Contains(content, `"fieldInfos":{`), true) t.Assert(gstr.Contains(content, `"fieldInfos":{`), true)
@ -56,14 +56,14 @@ func Test_MapAttributeConvert(t *testing.T) {
` `
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.LoadContent(data) j, err := gjson.LoadContent(data)
gtest.Assert(err, nil) gtest.AssertNil(err)
tx := struct { tx := struct {
Title map[string]interface{} Title map[string]interface{}
}{} }{}
err = j.Var().Scan(&tx) err = j.Var().Scan(&tx)
gtest.Assert(err, nil) gtest.AssertNil(err)
t.Assert(tx.Title, g.Map{ t.Assert(tx.Title, g.Map{
"l1": "标签1", "l2": "标签2", "l1": "标签1", "l2": "标签2",
}) })
@ -76,14 +76,14 @@ func Test_MapAttributeConvert(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.LoadContent(data) j, err := gjson.LoadContent(data)
gtest.Assert(err, nil) gtest.AssertNil(err)
tx := struct { tx := struct {
Title map[string]string Title map[string]string
}{} }{}
err = j.Var().Scan(&tx) err = j.Var().Scan(&tx)
gtest.Assert(err, nil) gtest.AssertNil(err)
t.Assert(tx.Title, g.Map{ t.Assert(tx.Title, g.Map{
"l1": "标签1", "l2": "标签2", "l1": "标签1", "l2": "标签2",
}) })

View File

@ -20,7 +20,7 @@ func Test_Load_JSON1(t *testing.T) {
// JSON // JSON
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.LoadContent(data) j, err := gjson.LoadContent(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789") t.Assert(j.Get("n").String(), "123456789")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("m.k").String(), "v") t.Assert(j.Get("m.k").String(), "v")
@ -39,7 +39,7 @@ func Test_Load_JSON1(t *testing.T) {
gfile.PutBytes(path, data) gfile.PutBytes(path, data)
defer gfile.Remove(path) defer gfile.Remove(path)
j, err := gjson.Load(path, true) j, err := gjson.Load(path, true)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789") t.Assert(j.Get("n").String(), "123456789")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("m.k").String(), "v") t.Assert(j.Get("m.k").String(), "v")
@ -52,7 +52,7 @@ func Test_Load_JSON2(t *testing.T) {
data := []byte(`{"n":123456789000000000000, "m":{"k":"v"}, "a":[1,2,3]}`) data := []byte(`{"n":123456789000000000000, "m":{"k":"v"}, "a":[1,2,3]}`)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.LoadContent(data) j, err := gjson.LoadContent(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789000000000000") t.Assert(j.Get("n").String(), "123456789000000000000")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("m.k").String(), "v") t.Assert(j.Get("m.k").String(), "v")
@ -66,7 +66,7 @@ func Test_Load_XML(t *testing.T) {
// XML // XML
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.LoadContent(data) j, err := gjson.LoadContent(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("doc.n").String(), "123456789") t.Assert(j.Get("doc.n").String(), "123456789")
t.Assert(j.Get("doc.m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("doc.m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("doc.m.k").String(), "v") t.Assert(j.Get("doc.m.k").String(), "v")
@ -76,7 +76,7 @@ func Test_Load_XML(t *testing.T) {
// XML // XML
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.LoadXml(data, true) j, err := gjson.LoadXml(data, true)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("doc.n").String(), "123456789") t.Assert(j.Get("doc.n").String(), "123456789")
t.Assert(j.Get("doc.m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("doc.m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("doc.m.k").String(), "v") t.Assert(j.Get("doc.m.k").String(), "v")
@ -95,7 +95,7 @@ func Test_Load_XML(t *testing.T) {
gfile.PutBytes(path, data) gfile.PutBytes(path, data)
defer gfile.Remove(path) defer gfile.Remove(path)
j, err := gjson.Load(path) j, err := gjson.Load(path)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("doc.n").String(), "123456789") t.Assert(j.Get("doc.n").String(), "123456789")
t.Assert(j.Get("doc.m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("doc.m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("doc.m.k").String(), "v") t.Assert(j.Get("doc.m.k").String(), "v")
@ -116,7 +116,7 @@ func Test_Load_XML(t *testing.T) {
<nworkOrderFrontXML/> <nworkOrderFrontXML/>
</Output>` </Output>`
j, err := gjson.LoadContent(xml) j, err := gjson.LoadContent(xml)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("Output.ipageIndex"), "2") t.Assert(j.Get("Output.ipageIndex"), "2")
t.Assert(j.Get("Output.itotalRecords"), "GF框架") t.Assert(j.Get("Output.itotalRecords"), "GF框架")
}) })
@ -135,7 +135,7 @@ m:
// YAML // YAML
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.LoadContent(data) j, err := gjson.LoadContent(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789") t.Assert(j.Get("n").String(), "123456789")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("m.k").String(), "v") t.Assert(j.Get("m.k").String(), "v")
@ -145,7 +145,7 @@ m:
// YAML // YAML
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.LoadYaml(data, true) j, err := gjson.LoadYaml(data, true)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789") t.Assert(j.Get("n").String(), "123456789")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("m.k").String(), "v") t.Assert(j.Get("m.k").String(), "v")
@ -158,7 +158,7 @@ m:
gfile.PutBytes(path, data) gfile.PutBytes(path, data)
defer gfile.Remove(path) defer gfile.Remove(path)
j, err := gjson.Load(path) j, err := gjson.Load(path)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789") t.Assert(j.Get("n").String(), "123456789")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("m.k").String(), "v") t.Assert(j.Get("m.k").String(), "v")
@ -171,7 +171,7 @@ func Test_Load_YAML2(t *testing.T) {
data := []byte("i : 123456789") data := []byte("i : 123456789")
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.LoadContent(data) j, err := gjson.LoadContent(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("i"), "123456789") t.Assert(j.Get("i"), "123456789")
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
@ -192,7 +192,7 @@ n = 123456789
// TOML // TOML
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.LoadContent(data) j, err := gjson.LoadContent(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789") t.Assert(j.Get("n").String(), "123456789")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("m.k").String(), "v") t.Assert(j.Get("m.k").String(), "v")
@ -202,7 +202,7 @@ n = 123456789
// TOML // TOML
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.LoadToml(data, true) j, err := gjson.LoadToml(data, true)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789") t.Assert(j.Get("n").String(), "123456789")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("m.k").String(), "v") t.Assert(j.Get("m.k").String(), "v")
@ -215,7 +215,7 @@ n = 123456789
gfile.PutBytes(path, data) gfile.PutBytes(path, data)
defer gfile.Remove(path) defer gfile.Remove(path)
j, err := gjson.Load(path) j, err := gjson.Load(path)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789") t.Assert(j.Get("n").String(), "123456789")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("m.k").String(), "v") t.Assert(j.Get("m.k").String(), "v")
@ -228,7 +228,7 @@ func Test_Load_TOML2(t *testing.T) {
data := []byte("i=123456789") data := []byte("i=123456789")
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.LoadContent(data) j, err := gjson.LoadContent(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("i"), "123456789") t.Assert(j.Get("i"), "123456789")
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
@ -247,11 +247,11 @@ func Test_Load_Basic(t *testing.T) {
_, err = gjson.DecodeToJson(nil) _, err = gjson.DecodeToJson(nil)
t.AssertNE(err, nil) t.AssertNE(err, nil)
j, err = gjson.LoadContent(nil) j, err = gjson.LoadContent(nil)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Interface(), nil) t.Assert(j.Interface(), nil)
j, err = gjson.LoadContent(`{"name": "gf"}`) j, err = gjson.LoadContent(`{"name": "gf"}`)
t.Assert(err, nil) t.AssertNil(err)
j, err = gjson.LoadContent(`{"name": "gf"""}`) j, err = gjson.LoadContent(`{"name": "gf"""}`)
t.AssertNE(err, nil) t.AssertNE(err, nil)

View File

@ -65,7 +65,7 @@ func Test_New_CustomStruct(t *testing.T) {
t.AssertNE(j, nil) t.AssertNE(j, nil)
s, err := j.ToJsonString() s, err := j.ToJsonString()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(s == `{"Id":1,"Name":"john"}` || s == `{"Name":"john","Id":1}`, true) t.Assert(s == `{"Id":1,"Name":"john"}` || s == `{"Name":"john","Id":1}`, true)
}) })
} }

View File

@ -236,7 +236,7 @@ func Test_Set15(t *testing.T) {
t.Assert(j.Set("k", "v"), nil) t.Assert(j.Set("k", "v"), nil)
s, err := j.ToJsonString() s, err := j.ToJsonString()
t.Assert(err, nil) t.AssertNil(err)
t.Assert( t.Assert(
gstr.Contains(s, `"root":[{"k1":"v1"},{"k2":"v2"}`) || gstr.Contains(s, `"root":[{"k1":"v1"},{"k2":"v2"}`) ||
gstr.Contains(s, `"root":[{"k2":"v2"},{"k1":"v1"}`), gstr.Contains(s, `"root":[{"k2":"v2"},{"k1":"v1"}`),
@ -259,7 +259,7 @@ func Test_Set16(t *testing.T) {
t.Assert(j.Set("description", "3"), nil) t.Assert(j.Set("description", "3"), nil)
s, err := j.ToJsonString() s, err := j.ToJsonString()
t.Assert(err, nil) t.AssertNil(err)
t.Assert( t.Assert(
gstr.Contains(s, `"processors":[{"set":{"0field":"2","0value":"1"}}]`) || gstr.Contains(s, `"processors":[{"set":{"0field":"2","0value":"1"}}]`) ||
gstr.Contains(s, `"processors":[{"set":{"0value":"1","0field":"2"}}]`), gstr.Contains(s, `"processors":[{"set":{"0value":"1","0field":"2"}}]`),
@ -282,7 +282,7 @@ func Test_Set17(t *testing.T) {
t.Assert(j.Set("k", "v"), nil) t.Assert(j.Set("k", "v"), nil)
s, err := j.ToJsonString() s, err := j.ToJsonString()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(s, `{"k":"v"}`) t.Assert(s, `{"k":"v"}`)
}) })
} }
@ -294,7 +294,7 @@ func Test_Set18(t *testing.T) {
t.Assert(j.Set("0.1.k1", "v1"), nil) t.Assert(j.Set("0.1.k1", "v1"), nil)
t.Assert(j.Set("0.2.k2", "v2"), nil) t.Assert(j.Set("0.2.k2", "v2"), nil)
s, err := j.ToJsonString() s, err := j.ToJsonString()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(s, `[[null,{"k1":"v1"},{"k2":"v2"}]]`) t.Assert(s, `[[null,{"k1":"v1"},{"k2":"v2"}]]`)
}) })
} }
@ -306,7 +306,7 @@ func Test_Set19(t *testing.T) {
t.Assert(j.Set("0.1.1.k1", "v1"), nil) t.Assert(j.Set("0.1.1.k1", "v1"), nil)
t.Assert(j.Set("0.2.1.k2", "v2"), nil) t.Assert(j.Set("0.2.1.k2", "v2"), nil)
s, err := j.ToJsonString() s, err := j.ToJsonString()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(s, `[[null,[null,{"k1":"v1"}],[null,{"k2":"v2"}]]]`) t.Assert(s, `[[null,[null,{"k1":"v1"}],[null,{"k2":"v2"}]]]`)
}) })
} }
@ -320,7 +320,7 @@ func Test_Set20(t *testing.T) {
t.Assert(j.Set("k2.1", 20), nil) t.Assert(j.Set("k2.1", 20), nil)
t.Assert(j.Set("k2.2", g.Map{"k3": "v3"}), nil) t.Assert(j.Set("k2.2", g.Map{"k3": "v3"}), nil)
s, err := j.ToJsonString() s, err := j.ToJsonString()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(gstr.InArray( t.Assert(gstr.InArray(
g.SliceStr{ g.SliceStr{
`{"k1":"v1","k2":[1,20,{"k3":"v3"}]}`, `{"k1":"v1","k2":[1,20,{"k3":"v3"}]}`,

View File

@ -22,7 +22,7 @@ func Test_GetScan(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
var user *User var user *User
err := j.Get("1").Scan(&user) err := j.Get("1").Scan(&user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user, &User{ t.Assert(user, &User{
Name: "smith", Name: "smith",
Score: 60, Score: 60,
@ -31,7 +31,7 @@ func Test_GetScan(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
var users []User var users []User
err := j.Get(".").Scan(&users) err := j.Get(".").Scan(&users)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(users, []User{ t.Assert(users, []User{
{ {
Name: "john", Name: "john",
@ -54,7 +54,7 @@ func Test_GetScanDeep(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
var user *User var user *User
err := j.Get("1").Scan(&user) err := j.Get("1").Scan(&user)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(user, &User{ t.Assert(user, &User{
Name: "smith", Name: "smith",
Score: 60, Score: 60,
@ -63,7 +63,7 @@ func Test_GetScanDeep(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
var users []User var users []User
err := j.Get(".").Scan(&users) err := j.Get(".").Scan(&users)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(users, []User{ t.Assert(users, []User{
{ {
Name: "john", Name: "john",
@ -86,7 +86,7 @@ func Test_Scan1(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
var users []User var users []User
err := j.Var().Scan(&users) err := j.Var().Scan(&users)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(users, []User{ t.Assert(users, []User{
{ {
Name: "john", Name: "john",
@ -109,7 +109,7 @@ func Test_Scan2(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
var users []User var users []User
err := j.Var().Scan(&users) err := j.Var().Scan(&users)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(users, []User{ t.Assert(users, []User{
{ {
Name: "john", Name: "john",
@ -198,9 +198,9 @@ func Test_Struct1(t *testing.T) {
}` }`
data := new(UserCollectionAddReq) data := new(UserCollectionAddReq)
j, err := gjson.LoadJson(jsonContent, true) j, err := gjson.LoadJson(jsonContent, true)
t.Assert(err, nil) t.AssertNil(err)
err = j.Scan(data) err = j.Scan(data)
t.Assert(err, nil) t.AssertNil(err)
}) })
} }
@ -226,14 +226,14 @@ func Test_Struct(t *testing.T) {
}` }`
j, err := gjson.LoadContent(txt) j, err := gjson.LoadContent(txt)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("me.name").String(), "mikey") t.Assert(j.Get("me.name").String(), "mikey")
t.Assert(j.Get("items").String(), "") t.Assert(j.Get("items").String(), "")
t.Assert(j.Get("items").Bool(), false) t.Assert(j.Get("items").Bool(), false)
t.Assert(j.Get("items").Array(), nil) t.Assert(j.Get("items").Array(), nil)
m := new(M) m := new(M)
err = j.Scan(m) err = j.Scan(m)
t.Assert(err, nil) t.AssertNil(err)
t.AssertNE(m.Me, nil) t.AssertNE(m.Me, nil)
t.Assert(m.Me["day"], "20009") t.Assert(m.Me["day"], "20009")
t.Assert(m.Items, nil) t.Assert(m.Items, nil)
@ -289,10 +289,10 @@ func Test_Struct_Complicated(t *testing.T) {
] ]
}` }`
j, err := gjson.LoadContent(jsonContent) j, err := gjson.LoadContent(jsonContent)
t.Assert(err, nil) t.AssertNil(err)
var response = new(Response) var response = new(Response)
err = j.Scan(response) err = j.Scan(response)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(response.CertList), 3) t.Assert(len(response.CertList), 3)
t.Assert(response.CertList[0].CertID, 2023313) t.Assert(response.CertList[0].CertID, 2023313)
t.Assert(response.CertList[1].CertID, 2023314) t.Assert(response.CertList[1].CertID, 2023314)

View File

@ -24,7 +24,7 @@ func TestJson_UnmarshalJSON(t *testing.T) {
j = gjson.New(nil) j = gjson.New(nil)
err = json.UnmarshalUseNumber(data, j) err = json.UnmarshalUseNumber(data, j)
) )
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get(".").String(), `["a","b","c"]`) t.Assert(j.Get(".").String(), `["a","b","c"]`)
t.Assert(j.Get("2").String(), `c`) t.Assert(j.Get("2").String(), `c`)
}) })
@ -35,7 +35,7 @@ func TestJson_UnmarshalJSON(t *testing.T) {
j = gjson.New(nil) j = gjson.New(nil)
err = json.UnmarshalUseNumber(data, j) err = json.UnmarshalUseNumber(data, j)
) )
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get(".").String(), `[{"a":1},{"b":2},{"c":3}]`) t.Assert(j.Get(".").String(), `[{"a":1},{"b":2},{"c":3}]`)
t.Assert(j.Get("2.c").String(), `3`) t.Assert(j.Get("2.c").String(), `3`)
}) })
@ -46,7 +46,7 @@ func TestJson_UnmarshalJSON(t *testing.T) {
j = gjson.New(nil) j = gjson.New(nil)
err = json.UnmarshalUseNumber(data, j) err = json.UnmarshalUseNumber(data, j)
) )
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789") t.Assert(j.Get("n").String(), "123456789")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("m.k").String(), "v") t.Assert(j.Get("m.k").String(), "v")
@ -68,7 +68,7 @@ func TestJson_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"json": []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`), "json": []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`),
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Json.Get("n").String(), "123456789") t.Assert(v.Json.Get("n").String(), "123456789")
t.Assert(v.Json.Get("m").Map(), g.Map{"k": "v"}) t.Assert(v.Json.Get("m").Map(), g.Map{"k": "v"})
@ -83,7 +83,7 @@ func TestJson_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"json": `["a", "b", "c"]`, "json": `["a", "b", "c"]`,
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Json.Get(".").String(), `["a","b","c"]`) t.Assert(v.Json.Get(".").String(), `["a","b","c"]`)
t.Assert(v.Json.Get("2").String(), `c`) t.Assert(v.Json.Get("2").String(), `c`)
@ -95,7 +95,7 @@ func TestJson_UnmarshalValue(t *testing.T) {
"name": "john", "name": "john",
"json": `[{"a":1},{"b":2},{"c":3}]`, "json": `[{"a":1},{"b":2},{"c":3}]`,
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Json.Get(".").String(), `[{"a":1},{"b":2},{"c":3}]`) t.Assert(v.Json.Get(".").String(), `[{"a":1},{"b":2},{"c":3}]`)
t.Assert(v.Json.Get("2.c").String(), `3`) t.Assert(v.Json.Get("2.c").String(), `3`)
@ -111,7 +111,7 @@ func TestJson_UnmarshalValue(t *testing.T) {
"a": g.Slice{1, 2, 3}, "a": g.Slice{1, 2, 3},
}, },
}, &v) }, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v.Name, "john") t.Assert(v.Name, "john")
t.Assert(v.Json.Get("n").String(), "123456789") t.Assert(v.Json.Get("n").String(), "123456789")
t.Assert(v.Json.Get("m").Map(), g.Map{"k": "v"}) t.Assert(v.Json.Get("m").Map(), g.Map{"k": "v"})

View File

@ -66,7 +66,7 @@ func Test_Encode(t *testing.T) {
value := g.Slice{1, 2, 3} value := g.Slice{1, 2, 3}
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
b, err := gjson.Encode(value) b, err := gjson.Encode(value)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(b, []byte(`[1,2,3]`)) t.Assert(b, []byte(`[1,2,3]`))
}) })
} }
@ -75,7 +75,7 @@ func Test_Decode(t *testing.T) {
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
v, err := gjson.Decode(data) v, err := gjson.Decode(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v, g.Map{ t.Assert(v, g.Map{
"n": 123456789, "n": 123456789,
"a": g.Slice{1, 2, 3}, "a": g.Slice{1, 2, 3},
@ -87,7 +87,7 @@ func Test_Decode(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
var v interface{} var v interface{}
err := gjson.DecodeTo(data, &v) err := gjson.DecodeTo(data, &v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(v, g.Map{ t.Assert(v, g.Map{
"n": 123456789, "n": 123456789,
"a": g.Slice{1, 2, 3}, "a": g.Slice{1, 2, 3},
@ -98,7 +98,7 @@ func Test_Decode(t *testing.T) {
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.DecodeToJson(data) j, err := gjson.DecodeToJson(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789") t.Assert(j.Get("n").String(), "123456789")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("m.k"), "v") t.Assert(j.Get("m.k"), "v")
@ -112,7 +112,7 @@ func Test_SplitChar(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.DecodeToJson(data) j, err := gjson.DecodeToJson(data)
j.SetSplitChar(byte('#')) j.SetSplitChar(byte('#'))
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789") t.Assert(j.Get("n").String(), "123456789")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("m#k").String(), "v") t.Assert(j.Get("m#k").String(), "v")
@ -125,7 +125,7 @@ func Test_ViolenceCheck(t *testing.T) {
data := []byte(`{"m":{"a":[1,2,3], "v1.v2":"4"}}`) data := []byte(`{"m":{"a":[1,2,3], "v1.v2":"4"}}`)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.DecodeToJson(data) j, err := gjson.DecodeToJson(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("m.a.2"), 3) t.Assert(j.Get("m.a.2"), 3)
t.Assert(j.Get("m.v1.v2"), nil) t.Assert(j.Get("m.v1.v2"), nil)
j.SetViolenceCheck(true) j.SetViolenceCheck(true)
@ -137,7 +137,7 @@ func Test_GetVar(t *testing.T) {
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.DecodeToJson(data) j, err := gjson.DecodeToJson(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").String(), "123456789") t.Assert(j.Get("n").String(), "123456789")
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("a").Interfaces(), g.Slice{1, 2, 3}) t.Assert(j.Get("a").Interfaces(), g.Slice{1, 2, 3})
@ -150,7 +150,7 @@ func Test_GetMap(t *testing.T) {
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.DecodeToJson(data) j, err := gjson.DecodeToJson(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").Map(), nil) t.Assert(j.Get("n").Map(), nil)
t.Assert(j.Get("m").Map(), g.Map{"k": "v"}) t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
t.Assert(j.Get("a").Map(), g.Map{"1": "2", "3": nil}) t.Assert(j.Get("a").Map(), g.Map{"1": "2", "3": nil})
@ -161,7 +161,7 @@ func Test_GetJson(t *testing.T) {
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.DecodeToJson(data) j, err := gjson.DecodeToJson(data)
t.Assert(err, nil) t.AssertNil(err)
j2 := j.GetJson("m") j2 := j.GetJson("m")
t.AssertNE(j2, nil) t.AssertNE(j2, nil)
t.Assert(j2.Get("k"), "v") t.Assert(j2.Get("k"), "v")
@ -174,7 +174,7 @@ func Test_GetArray(t *testing.T) {
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.DecodeToJson(data) j, err := gjson.DecodeToJson(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("n").Array(), g.Array{123456789}) t.Assert(j.Get("n").Array(), g.Array{123456789})
t.Assert(j.Get("m").Array(), g.Array{g.Map{"k": "v"}}) t.Assert(j.Get("m").Array(), g.Array{g.Map{"k": "v"}})
t.Assert(j.Get("a").Array(), g.Array{1, 2, 3}) t.Assert(j.Get("a").Array(), g.Array{1, 2, 3})
@ -185,7 +185,7 @@ func Test_GetString(t *testing.T) {
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.DecodeToJson(data) j, err := gjson.DecodeToJson(data)
t.Assert(err, nil) t.AssertNil(err)
t.AssertEQ(j.Get("n").String(), "123456789") t.AssertEQ(j.Get("n").String(), "123456789")
t.AssertEQ(j.Get("m").String(), `{"k":"v"}`) t.AssertEQ(j.Get("m").String(), `{"k":"v"}`)
t.AssertEQ(j.Get("a").String(), `[1,2,3]`) t.AssertEQ(j.Get("a").String(), `[1,2,3]`)
@ -197,7 +197,7 @@ func Test_GetStrings(t *testing.T) {
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.DecodeToJson(data) j, err := gjson.DecodeToJson(data)
t.Assert(err, nil) t.AssertNil(err)
t.AssertEQ(j.Get("n").Strings(), g.SliceStr{"123456789"}) t.AssertEQ(j.Get("n").Strings(), g.SliceStr{"123456789"})
t.AssertEQ(j.Get("m").Strings(), g.SliceStr{`{"k":"v"}`}) t.AssertEQ(j.Get("m").Strings(), g.SliceStr{`{"k":"v"}`})
t.AssertEQ(j.Get("a").Strings(), g.SliceStr{"1", "2", "3"}) t.AssertEQ(j.Get("a").Strings(), g.SliceStr{"1", "2", "3"})
@ -209,7 +209,7 @@ func Test_GetInterfaces(t *testing.T) {
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`) data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j, err := gjson.DecodeToJson(data) j, err := gjson.DecodeToJson(data)
t.Assert(err, nil) t.AssertNil(err)
t.AssertEQ(j.Get("n").Interfaces(), g.Array{123456789}) t.AssertEQ(j.Get("n").Interfaces(), g.Array{123456789})
t.AssertEQ(j.Get("m").Interfaces(), g.Array{g.Map{"k": "v"}}) t.AssertEQ(j.Get("m").Interfaces(), g.Array{g.Map{"k": "v"}})
t.AssertEQ(j.Get("a").Interfaces(), g.Array{1, 2, 3}) t.AssertEQ(j.Get("a").Interfaces(), g.Array{1, 2, 3})
@ -332,37 +332,37 @@ func Test_Convert(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
j := gjson.New(`{"name":"gf"}`) j := gjson.New(`{"name":"gf"}`)
arr, err := j.ToXml() arr, err := j.ToXml()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(arr), "<name>gf</name>") t.Assert(string(arr), "<name>gf</name>")
arr, err = j.ToXmlIndent() arr, err = j.ToXmlIndent()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(arr), "<name>gf</name>") t.Assert(string(arr), "<name>gf</name>")
str, err := j.ToXmlString() str, err := j.ToXmlString()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(str, "<name>gf</name>") t.Assert(str, "<name>gf</name>")
str, err = j.ToXmlIndentString() str, err = j.ToXmlIndentString()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(str, "<name>gf</name>") t.Assert(str, "<name>gf</name>")
arr, err = j.ToJsonIndent() arr, err = j.ToJsonIndent()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(arr), "{\n\t\"name\": \"gf\"\n}") t.Assert(string(arr), "{\n\t\"name\": \"gf\"\n}")
str, err = j.ToJsonIndentString() str, err = j.ToJsonIndentString()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(arr), "{\n\t\"name\": \"gf\"\n}") t.Assert(string(arr), "{\n\t\"name\": \"gf\"\n}")
arr, err = j.ToYaml() arr, err = j.ToYaml()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(arr), "name: gf\n") t.Assert(string(arr), "name: gf\n")
str, err = j.ToYamlString() str, err = j.ToYamlString()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(arr), "name: gf\n") t.Assert(string(arr), "name: gf\n")
arr, err = j.ToToml() arr, err = j.ToToml()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(arr), "name = \"gf\"\n") t.Assert(string(arr), "name = \"gf\"\n")
str, err = j.ToTomlString() str, err = j.ToTomlString()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(arr), "name = \"gf\"\n") t.Assert(string(arr), "name = \"gf\"\n")
}) })
} }
@ -387,19 +387,19 @@ func Test_Convert2(t *testing.T) {
t.Assert(j.Get("time").Duration().String(), "0s") t.Assert(j.Get("time").Duration().String(), "0s")
err := j.Var().Scan(&name) err := j.Var().Scan(&name)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(name.Name, "gf") t.Assert(name.Name, "gf")
// j.Dump() // j.Dump()
t.Assert(err, nil) t.AssertNil(err)
j = gjson.New(`{"person":{"name":"gf"}}`) j = gjson.New(`{"person":{"name":"gf"}}`)
err = j.Get("person").Scan(&name) err = j.Get("person").Scan(&name)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(name.Name, "gf") t.Assert(name.Name, "gf")
j = gjson.New(`{"name":"gf""}`) j = gjson.New(`{"name":"gf""}`)
// j.Dump() // j.Dump()
t.Assert(err, nil) t.AssertNil(err)
j = gjson.New(`[1,2,3]`) j = gjson.New(`[1,2,3]`)
t.Assert(len(j.Var().Array()), 3) t.Assert(len(j.Var().Array()), 3)
@ -417,12 +417,12 @@ func Test_Basic(t *testing.T) {
t.Assert(j.Get(".").Interface().(g.Map)["name"], "gf") t.Assert(j.Get(".").Interface().(g.Map)["name"], "gf")
err := j.Set("name", "gf1") err := j.Set("name", "gf1")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("name"), "gf1") t.Assert(j.Get("name"), "gf1")
j = gjson.New(`[1,2,3]`) j = gjson.New(`[1,2,3]`)
err = j.Set("\"0\".1", 11) err = j.Set("\"0\".1", 11)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("1"), 11) t.Assert(j.Get("1"), 11)
j = gjson.New(`[1,2,3]`) j = gjson.New(`[1,2,3]`)
@ -431,7 +431,7 @@ func Test_Basic(t *testing.T) {
j = gjson.New(`[1,2,3]`) j = gjson.New(`[1,2,3]`)
err = j.Remove("1") err = j.Remove("1")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("0"), 1) t.Assert(j.Get("0"), 1)
t.Assert(len(j.Var().Array()), 2) t.Assert(len(j.Var().Array()), 2)
@ -445,18 +445,18 @@ func Test_Basic(t *testing.T) {
j = gjson.New(`[1,2,3]`) j = gjson.New(`[1,2,3]`)
err = j.Remove("3") err = j.Remove("3")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("0"), 1) t.Assert(j.Get("0"), 1)
t.Assert(len(j.Var().Array()), 3) t.Assert(len(j.Var().Array()), 3)
j = gjson.New(`[1,2,3]`) j = gjson.New(`[1,2,3]`)
err = j.Remove("0.3") err = j.Remove("0.3")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("0"), 1) t.Assert(j.Get("0"), 1)
j = gjson.New(`[1,2,3]`) j = gjson.New(`[1,2,3]`)
err = j.Remove("0.a") err = j.Remove("0.a")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("0"), 1) t.Assert(j.Get("0"), 1)
name := struct { name := struct {
@ -465,35 +465,35 @@ func Test_Basic(t *testing.T) {
j = gjson.New(name) j = gjson.New(name)
t.Assert(j.Get("Name"), "gf") t.Assert(j.Get("Name"), "gf")
err = j.Remove("Name") err = j.Remove("Name")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("Name"), nil) t.Assert(j.Get("Name"), nil)
err = j.Set("Name", "gf1") err = j.Set("Name", "gf1")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("Name"), "gf1") t.Assert(j.Get("Name"), "gf1")
j = gjson.New(nil) j = gjson.New(nil)
err = j.Remove("Name") err = j.Remove("Name")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("Name"), nil) t.Assert(j.Get("Name"), nil)
j = gjson.New(name) j = gjson.New(name)
t.Assert(j.Get("Name"), "gf") t.Assert(j.Get("Name"), "gf")
err = j.Set("Name1", g.Map{"Name": "gf1"}) err = j.Set("Name1", g.Map{"Name": "gf1"})
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("Name1").Interface().(g.Map)["Name"], "gf1") t.Assert(j.Get("Name1").Interface().(g.Map)["Name"], "gf1")
err = j.Set("Name2", g.Slice{1, 2, 3}) err = j.Set("Name2", g.Slice{1, 2, 3})
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("Name2").Interface().(g.Slice)[0], 1) t.Assert(j.Get("Name2").Interface().(g.Slice)[0], 1)
err = j.Set("Name3", name) err = j.Set("Name3", name)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("Name3").Interface().(g.Map)["Name"], "gf") t.Assert(j.Get("Name3").Interface().(g.Map)["Name"], "gf")
err = j.Set("Name4", &name) err = j.Set("Name4", &name)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("Name4").Interface().(g.Map)["Name"], "gf") t.Assert(j.Get("Name4").Interface().(g.Map)["Name"], "gf")
arr := [3]int{1, 2, 3} arr := [3]int{1, 2, 3}
err = j.Set("Name5", arr) err = j.Set("Name5", arr)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(j.Get("Name5").Interface().(g.Array)[0], 1) t.Assert(j.Get("Name5").Interface().(g.Array)[0], 1)
}) })

View File

@ -112,7 +112,7 @@ func Test_Decode2(t *testing.T) {
<?xml version="1.0" encoding="UTF-8"?><doc><username>johngcn</username><password1>123456</password1><password2>123456</password2></doc> <?xml version="1.0" encoding="UTF-8"?><doc><username>johngcn</username><password1>123456</password1><password2>123456</password2></doc>
` `
m, err := gxml.Decode([]byte(content)) m, err := gxml.Decode([]byte(content))
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m["doc"].(map[string]interface{})["username"], "johngcn") t.Assert(m["doc"].(map[string]interface{})["username"], "johngcn")
t.Assert(m["doc"].(map[string]interface{})["password1"], "123456") t.Assert(m["doc"].(map[string]interface{})["password1"], "123456")
t.Assert(m["doc"].(map[string]interface{})["password2"], "123456") t.Assert(m["doc"].(map[string]interface{})["password2"], "123456")
@ -125,7 +125,7 @@ func Test_DecodeWitoutRoot(t *testing.T) {
<?xml version="1.0" encoding="UTF-8"?><doc><username>johngcn</username><password1>123456</password1><password2>123456</password2></doc> <?xml version="1.0" encoding="UTF-8"?><doc><username>johngcn</username><password1>123456</password1><password2>123456</password2></doc>
` `
m, err := gxml.DecodeWithoutRoot([]byte(content)) m, err := gxml.DecodeWithoutRoot([]byte(content))
t.Assert(err, nil) t.AssertNil(err)
t.Assert(m["username"], "johngcn") t.Assert(m["username"], "johngcn")
t.Assert(m["password1"], "123456") t.Assert(m["password1"], "123456")
t.Assert(m["password2"], "123456") t.Assert(m["password2"], "123456")

View File

@ -74,7 +74,7 @@ func Test_EncodeIndent(t *testing.T) {
func Test_Decode(t *testing.T) { func Test_Decode(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
result, err := gyaml.Decode([]byte(yamlStr)) result, err := gyaml.Decode([]byte(yamlStr))
t.Assert(err, nil) t.AssertNil(err)
m, ok := result.(map[string]interface{}) m, ok := result.(map[string]interface{})
t.Assert(ok, true) t.Assert(ok, true)
@ -92,7 +92,7 @@ func Test_DecodeTo(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
result := make(map[string]interface{}) result := make(map[string]interface{})
err := gyaml.DecodeTo([]byte(yamlStr), &result) err := gyaml.DecodeTo([]byte(yamlStr), &result)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, map[string]interface{}{ t.Assert(result, map[string]interface{}{
"url": "https://goframe.org", "url": "https://goframe.org",
"server": g.Slice{"120.168.117.21", "120.168.117.22"}, "server": g.Slice{"120.168.117.21", "120.168.117.22"},
@ -121,9 +121,9 @@ m:
k: v k: v
`) `)
v, err := gyaml.Decode(data) v, err := gyaml.Decode(data)
t.Assert(err, nil) t.AssertNil(err)
b, err := json.Marshal(v) b, err := json.Marshal(v)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(b, `{"m":{"k":"v"}}`) t.Assert(b, `{"m":{"k":"v"}}`)
}) })
} }

View File

@ -251,7 +251,7 @@ func Test_Next(t *testing.T) {
t.Assert(err.Error(), "1") t.Assert(err.Error(), "1")
err = gerror.Next(err) err = gerror.Next(err)
t.Assert(err, nil) t.AssertNil(err)
}) })
} }

View File

@ -42,15 +42,15 @@ func Test_Config2(t *testing.T) {
var err error var err error
dirPath := gfile.Temp(gtime.TimestampNanoStr()) dirPath := gfile.Temp(gtime.TimestampNanoStr())
err = gfile.Mkdir(dirPath) err = gfile.Mkdir(dirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(dirPath) defer gfile.Remove(dirPath)
name := "config.toml" name := "config.toml"
err = gfile.PutContents(gfile.Join(dirPath, name), configContent) err = gfile.PutContents(gfile.Join(dirPath, name), configContent)
t.Assert(err, nil) t.AssertNil(err)
err = gins.Config().GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath) err = gins.Config().GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear() defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear()
@ -91,15 +91,15 @@ func Test_Config3(t *testing.T) {
var err error var err error
dirPath := gfile.Temp(gtime.TimestampNanoStr()) dirPath := gfile.Temp(gtime.TimestampNanoStr())
err = gfile.Mkdir(dirPath) err = gfile.Mkdir(dirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(dirPath) defer gfile.Remove(dirPath)
name := "test.toml" name := "test.toml"
err = gfile.PutContents(gfile.Join(dirPath, name), configContent) err = gfile.PutContents(gfile.Join(dirPath, name), configContent)
t.Assert(err, nil) t.AssertNil(err)
err = gins.Config("test").GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath) err = gins.Config("test").GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gins.Config("test").GetAdapter().(*gcfg.AdapterFile).Clear() defer gins.Config("test").GetAdapter().(*gcfg.AdapterFile).Clear()
gins.Config("test").GetAdapter().(*gcfg.AdapterFile).SetFileName("test.toml") gins.Config("test").GetAdapter().(*gcfg.AdapterFile).SetFileName("test.toml")
@ -115,15 +115,15 @@ func Test_Config3(t *testing.T) {
var err error var err error
dirPath := gfile.Temp(gtime.TimestampNanoStr()) dirPath := gfile.Temp(gtime.TimestampNanoStr())
err = gfile.Mkdir(dirPath) err = gfile.Mkdir(dirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(dirPath) defer gfile.Remove(dirPath)
name := "config/test.toml" name := "config/test.toml"
err = gfile.PutContents(gfile.Join(dirPath, name), configContent) err = gfile.PutContents(gfile.Join(dirPath, name), configContent)
t.Assert(err, nil) t.AssertNil(err)
err = gins.Config("test").GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath) err = gins.Config("test").GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gins.Config("test").GetAdapter().(*gcfg.AdapterFile).Clear() defer gins.Config("test").GetAdapter().(*gcfg.AdapterFile).Clear()
gins.Config("test").GetAdapter().(*gcfg.AdapterFile).SetFileName("test.toml") gins.Config("test").GetAdapter().(*gcfg.AdapterFile).SetFileName("test.toml")
@ -142,7 +142,7 @@ func Test_Config4(t *testing.T) {
path := fmt.Sprintf(`%s/%d`, gfile.Temp(), gtime.TimestampNano()) path := fmt.Sprintf(`%s/%d`, gfile.Temp(), gtime.TimestampNano())
file := fmt.Sprintf(`%s/%s`, path, "config.toml") file := fmt.Sprintf(`%s/%s`, path, "config.toml")
err := gfile.PutContents(file, configContent) err := gfile.PutContents(file, configContent)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(file) defer gfile.Remove(file)
defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear() defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear()
@ -157,7 +157,7 @@ func Test_Config4(t *testing.T) {
path := fmt.Sprintf(`%s/%d/config`, gfile.Temp(), gtime.TimestampNano()) path := fmt.Sprintf(`%s/%d/config`, gfile.Temp(), gtime.TimestampNano())
file := fmt.Sprintf(`%s/%s`, path, "config.toml") file := fmt.Sprintf(`%s/%s`, path, "config.toml")
err := gfile.PutContents(file, configContent) err := gfile.PutContents(file, configContent)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(file) defer gfile.Remove(file)
defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear() defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear()
t.Assert(gins.Config().GetAdapter().(*gcfg.AdapterFile).AddPath(path), nil) t.Assert(gins.Config().GetAdapter().(*gcfg.AdapterFile).AddPath(path), nil)
@ -171,7 +171,7 @@ func Test_Config4(t *testing.T) {
path := fmt.Sprintf(`%s/%d`, gfile.Temp(), gtime.TimestampNano()) path := fmt.Sprintf(`%s/%d`, gfile.Temp(), gtime.TimestampNano())
file := fmt.Sprintf(`%s/%s`, path, "test.toml") file := fmt.Sprintf(`%s/%s`, path, "test.toml")
err := gfile.PutContents(file, configContent) err := gfile.PutContents(file, configContent)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(file) defer gfile.Remove(file)
defer gins.Config("test").GetAdapter().(*gcfg.AdapterFile).Clear() defer gins.Config("test").GetAdapter().(*gcfg.AdapterFile).Clear()
gins.Config("test").GetAdapter().(*gcfg.AdapterFile).SetFileName("test.toml") gins.Config("test").GetAdapter().(*gcfg.AdapterFile).SetFileName("test.toml")
@ -186,7 +186,7 @@ func Test_Config4(t *testing.T) {
path := fmt.Sprintf(`%s/%d/config`, gfile.Temp(), gtime.TimestampNano()) path := fmt.Sprintf(`%s/%d/config`, gfile.Temp(), gtime.TimestampNano())
file := fmt.Sprintf(`%s/%s`, path, "test.toml") file := fmt.Sprintf(`%s/%s`, path, "test.toml")
err := gfile.PutContents(file, configContent) err := gfile.PutContents(file, configContent)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(file) defer gfile.Remove(file)
defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear() defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear()
gins.Config("test").GetAdapter().(*gcfg.AdapterFile).SetFileName("test.toml") gins.Config("test").GetAdapter().(*gcfg.AdapterFile).SetFileName("test.toml")

View File

@ -26,15 +26,15 @@ func Test_Database(t *testing.T) {
var err error var err error
dirPath := gfile.Temp(gtime.TimestampNanoStr()) dirPath := gfile.Temp(gtime.TimestampNanoStr())
err = gfile.Mkdir(dirPath) err = gfile.Mkdir(dirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(dirPath) defer gfile.Remove(dirPath)
name := "config.toml" name := "config.toml"
err = gfile.PutContents(gfile.Join(dirPath, name), databaseContent) err = gfile.PutContents(gfile.Join(dirPath, name), databaseContent)
t.Assert(err, nil) t.AssertNil(err)
err = gins.Config().GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath) err = gins.Config().GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear() defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear()

View File

@ -27,15 +27,15 @@ func Test_Redis(t *testing.T) {
var err error var err error
dirPath := gfile.Temp(gtime.TimestampNanoStr()) dirPath := gfile.Temp(gtime.TimestampNanoStr())
err = gfile.Mkdir(dirPath) err = gfile.Mkdir(dirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(dirPath) defer gfile.Remove(dirPath)
name := "config.toml" name := "config.toml"
err = gfile.PutContents(gfile.Join(dirPath, name), redisContent) err = gfile.PutContents(gfile.Join(dirPath, name), redisContent)
t.Assert(err, nil) t.AssertNil(err)
err = gins.Config().GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath) err = gins.Config().GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath)
t.Assert(err, nil) t.AssertNil(err)
defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear() defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear()
@ -58,13 +58,13 @@ func Test_Redis(t *testing.T) {
t.Assert(r, "PONG") t.Assert(r, "PONG")
r, err = redisCache.Do(ctx, "PING") r, err = redisCache.Do(ctx, "PING")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r, "PONG") t.Assert(r, "PONG")
_, err = redisDisk.Do(ctx, "SET", "k", "v") _, err = redisDisk.Do(ctx, "SET", "k", "v")
t.Assert(err, nil) t.AssertNil(err)
r, err = redisDisk.Do(ctx, "GET", "k") r, err = redisDisk.Do(ctx, "GET", "k")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r, []byte("v")) t.Assert(r, []byte("v"))
}) })
} }

View File

@ -28,7 +28,7 @@ func Test_View(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
tpl := "t.tpl" tpl := "t.tpl"
err := gfile.PutContents(tpl, `{{"我是中国人" | substr 2 -1}}`) err := gfile.PutContents(tpl, `{{"我是中国人" | substr 2 -1}}`)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(tpl) defer gfile.Remove(tpl)
b, e := View().Parse(context.TODO(), "t.tpl", nil) b, e := View().Parse(context.TODO(), "t.tpl", nil)
@ -39,10 +39,10 @@ func Test_View(t *testing.T) {
path := fmt.Sprintf(`%s/%d`, gfile.Temp(), gtime.TimestampNano()) path := fmt.Sprintf(`%s/%d`, gfile.Temp(), gtime.TimestampNano())
tpl := fmt.Sprintf(`%s/%s`, path, "t.tpl") tpl := fmt.Sprintf(`%s/%s`, path, "t.tpl")
err := gfile.PutContents(tpl, `{{"我是中国人" | substr 2 -1}}`) err := gfile.PutContents(tpl, `{{"我是中国人" | substr 2 -1}}`)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(tpl) defer gfile.Remove(tpl)
err = View().AddPath(path) err = View().AddPath(path)
t.Assert(err, nil) t.AssertNil(err)
b, e := View().Parse(context.TODO(), "t.tpl", nil) b, e := View().Parse(context.TODO(), "t.tpl", nil)
t.Assert(e, nil) t.Assert(e, nil)
@ -61,16 +61,16 @@ func Test_View_Config(t *testing.T) {
view := View("test1") view := View("test1")
t.AssertNE(view, nil) t.AssertNE(view, nil)
err := view.AddPath(dirPath) err := view.AddPath(dirPath)
t.Assert(err, nil) t.AssertNil(err)
str := `hello ${.name},version:${.version}` str := `hello ${.name},version:${.version}`
view.Assigns(map[string]interface{}{"version": "1.9.0"}) view.Assigns(map[string]interface{}{"version": "1.9.0"})
result, err := view.ParseContent(context.TODO(), str, nil) result, err := view.ParseContent(context.TODO(), str, nil)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, "hello test1,version:1.9.0") t.Assert(result, "hello test1,version:1.9.0")
result, err = view.ParseDefault(context.TODO()) result, err = view.ParseDefault(context.TODO())
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, "test1:test1") t.Assert(result, "test1:test1")
}) })
// view1 test2 // view1 test2
@ -83,16 +83,16 @@ func Test_View_Config(t *testing.T) {
view := View("test2") view := View("test2")
t.AssertNE(view, nil) t.AssertNE(view, nil)
err := view.AddPath(dirPath) err := view.AddPath(dirPath)
t.Assert(err, nil) t.AssertNil(err)
str := `hello #{.name},version:#{.version}` str := `hello #{.name},version:#{.version}`
view.Assigns(map[string]interface{}{"version": "1.9.0"}) view.Assigns(map[string]interface{}{"version": "1.9.0"})
result, err := view.ParseContent(context.TODO(), str, nil) result, err := view.ParseContent(context.TODO(), str, nil)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, "hello test2,version:1.9.0") t.Assert(result, "hello test2,version:1.9.0")
result, err = view.ParseDefault(context.TODO()) result, err = view.ParseDefault(context.TODO())
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, "test2:test2") t.Assert(result, "test2:test2")
}) })
// view2 // view2
@ -105,16 +105,16 @@ func Test_View_Config(t *testing.T) {
view := View() view := View()
t.AssertNE(view, nil) t.AssertNE(view, nil)
err := view.AddPath(dirPath) err := view.AddPath(dirPath)
t.Assert(err, nil) t.AssertNil(err)
str := `hello {.name},version:{.version}` str := `hello {.name},version:{.version}`
view.Assigns(map[string]interface{}{"version": "1.9.0"}) view.Assigns(map[string]interface{}{"version": "1.9.0"})
result, err := view.ParseContent(context.TODO(), str, nil) result, err := view.ParseContent(context.TODO(), str, nil)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, "hello test,version:1.9.0") t.Assert(result, "hello test,version:1.9.0")
result, err = view.ParseDefault(context.TODO()) result, err = view.ParseDefault(context.TODO())
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, "test:test") t.Assert(result, "test:test")
}) })
// view2 // view2
@ -127,16 +127,16 @@ func Test_View_Config(t *testing.T) {
view := View("test100") view := View("test100")
t.AssertNE(view, nil) t.AssertNE(view, nil)
err := view.AddPath(dirPath) err := view.AddPath(dirPath)
t.Assert(err, nil) t.AssertNil(err)
str := `hello {.name},version:{.version}` str := `hello {.name},version:{.version}`
view.Assigns(map[string]interface{}{"version": "1.9.0"}) view.Assigns(map[string]interface{}{"version": "1.9.0"})
result, err := view.ParseContent(context.TODO(), str, nil) result, err := view.ParseContent(context.TODO(), str, nil)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, "hello test,version:1.9.0") t.Assert(result, "hello test,version:1.9.0")
result, err = view.ParseDefault(context.TODO()) result, err = view.ParseDefault(context.TODO())
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, "test:test") t.Assert(result, "test:test")
}) })
} }

View File

@ -85,7 +85,7 @@ func Test_TranslateFormat(t *testing.T) {
func Test_DefaultManager(t *testing.T) { func Test_DefaultManager(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
err := gi18n.SetPath(gdebug.TestDataPath("i18n")) err := gi18n.SetPath(gdebug.TestDataPath("i18n"))
t.Assert(err, nil) t.AssertNil(err)
gi18n.SetLanguage("none") gi18n.SetLanguage("none")
t.Assert(gi18n.T(context.Background(), "{#hello}{#world}"), "{#hello}{#world}") t.Assert(gi18n.T(context.Background(), "{#hello}{#world}"), "{#hello}{#world}")
@ -99,7 +99,7 @@ func Test_DefaultManager(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
err := gi18n.SetPath(gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n-dir") err := gi18n.SetPath(gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n-dir")
t.Assert(err, nil) t.AssertNil(err)
gi18n.SetLanguage("none") gi18n.SetLanguage("none")
t.Assert(gi18n.Translate(context.Background(), "{#hello}{#world}"), "{#hello}{#world}") t.Assert(gi18n.Translate(context.Background(), "{#hello}{#world}"), "{#hello}{#world}")
@ -117,7 +117,7 @@ func Test_Instance(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
m := gi18n.Instance() m := gi18n.Instance()
err := m.SetPath("i18n-dir") err := m.SetPath("i18n-dir")
t.Assert(err, nil) t.AssertNil(err)
m.SetLanguage("zh-CN") m.SetLanguage("zh-CN")
t.Assert(m.T(context.Background(), "{#hello}{#world}"), "你好世界") t.Assert(m.T(context.Background(), "{#hello}{#world}"), "你好世界")
}) })
@ -141,7 +141,7 @@ func Test_Resource(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
m := g.I18n("resource") m := g.I18n("resource")
err := m.SetPath("i18n-dir") err := m.SetPath("i18n-dir")
t.Assert(err, nil) t.AssertNil(err)
m.SetLanguage("none") m.SetLanguage("none")
t.Assert(m.T(context.Background(), "{#hello}{#world}"), "{#hello}{#world}") t.Assert(m.T(context.Background(), "{#hello}{#world}"), "{#hello}{#world}")

View File

@ -144,7 +144,7 @@ func Test_Client_Cookies(t *testing.T) {
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p)) c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
resp, err := c.Get(ctx, "/cookie") resp, err := c.Get(ctx, "/cookie")
t.Assert(err, nil) t.AssertNil(err)
defer resp.Close() defer resp.Close()
t.AssertNE(resp.Header.Get("Set-Cookie"), "") t.AssertNE(resp.Header.Get("Set-Cookie"), "")
@ -318,12 +318,12 @@ func Test_Client_File_And_Param(t *testing.T) {
s.BindHandler("/", func(r *ghttp.Request) { s.BindHandler("/", func(r *ghttp.Request) {
tmpPath := gfile.Temp(guid.S()) tmpPath := gfile.Temp(guid.S())
err := gfile.Mkdir(tmpPath) err := gfile.Mkdir(tmpPath)
gtest.Assert(err, nil) gtest.AssertNil(err)
defer gfile.Remove(tmpPath) defer gfile.Remove(tmpPath)
file := r.GetUploadFile("file") file := r.GetUploadFile("file")
_, err = file.Save(tmpPath) _, err = file.Save(tmpPath)
gtest.Assert(err, nil) gtest.AssertNil(err)
r.Response.Write( r.Response.Write(
r.Get("json"), r.Get("json"),
gfile.GetContents(gfile.Join(tmpPath, gfile.Basename(file.Filename))), gfile.GetContents(gfile.Join(tmpPath, gfile.Basename(file.Filename))),
@ -398,7 +398,7 @@ func Test_Client_Middleware(t *testing.T) {
}) })
resp, err := c.Get(ctx, "/") resp, err := c.Get(ctx, "/")
t.Assert(str1, "acefdb") t.Assert(str1, "acefdb")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp.ReadAllString(), str2) t.Assert(resp.ReadAllString(), str2)
t.Assert(isServerHandler, true) t.Assert(isServerHandler, true)
@ -473,7 +473,7 @@ func Test_Client_Request_13_Dump(t *testing.T) {
url := fmt.Sprintf("http://127.0.0.1:%d", p) url := fmt.Sprintf("http://127.0.0.1:%d", p)
client := g.Client().SetPrefix(url).ContentJson() client := g.Client().SetPrefix(url).ContentJson()
r, err := client.Post(ctx, "/hello", g.Map{"field": "test_for_request_body"}) r, err := client.Post(ctx, "/hello", g.Map{"field": "test_for_request_body"})
t.Assert(err, nil) t.AssertNil(err)
dumpedText := r.RawRequest() dumpedText := r.RawRequest()
t.Assert(gstr.Contains(dumpedText, "test_for_request_body"), true) t.Assert(gstr.Contains(dumpedText, "test_for_request_body"), true)
dumpedText2 := r.RawResponse() dumpedText2 := r.RawResponse()
@ -482,7 +482,7 @@ func Test_Client_Request_13_Dump(t *testing.T) {
client2 := g.Client().SetPrefix(url).ContentType("text/html") client2 := g.Client().SetPrefix(url).ContentType("text/html")
r2, err := client2.Post(ctx, "/hello2", g.Map{"field": "test_for_request_body"}) r2, err := client2.Post(ctx, "/hello2", g.Map{"field": "test_for_request_body"})
t.Assert(err, nil) t.AssertNil(err)
dumpedText3 := r2.RawRequest() dumpedText3 := r2.RawRequest()
t.Assert(gstr.Contains(dumpedText3, "test_for_request_body"), true) t.Assert(gstr.Contains(dumpedText3, "test_for_request_body"), true)
dumpedText4 := r2.RawResponse() dumpedText4 := r2.RawResponse()
@ -520,15 +520,15 @@ func Test_WebSocketClient(t *testing.T) {
client.HandshakeTimeout = time.Minute client.HandshakeTimeout = time.Minute
conn, _, err := client.Dial(fmt.Sprintf("ws://127.0.0.1:%d/ws", p), nil) conn, _, err := client.Dial(fmt.Sprintf("ws://127.0.0.1:%d/ws", p), nil)
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
msg := []byte("hello") msg := []byte("hello")
err = conn.WriteMessage(websocket.TextMessage, msg) err = conn.WriteMessage(websocket.TextMessage, msg)
t.Assert(err, nil) t.AssertNil(err)
mt, data, err := conn.ReadMessage() mt, data, err := conn.ReadMessage()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(mt, websocket.TextMessage) t.Assert(mt, websocket.TextMessage)
t.Assert(data, msg) t.Assert(data, msg)
}) })

View File

@ -34,7 +34,7 @@ func Test_ConfigFromMap(t *testing.T) {
"cookieHttpOnly": true, "cookieHttpOnly": true,
} }
config, err := ghttp.ConfigFromMap(m) config, err := ghttp.ConfigFromMap(m)
t.Assert(err, nil) t.AssertNil(err)
d1, _ := time.ParseDuration(gconv.String(m["readTimeout"])) d1, _ := time.ParseDuration(gconv.String(m["readTimeout"]))
d2, _ := time.ParseDuration(gconv.String(m["cookieMaxAge"])) d2, _ := time.ParseDuration(gconv.String(m["cookieMaxAge"]))
t.Assert(config.Address, m["address"]) t.Assert(config.Address, m["address"])
@ -67,7 +67,7 @@ func Test_SetConfigWithMap(t *testing.T) {
} }
s := g.Server() s := g.Server()
err := s.SetConfigWithMap(m) err := s.SetConfigWithMap(m)
t.Assert(err, nil) t.AssertNil(err)
}) })
} }

View File

@ -207,7 +207,7 @@ func Test_Middleware_Status(t *testing.T) {
resp, err := client.Get(ctx, "/") resp, err := client.Get(ctx, "/")
defer resp.Close() defer resp.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp.StatusCode, 404) t.Assert(resp.StatusCode, 404)
}) })
} }
@ -583,7 +583,7 @@ func Test_Middleware_CORSAndAuth(t *testing.T) {
t.Assert(client.PostContent(ctx, "/api.v2/user/list", "token=123456"), "list") t.Assert(client.PostContent(ctx, "/api.v2/user/list", "token=123456"), "list")
// CORS Checks. // CORS Checks.
resp, err := client.Post(ctx, "/api.v2/user/list", "token=123456") resp, err := client.Post(ctx, "/api.v2/user/list", "token=123456")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1)
t.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With") t.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With")
t.Assert(resp.Header["Access-Control-Allow-Methods"][0], "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE") t.Assert(resp.Header["Access-Control-Allow-Methods"][0], "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE")

View File

@ -38,14 +38,14 @@ func Test_Middleware_CORS1(t *testing.T) {
// GET request does not any route. // GET request does not any route.
resp, err := client.Get(ctx, "/api.v2/user/list") resp, err := client.Get(ctx, "/api.v2/user/list")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0) t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0)
t.Assert(resp.StatusCode, 404) t.Assert(resp.StatusCode, 404)
resp.Close() resp.Close()
// POST request matches the route and CORS middleware. // POST request matches the route and CORS middleware.
resp, err = client.Post(ctx, "/api.v2/user/list") resp, err = client.Post(ctx, "/api.v2/user/list")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1)
t.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With") t.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With")
t.Assert(resp.Header["Access-Control-Allow-Methods"][0], "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE") t.Assert(resp.Header["Access-Control-Allow-Methods"][0], "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE")
@ -59,7 +59,7 @@ func Test_Middleware_CORS1(t *testing.T) {
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())) client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
client.SetHeader("Access-Control-Request-Method", "GET") client.SetHeader("Access-Control-Request-Method", "GET")
resp, err := client.Options(ctx, "/api.v2/user/list") resp, err := client.Options(ctx, "/api.v2/user/list")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0) t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0)
t.Assert(resp.ReadAllString(), "Not Found") t.Assert(resp.ReadAllString(), "Not Found")
t.Assert(resp.StatusCode, 404) t.Assert(resp.StatusCode, 404)
@ -71,7 +71,7 @@ func Test_Middleware_CORS1(t *testing.T) {
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())) client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
client.SetHeader("Access-Control-Request-Method", "POST") client.SetHeader("Access-Control-Request-Method", "POST")
resp, err := client.Options(ctx, "/api.v2/user/list") resp, err := client.Options(ctx, "/api.v2/user/list")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1)
t.Assert(resp.StatusCode, 200) t.Assert(resp.StatusCode, 200)
resp.Close() resp.Close()
@ -98,7 +98,7 @@ func Test_Middleware_CORS2(t *testing.T) {
t.Assert(client.GetContent(ctx, "/api.v2"), "Not Found") t.Assert(client.GetContent(ctx, "/api.v2"), "Not Found")
// Get request. // Get request.
resp, err := client.Get(ctx, "/api.v2/user/list/1") resp, err := client.Get(ctx, "/api.v2/user/list/1")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1)
t.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With") t.Assert(resp.Header["Access-Control-Allow-Headers"][0], "Origin,Content-Type,Accept,User-Agent,Cookie,Authorization,X-Auth-Token,X-Requested-With")
t.Assert(resp.Header["Access-Control-Allow-Methods"][0], "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE") t.Assert(resp.Header["Access-Control-Allow-Methods"][0], "GET,PUT,POST,DELETE,PATCH,HEAD,CONNECT,OPTIONS,TRACE")
@ -113,7 +113,7 @@ func Test_Middleware_CORS2(t *testing.T) {
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())) client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
client.SetHeader("Access-Control-Request-Method", "GET") client.SetHeader("Access-Control-Request-Method", "GET")
resp, err := client.Options(ctx, "/api.v2/user") resp, err := client.Options(ctx, "/api.v2/user")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0) t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0)
t.Assert(resp.StatusCode, 404) t.Assert(resp.StatusCode, 404)
resp.Close() resp.Close()
@ -124,7 +124,7 @@ func Test_Middleware_CORS2(t *testing.T) {
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())) client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
client.SetHeader("Access-Control-Request-Method", "GET") client.SetHeader("Access-Control-Request-Method", "GET")
resp, err := client.Options(ctx, "/api.v2/user/list/1") resp, err := client.Options(ctx, "/api.v2/user/list/1")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1) t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 1)
t.Assert(resp.StatusCode, 200) t.Assert(resp.StatusCode, 200)
resp.Close() resp.Close()
@ -135,7 +135,7 @@ func Test_Middleware_CORS2(t *testing.T) {
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())) client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
client.SetHeader("Access-Control-Request-Method", "POST") client.SetHeader("Access-Control-Request-Method", "POST")
resp, err := client.Options(ctx, "/api.v2/user/list/1") resp, err := client.Options(ctx, "/api.v2/user/list/1")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0) t.Assert(len(resp.Header["Access-Control-Allow-Headers"]), 0)
t.Assert(resp.StatusCode, 404) t.Assert(resp.StatusCode, 404)
resp.Close() resp.Close()

View File

@ -115,22 +115,22 @@ func Test_Router_Method(t *testing.T) {
resp1, err := client.Get(ctx, "/get") resp1, err := client.Get(ctx, "/get")
defer resp1.Close() defer resp1.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp1.StatusCode, 200) t.Assert(resp1.StatusCode, 200)
resp2, err := client.Post(ctx, "/get") resp2, err := client.Post(ctx, "/get")
defer resp2.Close() defer resp2.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp2.StatusCode, 404) t.Assert(resp2.StatusCode, 404)
resp3, err := client.Get(ctx, "/post") resp3, err := client.Get(ctx, "/post")
defer resp3.Close() defer resp3.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp3.StatusCode, 404) t.Assert(resp3.StatusCode, 404)
resp4, err := client.Post(ctx, "/post") resp4, err := client.Post(ctx, "/post")
defer resp4.Close() defer resp4.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp4.StatusCode, 200) t.Assert(resp4.StatusCode, 200)
}) })
} }
@ -187,27 +187,27 @@ func Test_Router_Status(t *testing.T) {
resp1, err := client.Get(ctx, "/200") resp1, err := client.Get(ctx, "/200")
defer resp1.Close() defer resp1.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp1.StatusCode, 200) t.Assert(resp1.StatusCode, 200)
resp2, err := client.Get(ctx, "/300") resp2, err := client.Get(ctx, "/300")
defer resp2.Close() defer resp2.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp2.StatusCode, 300) t.Assert(resp2.StatusCode, 300)
resp3, err := client.Get(ctx, "/400") resp3, err := client.Get(ctx, "/400")
defer resp3.Close() defer resp3.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp3.StatusCode, 400) t.Assert(resp3.StatusCode, 400)
resp4, err := client.Get(ctx, "/500") resp4, err := client.Get(ctx, "/500")
defer resp4.Close() defer resp4.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp4.StatusCode, 500) t.Assert(resp4.StatusCode, 500)
resp5, err := client.Get(ctx, "/404") resp5, err := client.Get(ctx, "/404")
defer resp5.Close() defer resp5.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp5.StatusCode, 404) t.Assert(resp5.StatusCode, 404)
}) })
} }
@ -232,7 +232,7 @@ func Test_Router_CustomStatusHandler(t *testing.T) {
t.Assert(client.GetContent(ctx, "/"), "hello") t.Assert(client.GetContent(ctx, "/"), "hello")
resp, err := client.Get(ctx, "/ThisDoesNotExist") resp, err := client.Get(ctx, "/ThisDoesNotExist")
defer resp.Close() defer resp.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp.StatusCode, 404) t.Assert(resp.StatusCode, 404)
t.Assert(resp.ReadAllString(), "404 page") t.Assert(resp.ReadAllString(), "404 page")
}) })
@ -256,7 +256,7 @@ func Test_Router_404(t *testing.T) {
t.Assert(client.GetContent(ctx, "/"), "hello") t.Assert(client.GetContent(ctx, "/"), "hello")
resp, err := client.Get(ctx, "/ThisDoesNotExist") resp, err := client.Get(ctx, "/ThisDoesNotExist")
defer resp.Close() defer resp.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp.StatusCode, 404) t.Assert(resp.StatusCode, 404)
}) })
} }

View File

@ -87,22 +87,22 @@ func Test_Router_DomainMethod(t *testing.T) {
resp1, err := client.Get(ctx, "/get") resp1, err := client.Get(ctx, "/get")
defer resp1.Close() defer resp1.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp1.StatusCode, 404) t.Assert(resp1.StatusCode, 404)
resp2, err := client.Post(ctx, "/get") resp2, err := client.Post(ctx, "/get")
defer resp2.Close() defer resp2.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp2.StatusCode, 404) t.Assert(resp2.StatusCode, 404)
resp3, err := client.Get(ctx, "/post") resp3, err := client.Get(ctx, "/post")
defer resp3.Close() defer resp3.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp3.StatusCode, 404) t.Assert(resp3.StatusCode, 404)
resp4, err := client.Post(ctx, "/post") resp4, err := client.Post(ctx, "/post")
defer resp4.Close() defer resp4.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp4.StatusCode, 404) t.Assert(resp4.StatusCode, 404)
}) })
@ -112,22 +112,22 @@ func Test_Router_DomainMethod(t *testing.T) {
resp1, err := client.Get(ctx, "/get") resp1, err := client.Get(ctx, "/get")
defer resp1.Close() defer resp1.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp1.StatusCode, 200) t.Assert(resp1.StatusCode, 200)
resp2, err := client.Post(ctx, "/get") resp2, err := client.Post(ctx, "/get")
defer resp2.Close() defer resp2.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp2.StatusCode, 404) t.Assert(resp2.StatusCode, 404)
resp3, err := client.Get(ctx, "/post") resp3, err := client.Get(ctx, "/post")
defer resp3.Close() defer resp3.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp3.StatusCode, 404) t.Assert(resp3.StatusCode, 404)
resp4, err := client.Post(ctx, "/post") resp4, err := client.Post(ctx, "/post")
defer resp4.Close() defer resp4.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp4.StatusCode, 200) t.Assert(resp4.StatusCode, 200)
}) })
@ -137,22 +137,22 @@ func Test_Router_DomainMethod(t *testing.T) {
resp1, err := client.Get(ctx, "/get") resp1, err := client.Get(ctx, "/get")
defer resp1.Close() defer resp1.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp1.StatusCode, 200) t.Assert(resp1.StatusCode, 200)
resp2, err := client.Post(ctx, "/get") resp2, err := client.Post(ctx, "/get")
defer resp2.Close() defer resp2.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp2.StatusCode, 404) t.Assert(resp2.StatusCode, 404)
resp3, err := client.Get(ctx, "/post") resp3, err := client.Get(ctx, "/post")
defer resp3.Close() defer resp3.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp3.StatusCode, 404) t.Assert(resp3.StatusCode, 404)
resp4, err := client.Post(ctx, "/post") resp4, err := client.Post(ctx, "/post")
defer resp4.Close() defer resp4.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp4.StatusCode, 200) t.Assert(resp4.StatusCode, 200)
}) })
} }
@ -183,22 +183,22 @@ func Test_Router_DomainStatus(t *testing.T) {
resp1, err := client.Get(ctx, "/200") resp1, err := client.Get(ctx, "/200")
defer resp1.Close() defer resp1.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp1.StatusCode, 404) t.Assert(resp1.StatusCode, 404)
resp2, err := client.Get(ctx, "/300") resp2, err := client.Get(ctx, "/300")
defer resp2.Close() defer resp2.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp2.StatusCode, 404) t.Assert(resp2.StatusCode, 404)
resp3, err := client.Get(ctx, "/400") resp3, err := client.Get(ctx, "/400")
defer resp3.Close() defer resp3.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp3.StatusCode, 404) t.Assert(resp3.StatusCode, 404)
resp4, err := client.Get(ctx, "/500") resp4, err := client.Get(ctx, "/500")
defer resp4.Close() defer resp4.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp4.StatusCode, 404) t.Assert(resp4.StatusCode, 404)
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
@ -207,22 +207,22 @@ func Test_Router_DomainStatus(t *testing.T) {
resp1, err := client.Get(ctx, "/200") resp1, err := client.Get(ctx, "/200")
defer resp1.Close() defer resp1.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp1.StatusCode, 200) t.Assert(resp1.StatusCode, 200)
resp2, err := client.Get(ctx, "/300") resp2, err := client.Get(ctx, "/300")
defer resp2.Close() defer resp2.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp2.StatusCode, 300) t.Assert(resp2.StatusCode, 300)
resp3, err := client.Get(ctx, "/400") resp3, err := client.Get(ctx, "/400")
defer resp3.Close() defer resp3.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp3.StatusCode, 400) t.Assert(resp3.StatusCode, 400)
resp4, err := client.Get(ctx, "/500") resp4, err := client.Get(ctx, "/500")
defer resp4.Close() defer resp4.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp4.StatusCode, 500) t.Assert(resp4.StatusCode, 500)
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
@ -231,22 +231,22 @@ func Test_Router_DomainStatus(t *testing.T) {
resp1, err := client.Get(ctx, "/200") resp1, err := client.Get(ctx, "/200")
defer resp1.Close() defer resp1.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp1.StatusCode, 200) t.Assert(resp1.StatusCode, 200)
resp2, err := client.Get(ctx, "/300") resp2, err := client.Get(ctx, "/300")
defer resp2.Close() defer resp2.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp2.StatusCode, 300) t.Assert(resp2.StatusCode, 300)
resp3, err := client.Get(ctx, "/400") resp3, err := client.Get(ctx, "/400")
defer resp3.Close() defer resp3.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp3.StatusCode, 400) t.Assert(resp3.StatusCode, 400)
resp4, err := client.Get(ctx, "/500") resp4, err := client.Get(ctx, "/500")
defer resp4.Close() defer resp4.Close()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp4.StatusCode, 500) t.Assert(resp4.StatusCode, 500)
}) })
} }

View File

@ -78,7 +78,7 @@ func Test_Router_DomainObjectRest(t *testing.T) {
if err == nil { if err == nil {
defer resp1.Close() defer resp1.Close()
} }
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp1.Header.Get("head-ok"), "") t.Assert(resp1.Header.Get("head-ok"), "")
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found") t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
}) })
@ -96,7 +96,7 @@ func Test_Router_DomainObjectRest(t *testing.T) {
if err == nil { if err == nil {
defer resp1.Close() defer resp1.Close()
} }
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp1.Header.Get("head-ok"), "1") t.Assert(resp1.Header.Get("head-ok"), "1")
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found") t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
}) })
@ -114,7 +114,7 @@ func Test_Router_DomainObjectRest(t *testing.T) {
if err == nil { if err == nil {
defer resp1.Close() defer resp1.Close()
} }
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp1.Header.Get("head-ok"), "1") t.Assert(resp1.Header.Get("head-ok"), "1")
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found") t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
}) })

View File

@ -80,7 +80,7 @@ func Test_Router_GroupRest1(t *testing.T) {
if err == nil { if err == nil {
defer resp2.Close() defer resp2.Close()
} }
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp2.Header.Get("head-ok"), "1") t.Assert(resp2.Header.Get("head-ok"), "1")
t.Assert(client.GetContent(ctx, "/api/group-obj-rest"), "Not Found") t.Assert(client.GetContent(ctx, "/api/group-obj-rest"), "Not Found")
@ -94,7 +94,7 @@ func Test_Router_GroupRest1(t *testing.T) {
if err == nil { if err == nil {
defer resp4.Close() defer resp4.Close()
} }
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp4.Header.Get("head-ok"), "1") t.Assert(resp4.Header.Get("head-ok"), "1")
}) })
} }
@ -125,7 +125,7 @@ func Test_Router_GroupRest2(t *testing.T) {
if err == nil { if err == nil {
defer resp2.Close() defer resp2.Close()
} }
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp2.Header.Get("head-ok"), "1") t.Assert(resp2.Header.Get("head-ok"), "1")
t.Assert(client.GetContent(ctx, "/api/group-obj-rest"), "Not Found") t.Assert(client.GetContent(ctx, "/api/group-obj-rest"), "Not Found")
@ -139,7 +139,7 @@ func Test_Router_GroupRest2(t *testing.T) {
if err == nil { if err == nil {
defer resp4.Close() defer resp4.Close()
} }
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp4.Header.Get("head-ok"), "1") t.Assert(resp4.Header.Get("head-ok"), "1")
}) })
} }

View File

@ -78,7 +78,7 @@ func Test_Router_ObjectRest(t *testing.T) {
if err == nil { if err == nil {
defer resp1.Close() defer resp1.Close()
} }
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp1.Header.Get("head-ok"), "1") t.Assert(resp1.Header.Get("head-ok"), "1")
t.Assert(client.GetContent(ctx, "/object-rest/get"), "1Object Get2") t.Assert(client.GetContent(ctx, "/object-rest/get"), "1Object Get2")
@ -91,7 +91,7 @@ func Test_Router_ObjectRest(t *testing.T) {
if err == nil { if err == nil {
defer resp2.Close() defer resp2.Close()
} }
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resp2.Header.Get("head-ok"), "1") t.Assert(resp2.Header.Get("head-ok"), "1")
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found") t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")

View File

@ -179,7 +179,7 @@ func Test_Session_Custom_Id(t *testing.T) {
client := g.Client() client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort())) client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
r, err := client.Get(ctx, "/id") r, err := client.Get(ctx, "/id")
t.Assert(err, nil) t.AssertNil(err)
defer r.Close() defer r.Close()
t.Assert(r.ReadAllString(), sessionId) t.Assert(r.ReadAllString(), sessionId)
t.Assert(r.GetCookie(s.GetSessionIdName()), sessionId) t.Assert(r.GetCookie(s.GetSessionIdName()), sessionId)

View File

@ -31,7 +31,7 @@ func Test_Template_Basic(t *testing.T) {
err := r.Response.WriteTpl("index.html", g.Map{ err := r.Response.WriteTpl("index.html", g.Map{
"name": "john", "name": "john",
}) })
t.Assert(err, nil) t.AssertNil(err)
}) })
s.SetDumpRouterMap(false) s.SetDumpRouterMap(false)
s.Start() s.Start()
@ -55,7 +55,7 @@ func Test_Template_Encode(t *testing.T) {
err := r.Response.WriteTpl("index.html", g.Map{ err := r.Response.WriteTpl("index.html", g.Map{
"name": "john", "name": "john",
}) })
t.Assert(err, nil) t.AssertNil(err)
}) })
s.SetDumpRouterMap(false) s.SetDumpRouterMap(false)
s.Start() s.Start()
@ -78,11 +78,11 @@ func Test_Template_Layout1(t *testing.T) {
err := r.Response.WriteTpl("layout.html", g.Map{ err := r.Response.WriteTpl("layout.html", g.Map{
"mainTpl": "main/main1.html", "mainTpl": "main/main1.html",
}) })
t.Assert(err, nil) t.AssertNil(err)
}) })
s.BindHandler("/nil", func(r *ghttp.Request) { s.BindHandler("/nil", func(r *ghttp.Request) {
err := r.Response.WriteTpl("layout.html", nil) err := r.Response.WriteTpl("layout.html", nil)
t.Assert(err, nil) t.AssertNil(err)
}) })
s.SetDumpRouterMap(false) s.SetDumpRouterMap(false)
s.Start() s.Start()
@ -106,17 +106,17 @@ func Test_Template_Layout2(t *testing.T) {
err := r.Response.WriteTpl("layout.html", g.Map{ err := r.Response.WriteTpl("layout.html", g.Map{
"mainTpl": "main/main1.html", "mainTpl": "main/main1.html",
}) })
t.Assert(err, nil) t.AssertNil(err)
}) })
s.BindHandler("/main2", func(r *ghttp.Request) { s.BindHandler("/main2", func(r *ghttp.Request) {
err := r.Response.WriteTpl("layout.html", g.Map{ err := r.Response.WriteTpl("layout.html", g.Map{
"mainTpl": "main/main2.html", "mainTpl": "main/main2.html",
}) })
t.Assert(err, nil) t.AssertNil(err)
}) })
s.BindHandler("/nil", func(r *ghttp.Request) { s.BindHandler("/nil", func(r *ghttp.Request) {
err := r.Response.WriteTpl("layout.html", nil) err := r.Response.WriteTpl("layout.html", nil)
t.Assert(err, nil) t.AssertNil(err)
}) })
s.SetDumpRouterMap(false) s.SetDumpRouterMap(false)
s.Start() s.Start()
@ -137,7 +137,7 @@ func Test_Template_BuildInVarRequest(t *testing.T) {
s := g.Server(guid.S()) s := g.Server(guid.S())
s.BindHandler("/:table/test", func(r *ghttp.Request) { s.BindHandler("/:table/test", func(r *ghttp.Request) {
err := r.Response.WriteTplContent("{{.Request.table}}") err := r.Response.WriteTplContent("{{.Request.table}}")
t.Assert(err, nil) t.AssertNil(err)
}) })
s.SetDumpRouterMap(false) s.SetDumpRouterMap(false)
s.Start() s.Start()
@ -162,7 +162,7 @@ func Test_Template_XSS(t *testing.T) {
err := r.Response.WriteTplContent("{{if eq 1 1}}{{.v}}{{end}}", g.Map{ err := r.Response.WriteTplContent("{{if eq 1 1}}{{.v}}{{end}}", g.Map{
"v": c, "v": c,
}) })
t.Assert(err, nil) t.AssertNil(err)
}) })
s.SetDumpRouterMap(false) s.SetDumpRouterMap(false)
s.Start() s.Start()

View File

@ -44,15 +44,15 @@ func Test_WebSocket(t *testing.T) {
conn, _, err := websocket.DefaultDialer.Dial(fmt.Sprintf( conn, _, err := websocket.DefaultDialer.Dial(fmt.Sprintf(
"ws://127.0.0.1:%d/ws", s.GetListenedPort(), "ws://127.0.0.1:%d/ws", s.GetListenedPort(),
), nil) ), nil)
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
msg := []byte("hello") msg := []byte("hello")
err = conn.WriteMessage(websocket.TextMessage, msg) err = conn.WriteMessage(websocket.TextMessage, msg)
t.Assert(err, nil) t.AssertNil(err)
mt, data, err := conn.ReadMessage() mt, data, err := conn.ReadMessage()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(mt, websocket.TextMessage) t.Assert(mt, websocket.TextMessage)
t.Assert(data, msg) t.Assert(data, msg)
}) })

View File

@ -34,21 +34,21 @@ func Test_Package_Basic(t *testing.T) {
// SendPkg // SendPkg
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
err := conn.SendPkg([]byte(gconv.String(i))) err := conn.SendPkg([]byte(gconv.String(i)))
t.Assert(err, nil) t.AssertNil(err)
} }
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
err := conn.SendPkgWithTimeout([]byte(gconv.String(i)), time.Second) err := conn.SendPkgWithTimeout([]byte(gconv.String(i)), time.Second)
t.Assert(err, nil) t.AssertNil(err)
} }
}) })
// SendPkg with big data - failure. // SendPkg with big data - failure.
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := make([]byte, 65536) data := make([]byte, 65536)
err = conn.SendPkg(data) err = conn.SendPkg(data)
@ -57,25 +57,25 @@ func Test_Package_Basic(t *testing.T) {
// SendRecvPkg // SendRecvPkg
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
for i := 100; i < 200; i++ { for i := 100; i < 200; i++ {
data := []byte(gconv.String(i)) data := []byte(gconv.String(i))
result, err := conn.SendRecvPkg(data) result, err := conn.SendRecvPkg(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, data) t.Assert(result, data)
} }
for i := 100; i < 200; i++ { for i := 100; i < 200; i++ {
data := []byte(gconv.String(i)) data := []byte(gconv.String(i))
result, err := conn.SendRecvPkgWithTimeout(data, time.Second) result, err := conn.SendRecvPkgWithTimeout(data, time.Second)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, data) t.Assert(result, data)
} }
}) })
// SendRecvPkg with big data - failure. // SendRecvPkg with big data - failure.
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := make([]byte, 65536) data := make([]byte, 65536)
result, err := conn.SendRecvPkg(data) result, err := conn.SendRecvPkg(data)
@ -85,13 +85,13 @@ func Test_Package_Basic(t *testing.T) {
// SendRecvPkg with big data - success. // SendRecvPkg with big data - success.
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := make([]byte, 65500) data := make([]byte, 65500)
data[100] = byte(65) data[100] = byte(65)
data[65400] = byte(85) data[65400] = byte(85)
result, err := conn.SendRecvPkg(data) result, err := conn.SendRecvPkg(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, data) t.Assert(result, data)
}) })
} }
@ -114,7 +114,7 @@ func Test_Package_Timeout(t *testing.T) {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := []byte("10000") data := []byte("10000")
result, err := conn.SendRecvPkgWithTimeout(data, time.Millisecond*500) result, err := conn.SendRecvPkgWithTimeout(data, time.Millisecond*500)
@ -123,11 +123,11 @@ func Test_Package_Timeout(t *testing.T) {
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := []byte("10000") data := []byte("10000")
result, err := conn.SendRecvPkgWithTimeout(data, time.Second*2) result, err := conn.SendRecvPkgWithTimeout(data, time.Second*2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, data) t.Assert(result, data)
}) })
} }
@ -151,7 +151,7 @@ func Test_Package_Option(t *testing.T) {
// SendRecvPkg with big data - failure. // SendRecvPkg with big data - failure.
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := make([]byte, 0xFF+1) data := make([]byte, 0xFF+1)
result, err := conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 1}) result, err := conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 1})
@ -161,13 +161,13 @@ func Test_Package_Option(t *testing.T) {
// SendRecvPkg with big data - success. // SendRecvPkg with big data - success.
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := make([]byte, 0xFF) data := make([]byte, 0xFF)
data[100] = byte(65) data[100] = byte(65)
data[200] = byte(85) data[200] = byte(85)
result, err := conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 1}) result, err := conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 1})
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, data) t.Assert(result, data)
}) })
} }

View File

@ -34,21 +34,21 @@ func Test_Pool_Package_Basic(t *testing.T) {
// SendPkg // SendPkg
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
err := conn.SendPkg([]byte(gconv.String(i))) err := conn.SendPkg([]byte(gconv.String(i)))
t.Assert(err, nil) t.AssertNil(err)
} }
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
err := conn.SendPkgWithTimeout([]byte(gconv.String(i)), time.Second) err := conn.SendPkgWithTimeout([]byte(gconv.String(i)), time.Second)
t.Assert(err, nil) t.AssertNil(err)
} }
}) })
// SendPkg with big data - failure. // SendPkg with big data - failure.
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := make([]byte, 65536) data := make([]byte, 65536)
err = conn.SendPkg(data) err = conn.SendPkg(data)
@ -57,25 +57,25 @@ func Test_Pool_Package_Basic(t *testing.T) {
// SendRecvPkg // SendRecvPkg
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
for i := 100; i < 200; i++ { for i := 100; i < 200; i++ {
data := []byte(gconv.String(i)) data := []byte(gconv.String(i))
result, err := conn.SendRecvPkg(data) result, err := conn.SendRecvPkg(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, data) t.Assert(result, data)
} }
for i := 100; i < 200; i++ { for i := 100; i < 200; i++ {
data := []byte(gconv.String(i)) data := []byte(gconv.String(i))
result, err := conn.SendRecvPkgWithTimeout(data, time.Second) result, err := conn.SendRecvPkgWithTimeout(data, time.Second)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, data) t.Assert(result, data)
} }
}) })
// SendRecvPkg with big data - failure. // SendRecvPkg with big data - failure.
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := make([]byte, 65536) data := make([]byte, 65536)
result, err := conn.SendRecvPkg(data) result, err := conn.SendRecvPkg(data)
@ -85,13 +85,13 @@ func Test_Pool_Package_Basic(t *testing.T) {
// SendRecvPkg with big data - success. // SendRecvPkg with big data - success.
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := make([]byte, 65500) data := make([]byte, 65500)
data[100] = byte(65) data[100] = byte(65)
data[65400] = byte(85) data[65400] = byte(85)
result, err := conn.SendRecvPkg(data) result, err := conn.SendRecvPkg(data)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, data) t.Assert(result, data)
}) })
} }
@ -114,7 +114,7 @@ func Test_Pool_Package_Timeout(t *testing.T) {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := []byte("10000") data := []byte("10000")
result, err := conn.SendRecvPkgWithTimeout(data, time.Millisecond*500) result, err := conn.SendRecvPkgWithTimeout(data, time.Millisecond*500)
@ -123,11 +123,11 @@ func Test_Pool_Package_Timeout(t *testing.T) {
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := []byte("10000") data := []byte("10000")
result, err := conn.SendRecvPkgWithTimeout(data, time.Second*2) result, err := conn.SendRecvPkgWithTimeout(data, time.Second*2)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, data) t.Assert(result, data)
}) })
} }
@ -151,7 +151,7 @@ func Test_Pool_Package_Option(t *testing.T) {
// SendRecvPkg with big data - failure. // SendRecvPkg with big data - failure.
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := make([]byte, 0xFF+1) data := make([]byte, 0xFF+1)
result, err := conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 1}) result, err := conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 1})
@ -161,13 +161,13 @@ func Test_Pool_Package_Option(t *testing.T) {
// SendRecvPkg with big data - success. // SendRecvPkg with big data - success.
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := make([]byte, 0xFF) data := make([]byte, 0xFF)
data[100] = byte(65) data[100] = byte(65)
data[200] = byte(85) data[200] = byte(85)
result, err := conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 1}) result, err := conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 1})
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, data) t.Assert(result, data)
}) })
} }

View File

@ -32,13 +32,13 @@ func Test_Pool_Basic1(t *testing.T) {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := []byte("9999") data := []byte("9999")
err = conn.SendPkg(data) err = conn.SendPkg(data)
t.Assert(err, nil) t.AssertNil(err)
err = conn.SendPkgWithTimeout(data, time.Second) err = conn.SendPkgWithTimeout(data, time.Second)
t.Assert(err, nil) t.AssertNil(err)
}) })
} }
@ -52,13 +52,13 @@ func Test_Pool_Basic2(t *testing.T) {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
defer conn.Close() defer conn.Close()
data := []byte("9999") data := []byte("9999")
err = conn.SendPkg(data) err = conn.SendPkg(data)
t.Assert(err, nil) t.AssertNil(err)
//err = conn.SendPkgWithTimeout(data, time.Second) //err = conn.SendPkgWithTimeout(data, time.Second)
//t.Assert(err, nil) //t.AssertNil(err)
_, err = conn.SendRecv(data, -1) _, err = conn.SendRecv(data, -1)
t.AssertNE(err, nil) t.AssertNE(err, nil)

View File

@ -44,7 +44,7 @@ func Test_Basic(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
conn, err := gudp.NewConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gudp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
t.Assert(conn.Send([]byte(gconv.String(i))), nil) t.Assert(conn.Send([]byte(gconv.String(i))), nil)
conn.Close() conn.Close()
} }
@ -53,9 +53,9 @@ func Test_Basic(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
conn, err := gudp.NewConn(fmt.Sprintf("127.0.0.1:%d", p)) conn, err := gudp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
t.Assert(err, nil) t.AssertNil(err)
_, err = conn.SendRecv([]byte(gconv.String(i)), -1) _, err = conn.SendRecv([]byte(gconv.String(i)), -1)
t.Assert(err, nil) t.AssertNil(err)
//t.Assert(string(result), fmt.Sprintf(`> %d`, i)) //t.Assert(string(result), fmt.Sprintf(`> %d`, i))
conn.Close() conn.Close()
} }
@ -64,14 +64,14 @@ func Test_Basic(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
err := gudp.Send(fmt.Sprintf("127.0.0.1:%d", p), []byte(gconv.String(i))) err := gudp.Send(fmt.Sprintf("127.0.0.1:%d", p), []byte(gconv.String(i)))
t.Assert(err, nil) t.AssertNil(err)
} }
}) })
// gudp.SendRecv // gudp.SendRecv
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
result, err := gudp.SendRecv(fmt.Sprintf("127.0.0.1:%d", p), []byte(gconv.String(i)), -1) result, err := gudp.SendRecv(fmt.Sprintf("127.0.0.1:%d", p), []byte(gconv.String(i)), -1)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(result), fmt.Sprintf(`> %d`, i)) t.Assert(string(result), fmt.Sprintf(`> %d`, i))
} }
}) })
@ -103,12 +103,12 @@ func Test_Buffer(t *testing.T) {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
result, err := gudp.SendRecv(fmt.Sprintf("127.0.0.1:%d", p), []byte("123"), -1) result, err := gudp.SendRecv(fmt.Sprintf("127.0.0.1:%d", p), []byte("123"), -1)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(result), "1") t.Assert(string(result), "1")
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
result, err := gudp.SendRecv(fmt.Sprintf("127.0.0.1:%d", p), []byte("456"), -1) result, err := gudp.SendRecv(fmt.Sprintf("127.0.0.1:%d", p), []byte("456"), -1)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(result), "4") t.Assert(string(result), "4")
}) })
} }

View File

@ -105,7 +105,7 @@ func Test_SetFileName(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
path := "config.json" path := "config.json"
err := gfile.PutContents(path, config) err := gfile.PutContents(path, config)
t.Assert(err, nil) t.AssertNil(err)
defer func() { defer func() {
_ = gfile.Remove(path) _ = gfile.Remove(path)
}() }()
@ -155,18 +155,18 @@ func TestCfg_Get_WrongConfigFile(t *testing.T) {
var err error var err error
configPath := gfile.Temp(gtime.TimestampNanoStr()) configPath := gfile.Temp(gtime.TimestampNanoStr())
err = gfile.Mkdir(configPath) err = gfile.Mkdir(configPath)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(configPath) defer gfile.Remove(configPath)
defer gfile.Chdir(gfile.Pwd()) defer gfile.Chdir(gfile.Pwd())
err = gfile.Chdir(configPath) err = gfile.Chdir(configPath)
t.Assert(err, nil) t.AssertNil(err)
err = gfile.PutContents( err = gfile.PutContents(
gfile.Join(configPath, "config.yml"), gfile.Join(configPath, "config.yml"),
"wrong config", "wrong config",
) )
t.Assert(err, nil) t.AssertNil(err)
adapterFile, err := gcfg.NewAdapterFile("config.yml") adapterFile, err := gcfg.NewAdapterFile("config.yml")
t.AssertNil(err) t.AssertNil(err)

View File

@ -25,7 +25,7 @@ func Test_Parse(t *testing.T) {
"f,force": false, "f,force": false,
"q,quiet": false, "q,quiet": false,
}) })
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(p.GetArgAll()), 3) t.Assert(len(p.GetArgAll()), 3)
t.Assert(p.GetArg(0), "gf") t.Assert(p.GetArg(0), "gf")
t.Assert(p.GetArg(1), "remove") t.Assert(p.GetArg(1), "remove")
@ -64,7 +64,7 @@ func Test_ParseArgs(t *testing.T) {
"f,force": false, "f,force": false,
"q,quiet": false, "q,quiet": false,
}) })
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(p.GetArgAll()), 3) t.Assert(len(p.GetArgAll()), 3)
t.Assert(p.GetArg(0), "gf") t.Assert(p.GetArg(0), "gf")
t.Assert(p.GetArg(1), "remove") t.Assert(p.GetArg(1), "remove")

View File

@ -29,7 +29,7 @@ func Test_GEnv_Map(t *testing.T) {
value := gconv.String(gtime.TimestampNano()) value := gconv.String(gtime.TimestampNano())
key := "TEST_ENV_" + value key := "TEST_ENV_" + value
err := os.Setenv(key, "TEST") err := os.Setenv(key, "TEST")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(genv.Map()[key], "TEST") t.Assert(genv.Map()[key], "TEST")
}) })
} }
@ -39,7 +39,7 @@ func Test_GEnv_Get(t *testing.T) {
value := gconv.String(gtime.TimestampNano()) value := gconv.String(gtime.TimestampNano())
key := "TEST_ENV_" + value key := "TEST_ENV_" + value
err := os.Setenv(key, "TEST") err := os.Setenv(key, "TEST")
t.Assert(err, nil) t.AssertNil(err)
t.AssertEQ(genv.Get(key).String(), "TEST") t.AssertEQ(genv.Get(key).String(), "TEST")
}) })
} }
@ -49,7 +49,7 @@ func Test_GEnv_GetVar(t *testing.T) {
value := gconv.String(gtime.TimestampNano()) value := gconv.String(gtime.TimestampNano())
key := "TEST_ENV_" + value key := "TEST_ENV_" + value
err := os.Setenv(key, "TEST") err := os.Setenv(key, "TEST")
t.Assert(err, nil) t.AssertNil(err)
t.AssertEQ(genv.Get(key).String(), "TEST") t.AssertEQ(genv.Get(key).String(), "TEST")
}) })
} }
@ -59,7 +59,7 @@ func Test_GEnv_Contains(t *testing.T) {
value := gconv.String(gtime.TimestampNano()) value := gconv.String(gtime.TimestampNano())
key := "TEST_ENV_" + value key := "TEST_ENV_" + value
err := os.Setenv(key, "TEST") err := os.Setenv(key, "TEST")
t.Assert(err, nil) t.AssertNil(err)
t.AssertEQ(genv.Contains(key), true) t.AssertEQ(genv.Contains(key), true)
t.AssertEQ(genv.Contains("none"), false) t.AssertEQ(genv.Contains("none"), false)
}) })
@ -70,7 +70,7 @@ func Test_GEnv_Set(t *testing.T) {
value := gconv.String(gtime.TimestampNano()) value := gconv.String(gtime.TimestampNano())
key := "TEST_ENV_" + value key := "TEST_ENV_" + value
err := genv.Set(key, "TEST") err := genv.Set(key, "TEST")
t.Assert(err, nil) t.AssertNil(err)
t.AssertEQ(os.Getenv(key), "TEST") t.AssertEQ(os.Getenv(key), "TEST")
}) })
} }
@ -81,7 +81,7 @@ func Test_GEnv_SetMap(t *testing.T) {
"K1": "TEST1", "K1": "TEST1",
"K2": "TEST2", "K2": "TEST2",
}) })
t.Assert(err, nil) t.AssertNil(err)
t.AssertEQ(os.Getenv("K1"), "TEST1") t.AssertEQ(os.Getenv("K1"), "TEST1")
t.AssertEQ(os.Getenv("K2"), "TEST2") t.AssertEQ(os.Getenv("K2"), "TEST2")
}) })
@ -102,9 +102,9 @@ func Test_GEnv_Remove(t *testing.T) {
value := gconv.String(gtime.TimestampNano()) value := gconv.String(gtime.TimestampNano())
key := "TEST_ENV_" + value key := "TEST_ENV_" + value
err := os.Setenv(key, "TEST") err := os.Setenv(key, "TEST")
t.Assert(err, nil) t.AssertNil(err)
err = genv.Remove(key) err = genv.Remove(key)
t.Assert(err, nil) t.AssertNil(err)
t.AssertEQ(os.Getenv(key), "") t.AssertEQ(os.Getenv(key), "")
}) })
} }

View File

@ -100,10 +100,10 @@ func Test_Truncate(t *testing.T) {
createTestFile(filepaths1, "abcdefghijkmln") createTestFile(filepaths1, "abcdefghijkmln")
defer delTestFiles(filepaths1) defer delTestFiles(filepaths1)
err = gfile.Truncate(testpath()+filepaths1, 10) err = gfile.Truncate(testpath()+filepaths1, 10)
t.Assert(err, nil) t.AssertNil(err)
files, err = os.Open(testpath() + filepaths1) files, err = os.Open(testpath() + filepaths1)
t.Assert(err, nil) t.AssertNil(err)
defer files.Close() defer files.Close()
fileinfo, err2 := files.Stat() fileinfo, err2 := files.Stat()
t.Assert(err2, nil) t.Assert(err2, nil)
@ -126,10 +126,10 @@ func Test_PutContents(t *testing.T) {
defer delTestFiles(filepaths) defer delTestFiles(filepaths)
err = gfile.PutContents(testpath()+filepaths, "test!") err = gfile.PutContents(testpath()+filepaths, "test!")
t.Assert(err, nil) t.AssertNil(err)
readcontent, err = ioutil.ReadFile(testpath() + filepaths) readcontent, err = ioutil.ReadFile(testpath() + filepaths)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(readcontent), "test!") t.Assert(string(readcontent), "test!")
err = gfile.PutContents("", "test!") err = gfile.PutContents("", "test!")
@ -149,10 +149,10 @@ func Test_PutContentsAppend(t *testing.T) {
createTestFile(filepaths, "a") createTestFile(filepaths, "a")
defer delTestFiles(filepaths) defer delTestFiles(filepaths)
err = gfile.PutContentsAppend(testpath()+filepaths, "hello") err = gfile.PutContentsAppend(testpath()+filepaths, "hello")
t.Assert(err, nil) t.AssertNil(err)
readcontent, err = ioutil.ReadFile(testpath() + filepaths) readcontent, err = ioutil.ReadFile(testpath() + filepaths)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(readcontent), "ahello") t.Assert(string(readcontent), "ahello")
err = gfile.PutContentsAppend("", "hello") err = gfile.PutContentsAppend("", "hello")
@ -173,10 +173,10 @@ func Test_PutBinContents(t *testing.T) {
defer delTestFiles(filepaths) defer delTestFiles(filepaths)
err = gfile.PutBytes(testpath()+filepaths, []byte("test!!")) err = gfile.PutBytes(testpath()+filepaths, []byte("test!!"))
t.Assert(err, nil) t.AssertNil(err)
readcontent, err = ioutil.ReadFile(testpath() + filepaths) readcontent, err = ioutil.ReadFile(testpath() + filepaths)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(readcontent), "test!!") t.Assert(string(readcontent), "test!!")
err = gfile.PutBytes("", []byte("test!!")) err = gfile.PutBytes("", []byte("test!!"))
@ -195,10 +195,10 @@ func Test_PutBinContentsAppend(t *testing.T) {
createTestFile(filepaths, "test!!") createTestFile(filepaths, "test!!")
defer delTestFiles(filepaths) defer delTestFiles(filepaths)
err = gfile.PutBytesAppend(testpath()+filepaths, []byte("word")) err = gfile.PutBytesAppend(testpath()+filepaths, []byte("word"))
t.Assert(err, nil) t.AssertNil(err)
readcontent, err = ioutil.ReadFile(testpath() + filepaths) readcontent, err = ioutil.ReadFile(testpath() + filepaths)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(readcontent), "test!!word") t.Assert(string(readcontent), "test!!word")
err = gfile.PutBytesAppend("", []byte("word")) err = gfile.PutBytesAppend("", []byte("word"))
@ -324,7 +324,7 @@ func Test_Home(t *testing.T) {
) )
reads, err = gfile.Home("a", "b") reads, err = gfile.Home("a", "b")
t.Assert(err, nil) t.AssertNil(err)
t.AssertNE(reads, "") t.AssertNE(reads, "")
}) })
} }

View File

@ -127,7 +127,7 @@ func Test_CopyDir(t *testing.T) {
t.Assert(gfile.GetContents(dst), dstContent) t.Assert(gfile.GetContents(dst), dstContent)
err := gfile.CopyDir(gfile.Dir(src), gfile.Dir(dst)) err := gfile.CopyDir(gfile.Dir(src), gfile.Dir(dst))
t.Assert(err, nil) t.AssertNil(err)
t.Assert(gfile.GetContents(src), srcContent) t.Assert(gfile.GetContents(src), srcContent)
t.Assert(gfile.GetContents(dst), srcContent) t.Assert(gfile.GetContents(dst), srcContent)

View File

@ -19,14 +19,14 @@ func Test_ScanDir(t *testing.T) {
teatPath := gdebug.TestDataPath() teatPath := gdebug.TestDataPath()
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
files, err := gfile.ScanDir(teatPath, "*", false) files, err := gfile.ScanDir(teatPath, "*", false)
t.Assert(err, nil) t.AssertNil(err)
t.AssertIN(teatPath+gfile.Separator+"dir1", files) t.AssertIN(teatPath+gfile.Separator+"dir1", files)
t.AssertIN(teatPath+gfile.Separator+"dir2", files) t.AssertIN(teatPath+gfile.Separator+"dir2", files)
t.AssertNE(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files) t.AssertNE(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files)
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
files, err := gfile.ScanDir(teatPath, "*", true) files, err := gfile.ScanDir(teatPath, "*", true)
t.Assert(err, nil) t.AssertNil(err)
t.AssertIN(teatPath+gfile.Separator+"dir1", files) t.AssertIN(teatPath+gfile.Separator+"dir1", files)
t.AssertIN(teatPath+gfile.Separator+"dir2", files) t.AssertIN(teatPath+gfile.Separator+"dir2", files)
t.AssertIN(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files) t.AssertIN(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files)
@ -43,7 +43,7 @@ func Test_ScanDirFunc(t *testing.T) {
} }
return path return path
}) })
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(files), 1) t.Assert(len(files), 1)
t.Assert(gfile.Name(files[0]), "file1") t.Assert(gfile.Name(files[0]), "file1")
}) })
@ -53,12 +53,12 @@ func Test_ScanDirFile(t *testing.T) {
teatPath := gdebug.TestDataPath() teatPath := gdebug.TestDataPath()
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
files, err := gfile.ScanDirFile(teatPath, "*", false) files, err := gfile.ScanDirFile(teatPath, "*", false)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(files), 0) t.Assert(len(files), 0)
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
files, err := gfile.ScanDirFile(teatPath, "*", true) files, err := gfile.ScanDirFile(teatPath, "*", true)
t.Assert(err, nil) t.AssertNil(err)
t.AssertNI(teatPath+gfile.Separator+"dir1", files) t.AssertNI(teatPath+gfile.Separator+"dir1", files)
t.AssertNI(teatPath+gfile.Separator+"dir2", files) t.AssertNI(teatPath+gfile.Separator+"dir2", files)
t.AssertIN(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files) t.AssertIN(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files)
@ -74,7 +74,7 @@ func Test_ScanDirFileFunc(t *testing.T) {
array.Append(1) array.Append(1)
return path return path
}) })
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(files), 0) t.Assert(len(files), 0)
t.Assert(array.Len(), 0) t.Assert(array.Len(), 0)
}) })
@ -87,7 +87,7 @@ func Test_ScanDirFileFunc(t *testing.T) {
} }
return "" return ""
}) })
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(files), 1) t.Assert(len(files), 1)
t.Assert(array.Len(), 3) t.Assert(array.Len(), 3)
}) })

View File

@ -31,13 +31,13 @@ func Test_Search(t *testing.T) {
ypaths1 = paths1 ypaths1 = paths1
tpath, err = gfile.Search(testpath() + paths1) tpath, err = gfile.Search(testpath() + paths1)
t.Assert(err, nil) t.AssertNil(err)
tpath = filepath.ToSlash(tpath) tpath = filepath.ToSlash(tpath)
// 自定义优先路径 // 自定义优先路径
tpath2, err = gfile.Search(testpath() + paths1) tpath2, err = gfile.Search(testpath() + paths1)
t.Assert(err, nil) t.AssertNil(err)
tpath2 = filepath.ToSlash(tpath2) tpath2 = filepath.ToSlash(tpath2)
tempstr = testpath() tempstr = testpath()

View File

@ -69,7 +69,7 @@ func Test_Create(t *testing.T) {
fileobj, err = gfile.Create(testpath() + v) fileobj, err = gfile.Create(testpath() + v)
defer delTestFiles(v) defer delTestFiles(v)
fileobj.Close() fileobj.Close()
t.Assert(err, nil) t.AssertNil(err)
} }
}) })
} }
@ -97,7 +97,7 @@ func Test_Open(t *testing.T) {
fileobj, err = gfile.Open(testpath() + v) fileobj, err = gfile.Open(testpath() + v)
fileobj.Close() fileobj.Close()
if flags[k] { if flags[k] {
t.Assert(err, nil) t.AssertNil(err)
} else { } else {
t.AssertNE(err, nil) t.AssertNE(err, nil)
} }
@ -130,7 +130,7 @@ func Test_OpenFile(t *testing.T) {
fileobj, err = gfile.OpenFile(testpath()+v, os.O_RDWR, 0666) fileobj, err = gfile.OpenFile(testpath()+v, os.O_RDWR, 0666)
fileobj.Close() fileobj.Close()
if flags[k] { if flags[k] {
t.Assert(err, nil) t.AssertNil(err)
} else { } else {
t.AssertNE(err, nil) t.AssertNE(err, nil)
} }
@ -162,7 +162,7 @@ func Test_OpenWithFlag(t *testing.T) {
fileobj, err = gfile.OpenWithFlag(testpath()+v, os.O_RDWR) fileobj, err = gfile.OpenWithFlag(testpath()+v, os.O_RDWR)
fileobj.Close() fileobj.Close()
if flags[k] { if flags[k] {
t.Assert(err, nil) t.AssertNil(err)
} else { } else {
t.AssertNE(err, nil) t.AssertNE(err, nil)
} }
@ -193,7 +193,7 @@ func Test_OpenWithFlagPerm(t *testing.T) {
fileobj, err = gfile.OpenWithFlagPerm(testpath()+v, os.O_RDWR, 0666) fileobj, err = gfile.OpenWithFlagPerm(testpath()+v, os.O_RDWR, 0666)
fileobj.Close() fileobj.Close()
if flags[k] { if flags[k] {
t.Assert(err, nil) t.AssertNil(err)
} else { } else {
t.AssertNE(err, nil) t.AssertNE(err, nil)
} }
@ -238,7 +238,7 @@ func Test_Exists(t *testing.T) {
func Test_Pwd(t *testing.T) { func Test_Pwd(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
paths, err := os.Getwd() paths, err := os.Getwd()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(gfile.Pwd(), paths) t.Assert(gfile.Pwd(), paths)
}) })
@ -292,10 +292,10 @@ func Test_Info(t *testing.T) {
createTestFile(paths, "") createTestFile(paths, "")
defer delTestFiles(paths) defer delTestFiles(paths)
files, err = gfile.Stat(testpath() + paths) files, err = gfile.Stat(testpath() + paths)
t.Assert(err, nil) t.AssertNil(err)
files2, err = os.Stat(testpath() + paths) files2, err = os.Stat(testpath() + paths)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(files, files2) t.Assert(files, files2)
@ -370,7 +370,7 @@ func Test_DirNames(t *testing.T) {
readlist, err = gfile.DirNames(testpath() + paths) readlist, err = gfile.DirNames(testpath() + paths)
t.Assert(err, nil) t.AssertNil(err)
t.AssertIN(readlist, havelist) t.AssertIN(readlist, havelist)
_, err = gfile.DirNames("") _, err = gfile.DirNames("")
@ -406,16 +406,16 @@ func Test_Glob(t *testing.T) {
defer delTestFiles(dirpath) defer delTestFiles(dirpath)
resultlist, err = gfile.Glob(testpath()+paths, true) resultlist, err = gfile.Glob(testpath()+paths, true)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(resultlist, havelist1) t.Assert(resultlist, havelist1)
resultlist, err = gfile.Glob(testpath()+paths, false) resultlist, err = gfile.Glob(testpath()+paths, false)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(formatpaths(resultlist), formatpaths(havelist2)) t.Assert(formatpaths(resultlist), formatpaths(havelist2))
_, err = gfile.Glob("", true) _, err = gfile.Glob("", true)
t.Assert(err, nil) t.AssertNil(err)
}) })
} }
@ -628,13 +628,13 @@ func Test_Mkdir(t *testing.T) {
defer delTestFiles("/testfile") defer delTestFiles("/testfile")
err = gfile.Mkdir(testpath() + tpath) err = gfile.Mkdir(testpath() + tpath)
t.Assert(err, nil) t.AssertNil(err)
err = gfile.Mkdir("") err = gfile.Mkdir("")
t.AssertNE(err, nil) t.AssertNE(err, nil)
err = gfile.Mkdir(testpath() + tpath + "2/t1") err = gfile.Mkdir(testpath() + tpath + "2/t1")
t.Assert(err, nil) t.AssertNil(err)
}) })
} }
@ -652,7 +652,7 @@ func Test_Stat(t *testing.T) {
defer delTestFiles(tpath1) defer delTestFiles(tpath1)
fileiofo, err = gfile.Stat(testpath() + tpath1) fileiofo, err = gfile.Stat(testpath() + tpath1)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(fileiofo.Size(), 1) t.Assert(fileiofo.Size(), 1)

View File

@ -27,7 +27,7 @@ func Test_MTime(t *testing.T) {
createTestFile(file1, "") createTestFile(file1, "")
defer delTestFiles(file1) defer delTestFiles(file1)
fileobj, err = os.Stat(testpath() + file1) fileobj, err = os.Stat(testpath() + file1)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(gfile.MTime(testpath()+file1), fileobj.ModTime()) t.Assert(gfile.MTime(testpath()+file1), fileobj.ModTime())
t.Assert(gfile.MTime(""), "") t.Assert(gfile.MTime(""), "")
@ -45,7 +45,7 @@ func Test_MTimeMillisecond(t *testing.T) {
createTestFile(file1, "") createTestFile(file1, "")
defer delTestFiles(file1) defer delTestFiles(file1)
fileobj, err = os.Stat(testpath() + file1) fileobj, err = os.Stat(testpath() + file1)
t.Assert(err, nil) t.AssertNil(err)
time.Sleep(time.Millisecond * 100) time.Sleep(time.Millisecond * 100)
t.AssertGE( t.AssertGE(

View File

@ -150,29 +150,29 @@ func Test_ConcurrentOS(t *testing.T) {
path := gfile.Temp(gtime.TimestampNanoStr()) path := gfile.Temp(gtime.TimestampNanoStr())
defer gfile.Remove(path) defer gfile.Remove(path)
f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
t.Assert(err, nil) t.AssertNil(err)
defer f1.Close() defer f1.Close()
f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
t.Assert(err, nil) t.AssertNil(err)
defer f2.Close() defer f2.Close()
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
_, err = f1.Write([]byte("@1234567890#")) _, err = f1.Write([]byte("@1234567890#"))
t.Assert(err, nil) t.AssertNil(err)
} }
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
_, err = f2.Write([]byte("@1234567890#")) _, err = f2.Write([]byte("@1234567890#"))
t.Assert(err, nil) t.AssertNil(err)
} }
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
_, err = f1.Write([]byte("@1234567890#")) _, err = f1.Write([]byte("@1234567890#"))
t.Assert(err, nil) t.AssertNil(err)
} }
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
_, err = f2.Write([]byte("@1234567890#")) _, err = f2.Write([]byte("@1234567890#"))
t.Assert(err, nil) t.AssertNil(err)
} }
t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2200) t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2200)
}) })
@ -181,20 +181,20 @@ func Test_ConcurrentOS(t *testing.T) {
path := gfile.Temp(gtime.TimestampNanoStr()) path := gfile.Temp(gtime.TimestampNanoStr())
defer gfile.Remove(path) defer gfile.Remove(path)
f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
t.Assert(err, nil) t.AssertNil(err)
defer f1.Close() defer f1.Close()
f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
t.Assert(err, nil) t.AssertNil(err)
defer f2.Close() defer f2.Close()
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
_, err = f1.Write([]byte("@1234567890#")) _, err = f1.Write([]byte("@1234567890#"))
t.Assert(err, nil) t.AssertNil(err)
} }
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
_, err = f2.Write([]byte("@1234567890#")) _, err = f2.Write([]byte("@1234567890#"))
t.Assert(err, nil) t.AssertNil(err)
} }
t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000)
}) })
@ -202,11 +202,11 @@ func Test_ConcurrentOS(t *testing.T) {
path := gfile.Temp(gtime.TimestampNanoStr()) path := gfile.Temp(gtime.TimestampNanoStr())
defer gfile.Remove(path) defer gfile.Remove(path)
f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
t.Assert(err, nil) t.AssertNil(err)
defer f1.Close() defer f1.Close()
f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
t.Assert(err, nil) t.AssertNil(err)
defer f2.Close() defer f2.Close()
s1 := "" s1 := ""
@ -214,14 +214,14 @@ func Test_ConcurrentOS(t *testing.T) {
s1 += "@1234567890#" s1 += "@1234567890#"
} }
_, err = f2.Write([]byte(s1)) _, err = f2.Write([]byte(s1))
t.Assert(err, nil) t.AssertNil(err)
s2 := "" s2 := ""
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
s2 += "@1234567890#" s2 += "@1234567890#"
} }
_, err = f2.Write([]byte(s2)) _, err = f2.Write([]byte(s2))
t.Assert(err, nil) t.AssertNil(err)
t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000)
}) })
@ -230,11 +230,11 @@ func Test_ConcurrentOS(t *testing.T) {
// path := gfile.Temp(gtime.TimestampNanoStr()) // path := gfile.Temp(gtime.TimestampNanoStr())
// defer gfile.Remove(path) // defer gfile.Remove(path)
// f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) // f1, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
// t.Assert(err, nil) // t.AssertNil(err)
// defer f1.Close() // defer f1.Close()
// //
// f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) // f2, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
// t.Assert(err, nil) // t.AssertNil(err)
// defer f2.Close() // defer f2.Close()
// //
// wg := sync.WaitGroup{} // wg := sync.WaitGroup{}
@ -245,7 +245,7 @@ func Test_ConcurrentOS(t *testing.T) {
// defer wg.Done() // defer wg.Done()
// <-ch // <-ch
// _, err = f1.Write([]byte("@1234567890#")) // _, err = f1.Write([]byte("@1234567890#"))
// t.Assert(err, nil) // t.AssertNil(err)
// }() // }()
// } // }
// for i := 0; i < 1000; i++ { // for i := 0; i < 1000; i++ {
@ -254,7 +254,7 @@ func Test_ConcurrentOS(t *testing.T) {
// defer wg.Done() // defer wg.Done()
// <-ch // <-ch
// _, err = f2.Write([]byte("@1234567890#")) // _, err = f2.Write([]byte("@1234567890#"))
// t.Assert(err, nil) // t.AssertNil(err)
// }() // }()
// } // }
// close(ch) // close(ch)
@ -268,20 +268,20 @@ func Test_ConcurrentGFPool(t *testing.T) {
path := gfile.Temp(gtime.TimestampNanoStr()) path := gfile.Temp(gtime.TimestampNanoStr())
defer gfile.Remove(path) defer gfile.Remove(path)
f1, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) f1, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
t.Assert(err, nil) t.AssertNil(err)
defer f1.Close() defer f1.Close()
f2, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) f2, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
t.Assert(err, nil) t.AssertNil(err)
defer f2.Close() defer f2.Close()
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
_, err = f1.Write([]byte("@1234567890#")) _, err = f1.Write([]byte("@1234567890#"))
t.Assert(err, nil) t.AssertNil(err)
} }
for i := 0; i < 1000; i++ { for i := 0; i < 1000; i++ {
_, err = f2.Write([]byte("@1234567890#")) _, err = f2.Write([]byte("@1234567890#"))
t.Assert(err, nil) t.AssertNil(err)
} }
t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000) t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000)
}) })
@ -290,11 +290,11 @@ func Test_ConcurrentGFPool(t *testing.T) {
// path := gfile.Temp(gtime.TimestampNanoStr()) // path := gfile.Temp(gtime.TimestampNanoStr())
// defer gfile.Remove(path) // defer gfile.Remove(path)
// f1, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) // f1, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
// t.Assert(err, nil) // t.AssertNil(err)
// defer f1.Close() // defer f1.Close()
// //
// f2, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666) // f2, err := gfpool.Open(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_APPEND, 0666)
// t.Assert(err, nil) // t.AssertNil(err)
// defer f2.Close() // defer f2.Close()
// //
// wg := sync.WaitGroup{} // wg := sync.WaitGroup{}
@ -305,7 +305,7 @@ func Test_ConcurrentGFPool(t *testing.T) {
// defer wg.Done() // defer wg.Done()
// <-ch // <-ch
// _, err = f1.Write([]byte("@1234567890#")) // _, err = f1.Write([]byte("@1234567890#"))
// t.Assert(err, nil) // t.AssertNil(err)
// }() // }()
// } // }
// for i := 0; i < 1000; i++ { // for i := 0; i < 1000; i++ {
@ -314,7 +314,7 @@ func Test_ConcurrentGFPool(t *testing.T) {
// defer wg.Done() // defer wg.Done()
// <-ch // <-ch
// _, err = f2.Write([]byte("@1234567890#")) // _, err = f2.Write([]byte("@1234567890#"))
// t.Assert(err, nil) // t.AssertNil(err)
// }() // }()
// } // }
// close(ch) // close(ch)

View File

@ -24,31 +24,31 @@ func TestWatcher_AddOnce(t *testing.T) {
value := gtype.New() value := gtype.New()
path := gfile.Temp(gconv.String(gtime.TimestampNano())) path := gfile.Temp(gconv.String(gtime.TimestampNano()))
err := gfile.PutContents(path, "init") err := gfile.PutContents(path, "init")
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
callback1, err := gfsnotify.AddOnce("mywatch", path, func(event *gfsnotify.Event) { callback1, err := gfsnotify.AddOnce("mywatch", path, func(event *gfsnotify.Event) {
value.Set(1) value.Set(1)
}) })
t.Assert(err, nil) t.AssertNil(err)
callback2, err := gfsnotify.AddOnce("mywatch", path, func(event *gfsnotify.Event) { callback2, err := gfsnotify.AddOnce("mywatch", path, func(event *gfsnotify.Event) {
value.Set(2) value.Set(2)
}) })
t.Assert(err, nil) t.AssertNil(err)
t.Assert(callback2, nil) t.Assert(callback2, nil)
err = gfile.PutContents(path, "1") err = gfile.PutContents(path, "1")
t.Assert(err, nil) t.AssertNil(err)
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
t.Assert(value, 1) t.Assert(value, 1)
err = gfsnotify.RemoveCallback(callback1.Id) err = gfsnotify.RemoveCallback(callback1.Id)
t.Assert(err, nil) t.AssertNil(err)
err = gfile.PutContents(path, "2") err = gfile.PutContents(path, "2")
t.Assert(err, nil) t.AssertNil(err)
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
t.Assert(value, 1) t.Assert(value, 1)
@ -76,7 +76,7 @@ func TestWatcher_AddRemove(t *testing.T) {
return return
} }
}) })
t.Assert(err, nil) t.AssertNil(err)
t.AssertNE(callback, nil) t.AssertNE(callback, nil)
gfile.PutContents(path1, "2") gfile.PutContents(path1, "2")
@ -105,7 +105,7 @@ func TestWatcher_AddRemove(t *testing.T) {
return return
} }
}) })
t.Assert(err, nil) t.AssertNil(err)
t.AssertNE(callback, nil) t.AssertNE(callback, nil)
gfile.PutContents(path1, "2") gfile.PutContents(path1, "2")
@ -136,7 +136,7 @@ func TestWatcher_Callback1(t *testing.T) {
return return
} }
}) })
t.Assert(err, nil) t.AssertNil(err)
t.AssertNE(callback, nil) t.AssertNE(callback, nil)
gfile.PutContents(path1, "2") gfile.PutContents(path1, "2")

View File

@ -24,7 +24,7 @@ func Test_SetConfigWithMap(t *testing.T) {
"StStatus": 0, "StStatus": 0,
} }
err := l.SetConfigWithMap(m) err := l.SetConfigWithMap(m)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(l.config.Path, m["path"]) t.Assert(l.config.Path, m["path"])
t.Assert(l.config.Level, LEVEL_ALL) t.Assert(l.config.Level, LEVEL_ALL)
t.Assert(l.config.StdoutPrint, m["stdout"]) t.Assert(l.config.StdoutPrint, m["stdout"])
@ -39,7 +39,7 @@ func Test_SetConfigWithMap_LevelStr(t *testing.T) {
"level": "all", "level": "all",
} }
err := l.SetConfigWithMap(m) err := l.SetConfigWithMap(m)
t.Assert(err, nil) t.AssertNil(err)
l.SetWriter(buffer) l.SetWriter(buffer)
@ -56,7 +56,7 @@ func Test_SetConfigWithMap_LevelStr(t *testing.T) {
"level": "warn", "level": "warn",
} }
err := l.SetConfigWithMap(m) err := l.SetConfigWithMap(m)
t.Assert(err, nil) t.AssertNil(err)
l.SetWriter(buffer) l.SetWriter(buffer)
l.Debug(ctx, "test") l.Debug(ctx, "test")
l.Warning(ctx, "test") l.Warning(ctx, "test")

View File

@ -34,7 +34,7 @@ func Test_Path(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).Stdout(false).Error(ctx, 1, 2, 3) Path(path).File(file).Stdout(false).Error(ctx, 1, 2, 3)
@ -52,7 +52,7 @@ func Test_Cat(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).Cat(cat).Stdout(false).Error(ctx, 1, 2, 3) Path(path).File(file).Cat(cat).Stdout(false).Error(ctx, 1, 2, 3)
@ -69,7 +69,7 @@ func Test_Level(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).Level(LEVEL_PROD).Stdout(false).Debug(ctx, 1, 2, 3) Path(path).File(file).Level(LEVEL_PROD).Stdout(false).Debug(ctx, 1, 2, 3)
@ -86,7 +86,7 @@ func Test_Skip(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).Skip(10).Stdout(false).Error(ctx, 1, 2, 3) Path(path).File(file).Skip(10).Stdout(false).Error(ctx, 1, 2, 3)
@ -105,7 +105,7 @@ func Test_Stack(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).Stack(false).Stdout(false).Error(ctx, 1, 2, 3) Path(path).File(file).Stack(false).Stdout(false).Error(ctx, 1, 2, 3)
@ -124,7 +124,7 @@ func Test_StackWithFilter(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).StackWithFilter("none").Stdout(false).Error(ctx, 1, 2, 3) Path(path).File(file).StackWithFilter("none").Stdout(false).Error(ctx, 1, 2, 3)
@ -140,7 +140,7 @@ func Test_StackWithFilter(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).StackWithFilter("/gf/").Stdout(false).Error(ctx, 1, 2, 3) Path(path).File(file).StackWithFilter("/gf/").Stdout(false).Error(ctx, 1, 2, 3)
@ -158,7 +158,7 @@ func Test_Header(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).Header(true).Stdout(false).Error(ctx, 1, 2, 3) Path(path).File(file).Header(true).Stdout(false).Error(ctx, 1, 2, 3)
@ -171,7 +171,7 @@ func Test_Header(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).Header(false).Stdout(false).Error(ctx, 1, 2, 3) Path(path).File(file).Header(false).Stdout(false).Error(ctx, 1, 2, 3)
@ -187,7 +187,7 @@ func Test_Line(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).Line(true).Stdout(false).Debug(ctx, 1, 2, 3) Path(path).File(file).Line(true).Stdout(false).Debug(ctx, 1, 2, 3)
@ -203,7 +203,7 @@ func Test_Line(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).Line(false).Stdout(false).Debug(ctx, 1, 2, 3) Path(path).File(file).Line(false).Stdout(false).Debug(ctx, 1, 2, 3)
@ -221,7 +221,7 @@ func Test_Async(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).Async().Stdout(false).Debug(ctx, 1, 2, 3) Path(path).File(file).Async().Stdout(false).Debug(ctx, 1, 2, 3)
@ -239,7 +239,7 @@ func Test_Async(t *testing.T) {
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano()) file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
err := gfile.Mkdir(path) err := gfile.Mkdir(path)
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(path) defer gfile.Remove(path)
Path(path).File(file).Async(false).Stdout(false).Debug(ctx, 1, 2, 3) Path(path).File(file).Async(false).Stdout(false).Debug(ctx, 1, 2, 3)

View File

@ -38,7 +38,7 @@ func Test_Rotate_Size(t *testing.T) {
"RotateBackupCompress": 9, "RotateBackupCompress": 9,
"RotateCheckInterval": time.Second, // For unit testing only. "RotateCheckInterval": time.Second, // For unit testing only.
}) })
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(p) defer gfile.Remove(p)
s := "1234567890abcdefg" s := "1234567890abcdefg"
@ -50,7 +50,7 @@ func Test_Rotate_Size(t *testing.T) {
time.Sleep(time.Second * 3) time.Sleep(time.Second * 3)
files, err := gfile.ScanDirFile(p, "*.gz") files, err := gfile.ScanDirFile(p, "*.gz")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(files), 2) t.Assert(len(files), 2)
content := gfile.GetContents(gfile.Join(p, "access.log")) content := gfile.GetContents(gfile.Join(p, "access.log"))
@ -58,7 +58,7 @@ func Test_Rotate_Size(t *testing.T) {
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
files, err = gfile.ScanDirFile(p, "*.gz") files, err = gfile.ScanDirFile(p, "*.gz")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(files), 0) t.Assert(len(files), 0)
}) })
} }
@ -77,7 +77,7 @@ func Test_Rotate_Expire(t *testing.T) {
"RotateBackupCompress": 9, "RotateBackupCompress": 9,
"RotateCheckInterval": time.Second, // For unit testing only. "RotateCheckInterval": time.Second, // For unit testing only.
}) })
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(p) defer gfile.Remove(p)
s := "1234567890abcdefg" s := "1234567890abcdefg"
@ -86,7 +86,7 @@ func Test_Rotate_Expire(t *testing.T) {
} }
files, err := gfile.ScanDirFile(p, "*.gz") files, err := gfile.ScanDirFile(p, "*.gz")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(files), 0) t.Assert(len(files), 0)
t.Assert(gstr.Count(gfile.GetContents(gfile.Join(p, "access.log")), s), 10) t.Assert(gstr.Count(gfile.GetContents(gfile.Join(p, "access.log")), s), 10)
@ -94,14 +94,14 @@ func Test_Rotate_Expire(t *testing.T) {
time.Sleep(time.Second * 3) time.Sleep(time.Second * 3)
files, err = gfile.ScanDirFile(p, "*.gz") files, err = gfile.ScanDirFile(p, "*.gz")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(files), 1) t.Assert(len(files), 1)
t.Assert(gstr.Count(gfile.GetContents(gfile.Join(p, "access.log")), s), 0) t.Assert(gstr.Count(gfile.GetContents(gfile.Join(p, "access.log")), s), 0)
time.Sleep(time.Second * 5) time.Sleep(time.Second * 5)
files, err = gfile.ScanDirFile(p, "*.gz") files, err = gfile.ScanDirFile(p, "*.gz")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(len(files), 0) t.Assert(len(files), 0)
}) })
} }

View File

@ -43,7 +43,7 @@ func Test_Ctx_Config(t *testing.T) {
"CtxKeys": g.SliceStr{"Trace-Id", "Span-Id", "Test"}, "CtxKeys": g.SliceStr{"Trace-Id", "Span-Id", "Test"},
} }
err := l.SetConfigWithMap(m) err := l.SetConfigWithMap(m)
t.Assert(err, nil) t.AssertNil(err)
ctx := context.WithValue(context.Background(), "Trace-Id", "1234567890") ctx := context.WithValue(context.Background(), "Trace-Id", "1234567890")
ctx = context.WithValue(ctx, "Span-Id", "abcdefg") ctx = context.WithValue(ctx, "Span-Id", "abcdefg")

View File

@ -28,7 +28,7 @@ func Test_PackToGoFile(t *testing.T) {
pkgName = "testdata" pkgName = "testdata"
err = gres.PackToGoFile(srcPath, goFilePath, pkgName) err = gres.PackToGoFile(srcPath, goFilePath, pkgName)
) )
t.Assert(err, nil) t.AssertNil(err)
_ = gfile.Remove(goFilePath) _ = gfile.Remove(goFilePath)
}) })
} }
@ -39,11 +39,11 @@ func Test_Pack(t *testing.T) {
srcPath = gdebug.TestDataPath("files") srcPath = gdebug.TestDataPath("files")
data, err = gres.Pack(srcPath) data, err = gres.Pack(srcPath)
) )
t.Assert(err, nil) t.AssertNil(err)
r := gres.New() r := gres.New()
err = r.Add(string(data)) err = r.Add(string(data))
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r.Contains("files/"), true) t.Assert(r.Contains("files/"), true)
}) })
} }
@ -55,13 +55,13 @@ func Test_PackToFile(t *testing.T) {
dstPath = gfile.Temp(gtime.TimestampNanoStr()) dstPath = gfile.Temp(gtime.TimestampNanoStr())
err = gres.PackToFile(srcPath, dstPath) err = gres.PackToFile(srcPath, dstPath)
) )
t.Assert(err, nil) t.AssertNil(err)
defer gfile.Remove(dstPath) defer gfile.Remove(dstPath)
r := gres.New() r := gres.New()
err = r.Load(dstPath) err = r.Load(dstPath)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(r.Contains("files"), true) t.Assert(r.Contains("files"), true)
}) })
} }
@ -74,9 +74,9 @@ func Test_PackMulti(t *testing.T) {
pkgName = "data" pkgName = "data"
array, err = gfile.ScanDir(srcPath, "*", false) array, err = gfile.ScanDir(srcPath, "*", false)
) )
t.Assert(err, nil) t.AssertNil(err)
err = gres.PackToGoFile(strings.Join(array, ","), goFilePath, pkgName) err = gres.PackToGoFile(strings.Join(array, ","), goFilePath, pkgName)
t.Assert(err, nil) t.AssertNil(err)
_ = gfile.Remove(goFilePath) _ = gfile.Remove(goFilePath)
}) })
} }
@ -102,7 +102,7 @@ func Test_PackWithPrefix2(t *testing.T) {
pkgName = "testdata" pkgName = "testdata"
err = gres.PackToGoFile(srcPath, goFilePath, pkgName, "/var/www/gf-site/test") err = gres.PackToGoFile(srcPath, goFilePath, pkgName, "/var/www/gf-site/test")
) )
t.Assert(err, nil) t.AssertNil(err)
_ = gfile.Remove(goFilePath) _ = gfile.Remove(goFilePath)
}) })
} }
@ -127,13 +127,13 @@ func Test_Basic(t *testing.T) {
t.Assert(info.Name(), "test1") t.Assert(info.Name(), "test1")
rc, err := file.Open() rc, err := file.Open()
t.Assert(err, nil) t.AssertNil(err)
defer rc.Close() defer rc.Close()
b := make([]byte, 5) b := make([]byte, 5)
n, err := rc.Read(b) n, err := rc.Read(b)
t.Assert(n, 5) t.Assert(n, 5)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(string(b), "test1") t.Assert(string(b), "test1")
t.Assert(file.Content(), "test1 content") t.Assert(file.Content(), "test1 content")
@ -151,7 +151,7 @@ func Test_Basic(t *testing.T) {
t.Assert(info.Name(), "dir2") t.Assert(info.Name(), "dir2")
rc, err := file.Open() rc, err := file.Open()
t.Assert(err, nil) t.AssertNil(err)
defer rc.Close() defer rc.Close()
t.Assert(file.Content(), nil) t.Assert(file.Content(), nil)

View File

@ -88,7 +88,7 @@ func Test_StorageRedisHashTablePrefix(t *testing.T) {
Db: 0, Db: 0,
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
t.Assert(err, nil) t.AssertNil(err)
}) })
prefix := "s_" prefix := "s_"

View File

@ -22,7 +22,7 @@ func Test_StorageRedis(t *testing.T) {
Address: "127.0.0.1:6379", Address: "127.0.0.1:6379",
Db: 0, Db: 0,
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
storage := gsession.NewStorageRedis(redis) storage := gsession.NewStorageRedis(redis)
manager := gsession.New(time.Second, storage) manager := gsession.New(time.Second, storage)
@ -86,7 +86,7 @@ func Test_StorageRedisPrefix(t *testing.T) {
Address: "127.0.0.1:6379", Address: "127.0.0.1:6379",
Db: 0, Db: 0,
}) })
gtest.Assert(err, nil) gtest.AssertNil(err)
prefix := "s_" prefix := "s_"
storage := gsession.NewStorageRedis(redis, prefix) storage := gsession.NewStorageRedis(redis, prefix)

View File

@ -45,7 +45,7 @@ func TestSPath_Basic(t *testing.T) {
defer gfile.Remove(gfile.Join(root, "gf_tmp")) defer gfile.Remove(gfile.Join(root, "gf_tmp"))
gsp := gspath.New(root, false) gsp := gspath.New(root, false)
realPath, err := gsp.Add(gfile.Join(root, "gf_tmp")) realPath, err := gsp.Add(gfile.Join(root, "gf_tmp"))
t.Assert(err, nil) t.AssertNil(err)
t.Assert(realPath, gfile.Join(root, "gf_tmp")) t.Assert(realPath, gfile.Join(root, "gf_tmp"))
realPath, err = gsp.Add("gf_tmp1") realPath, err = gsp.Add("gf_tmp1")
t.Assert(err != nil, true) t.Assert(err != nil, true)
@ -65,7 +65,7 @@ func TestSPath_Basic(t *testing.T) {
t.Assert(realPath, "") t.Assert(realPath, "")
realPath, err = gsp.Set(root) realPath, err = gsp.Set(root)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(realPath, root) t.Assert(realPath, root)
fp, isDir := gsp.Search("gf_tmp") fp, isDir := gsp.Search("gf_tmp")
@ -80,7 +80,7 @@ func TestSPath_Basic(t *testing.T) {
gsp = gspath.New(root, true) gsp = gspath.New(root, true)
realPath, err = gsp.Add(gfile.Join(root, "gf_tmp")) realPath, err = gsp.Add(gfile.Join(root, "gf_tmp"))
t.Assert(err, nil) t.AssertNil(err)
t.Assert(realPath, gfile.Join(root, "gf_tmp")) t.Assert(realPath, gfile.Join(root, "gf_tmp"))
gfile.Mkdir(gfile.Join(root, "gf_tmp1")) gfile.Mkdir(gfile.Join(root, "gf_tmp1"))

View File

@ -30,12 +30,12 @@ func TestTime_Value(t1 *testing.T) {
gtest.C(t1, func(t *gtest.T) { gtest.C(t1, func(t *gtest.T) {
tt := gtime.Now() tt := gtime.Now()
s, err := tt.Value() s, err := tt.Value()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(s, tt.Time) t.Assert(s, tt.Time)
// test nil // test nil
none := (*gtime.Time)(nil) none := (*gtime.Time)(nil)
s, err = none.Value() s, err = none.Value()
t.Assert(err, nil) t.AssertNil(err)
t.Assert(s, nil) t.Assert(s, nil)
}) })

View File

@ -105,7 +105,7 @@ func Test_StrToTime(t *testing.T) {
for _, item := range testDateTimes { for _, item := range testDateTimes {
timeTemp, err := gtime.StrToTime(item) timeTemp, err := gtime.StrToTime(item)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), "2006-01-02 15:04:05") t.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), "2006-01-02 15:04:05")
} }
@ -118,7 +118,7 @@ func Test_StrToTime(t *testing.T) {
for _, item := range testDates { for _, item := range testDates {
timeTemp, err := gtime.StrToTime(item) timeTemp, err := gtime.StrToTime(item)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), "2006-01-02 00:00:00") t.Assert(timeTemp.Time.Format("2006-01-02 15:04:05"), "2006-01-02 00:00:00")
} }
@ -130,9 +130,9 @@ func Test_StrToTime(t *testing.T) {
for k, v := range testTimes { for k, v := range testTimes {
time1, err := gtime.StrToTime(k) time1, err := gtime.StrToTime(k)
t.Assert(err, nil) t.AssertNil(err)
time2, err := time.ParseInLocation(v, k, time.Local) time2, err := time.ParseInLocation(v, k, time.Local)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(time1.Time, time2) t.Assert(time1.Time, time2)
} }
@ -232,22 +232,22 @@ func Test_ConvertZone(t *testing.T) {
func Test_ParseDuration(t *testing.T) { func Test_ParseDuration(t *testing.T) {
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
d, err := gtime.ParseDuration("1d") d, err := gtime.ParseDuration("1d")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(d.String(), "24h0m0s") t.Assert(d.String(), "24h0m0s")
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
d, err := gtime.ParseDuration("1d2h3m") d, err := gtime.ParseDuration("1d2h3m")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(d.String(), "26h3m0s") t.Assert(d.String(), "26h3m0s")
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
d, err := gtime.ParseDuration("-1d2h3m") d, err := gtime.ParseDuration("-1d2h3m")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(d.String(), "-26h3m0s") t.Assert(d.String(), "-26h3m0s")
}) })
gtest.C(t, func(t *gtest.T) { gtest.C(t, func(t *gtest.T) {
d, err := gtime.ParseDuration("3m") d, err := gtime.ParseDuration("3m")
t.Assert(err, nil) t.AssertNil(err)
t.Assert(d.String(), "3m0s") t.Assert(d.String(), "3m0s")
}) })
// error // error

View File

@ -28,16 +28,16 @@ func Test_Config(t *testing.T) {
} }
view := gview.New() view := gview.New()
err := view.SetConfig(config) err := view.SetConfig(config)
t.Assert(err, nil) t.AssertNil(err)
str := `hello ${.name},version:${.version}` str := `hello ${.name},version:${.version}`
view.Assigns(g.Map{"version": "1.7.0"}) view.Assigns(g.Map{"version": "1.7.0"})
result, err := view.ParseContent(context.TODO(), str, nil) result, err := view.ParseContent(context.TODO(), str, nil)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, "hello gf,version:1.7.0") t.Assert(result, "hello gf,version:1.7.0")
result, err = view.ParseDefault(context.TODO()) result, err = view.ParseDefault(context.TODO())
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, "name:gf") t.Assert(result, "name:gf")
}) })
} }
@ -53,16 +53,16 @@ func Test_ConfigWithMap(t *testing.T) {
"name": "gf", "name": "gf",
}, },
}) })
t.Assert(err, nil) t.AssertNil(err)
str := `hello ${.name},version:${.version}` str := `hello ${.name},version:${.version}`
view.Assigns(g.Map{"version": "1.7.0"}) view.Assigns(g.Map{"version": "1.7.0"})
result, err := view.ParseContent(context.TODO(), str, nil) result, err := view.ParseContent(context.TODO(), str, nil)
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, "hello gf,version:1.7.0") t.Assert(result, "hello gf,version:1.7.0")
result, err = view.ParseDefault(context.TODO()) result, err = view.ParseDefault(context.TODO())
t.Assert(err, nil) t.AssertNil(err)
t.Assert(result, "name:gf") t.Assert(result, "name:gf")
}) })
} }

Some files were not shown because too many files have changed in this diff Show More