mirror of
https://gitee.com/johng/gf.git
synced 2024-11-29 10:47:38 +08:00
t.Assert(err, nil) -> t.AssertNil(err)
This commit is contained in:
parent
eca3583845
commit
546b6b1724
@ -576,7 +576,7 @@ func TestArray_Json(t *testing.T) {
|
||||
|
||||
var a3 garray.Array
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Slice(), s1)
|
||||
})
|
||||
// value.
|
||||
@ -595,7 +595,7 @@ func TestArray_Json(t *testing.T) {
|
||||
|
||||
var a3 garray.Array
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Slice(), s1)
|
||||
})
|
||||
// pointer
|
||||
@ -609,11 +609,11 @@ func TestArray_Json(t *testing.T) {
|
||||
"Scores": []int{99, 100, 98},
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
user := new(User)
|
||||
err = json.UnmarshalUseNumber(b, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Name, data["Name"])
|
||||
t.Assert(user.Scores, data["Scores"])
|
||||
})
|
||||
@ -628,11 +628,11 @@ func TestArray_Json(t *testing.T) {
|
||||
"Scores": []int{99, 100, 98},
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
user := new(User)
|
||||
err = json.UnmarshalUseNumber(b, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Name, data["Name"])
|
||||
t.Assert(user.Scores, data["Scores"])
|
||||
})
|
||||
@ -720,7 +720,7 @@ func TestArray_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"array": g.Slice{1, 2, 3},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
|
||||
})
|
||||
|
@ -619,7 +619,7 @@ func TestIntArray_Json(t *testing.T) {
|
||||
|
||||
var a3 garray.IntArray
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Slice(), s1)
|
||||
})
|
||||
// array value
|
||||
@ -637,7 +637,7 @@ func TestIntArray_Json(t *testing.T) {
|
||||
|
||||
var a3 garray.IntArray
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Slice(), s1)
|
||||
})
|
||||
// array pointer
|
||||
@ -651,11 +651,11 @@ func TestIntArray_Json(t *testing.T) {
|
||||
"Scores": []int{99, 100, 98},
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
user := new(User)
|
||||
err = json.UnmarshalUseNumber(b, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Name, data["Name"])
|
||||
t.Assert(user.Scores, data["Scores"])
|
||||
})
|
||||
@ -670,11 +670,11 @@ func TestIntArray_Json(t *testing.T) {
|
||||
"Scores": []int{99, 100, 98},
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
user := new(User)
|
||||
err = json.UnmarshalUseNumber(b, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Name, data["Name"])
|
||||
t.Assert(user.Scores, data["Scores"])
|
||||
})
|
||||
@ -752,7 +752,7 @@ func TestIntArray_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"array": []byte(`[1,2,3]`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
|
||||
})
|
||||
@ -763,7 +763,7 @@ func TestIntArray_UnmarshalValue(t *testing.T) {
|
||||
// "name": "john",
|
||||
// "array": g.Slice{1, 2, 3},
|
||||
// }, &v)
|
||||
// t.Assert(err, nil)
|
||||
// t.AssertNil(err)
|
||||
// t.Assert(v.Name, "john")
|
||||
// t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
|
||||
// })
|
||||
|
@ -619,7 +619,7 @@ func TestStrArray_Json(t *testing.T) {
|
||||
|
||||
var a3 garray.StrArray
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Slice(), s1)
|
||||
})
|
||||
// array value
|
||||
@ -637,7 +637,7 @@ func TestStrArray_Json(t *testing.T) {
|
||||
|
||||
var a3 garray.StrArray
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Slice(), s1)
|
||||
})
|
||||
// array pointer
|
||||
@ -651,11 +651,11 @@ func TestStrArray_Json(t *testing.T) {
|
||||
"Scores": []string{"A+", "A", "A"},
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
user := new(User)
|
||||
err = json.UnmarshalUseNumber(b, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Name, data["Name"])
|
||||
t.Assert(user.Scores, data["Scores"])
|
||||
})
|
||||
@ -670,11 +670,11 @@ func TestStrArray_Json(t *testing.T) {
|
||||
"Scores": []string{"A+", "A", "A"},
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
user := new(User)
|
||||
err = json.UnmarshalUseNumber(b, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Name, data["Name"])
|
||||
t.Assert(user.Scores, data["Scores"])
|
||||
})
|
||||
@ -751,7 +751,7 @@ func TestStrArray_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"array": []byte(`["1","2","3"]`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"})
|
||||
})
|
||||
@ -762,7 +762,7 @@ func TestStrArray_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"array": g.SliceStr{"1", "2", "3"},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"})
|
||||
})
|
||||
|
@ -661,7 +661,7 @@ func TestSortedArray_Json(t *testing.T) {
|
||||
|
||||
var a3 garray.SortedArray
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Slice(), s1)
|
||||
t.Assert(a3.Interfaces(), s1)
|
||||
})
|
||||
@ -681,7 +681,7 @@ func TestSortedArray_Json(t *testing.T) {
|
||||
|
||||
var a3 garray.SortedArray
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Slice(), s1)
|
||||
t.Assert(a3.Interfaces(), s1)
|
||||
})
|
||||
@ -696,11 +696,11 @@ func TestSortedArray_Json(t *testing.T) {
|
||||
"Scores": []int{99, 100, 98},
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
user := new(User)
|
||||
err = json.UnmarshalUseNumber(b, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Name, data["Name"])
|
||||
t.AssertNE(user.Scores, nil)
|
||||
t.Assert(user.Scores.Len(), 3)
|
||||
@ -732,11 +732,11 @@ func TestSortedArray_Json(t *testing.T) {
|
||||
"Scores": []int{99, 100, 98},
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
user := new(User)
|
||||
err = json.UnmarshalUseNumber(b, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Name, data["Name"])
|
||||
t.AssertNE(user.Scores, nil)
|
||||
t.Assert(user.Scores.Len(), 3)
|
||||
@ -830,7 +830,7 @@ func TestSortedArray_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"array": []byte(`[2,3,1]`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
|
||||
})
|
||||
@ -841,7 +841,7 @@ func TestSortedArray_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"array": g.Slice{2, 3, 1},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
|
||||
})
|
||||
|
@ -561,7 +561,7 @@ func TestSortedIntArray_Json(t *testing.T) {
|
||||
|
||||
var a3 garray.SortedIntArray
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Slice(), s1)
|
||||
})
|
||||
// array value
|
||||
@ -580,7 +580,7 @@ func TestSortedIntArray_Json(t *testing.T) {
|
||||
|
||||
var a3 garray.SortedIntArray
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Slice(), s1)
|
||||
})
|
||||
// array pointer
|
||||
@ -594,11 +594,11 @@ func TestSortedIntArray_Json(t *testing.T) {
|
||||
"Scores": []int{99, 100, 98},
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
user := new(User)
|
||||
err = json.UnmarshalUseNumber(b, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Name, data["Name"])
|
||||
t.Assert(user.Scores, []int{98, 99, 100})
|
||||
})
|
||||
@ -613,11 +613,11 @@ func TestSortedIntArray_Json(t *testing.T) {
|
||||
"Scores": []int{99, 100, 98},
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
user := new(User)
|
||||
err = json.UnmarshalUseNumber(b, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Name, data["Name"])
|
||||
t.Assert(user.Scores, []int{98, 99, 100})
|
||||
})
|
||||
@ -695,7 +695,7 @@ func TestSortedIntArray_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"array": []byte(`[2,3,1]`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
|
||||
})
|
||||
@ -706,7 +706,7 @@ func TestSortedIntArray_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"array": g.Slice{2, 3, 1},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Array.Slice(), g.Slice{1, 2, 3})
|
||||
})
|
||||
|
@ -583,7 +583,7 @@ func TestSortedStrArray_Json(t *testing.T) {
|
||||
|
||||
var a3 garray.SortedStrArray
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Slice(), s1)
|
||||
t.Assert(a3.Interfaces(), s1)
|
||||
})
|
||||
@ -604,7 +604,7 @@ func TestSortedStrArray_Json(t *testing.T) {
|
||||
|
||||
var a3 garray.SortedStrArray
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Slice(), s1)
|
||||
t.Assert(a3.Interfaces(), s1)
|
||||
})
|
||||
@ -619,11 +619,11 @@ func TestSortedStrArray_Json(t *testing.T) {
|
||||
"Scores": []string{"A+", "A", "A"},
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
user := new(User)
|
||||
err = json.UnmarshalUseNumber(b, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Name, data["Name"])
|
||||
t.Assert(user.Scores, []string{"A", "A", "A+"})
|
||||
})
|
||||
@ -638,11 +638,11 @@ func TestSortedStrArray_Json(t *testing.T) {
|
||||
"Scores": []string{"A+", "A", "A"},
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
user := new(User)
|
||||
err = json.UnmarshalUseNumber(b, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Name, data["Name"])
|
||||
t.Assert(user.Scores, []string{"A", "A", "A+"})
|
||||
})
|
||||
@ -719,7 +719,7 @@ func TestSortedStrArray_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"array": []byte(`["1","3","2"]`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"})
|
||||
})
|
||||
@ -730,7 +730,7 @@ func TestSortedStrArray_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"array": g.SliceStr{"1", "3", "2"},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Array.Slice(), g.SliceStr{"1", "2", "3"})
|
||||
})
|
||||
|
@ -709,20 +709,20 @@ func TestList_Json(t *testing.T) {
|
||||
a := []interface{}{"a", "b", "c"}
|
||||
l := New()
|
||||
b, err := json.Marshal(a)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = json.UnmarshalUseNumber(b, l)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(l.FrontAll(), a)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var l List
|
||||
a := []interface{}{"a", "b", "c"}
|
||||
b, err := json.Marshal(a)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = json.UnmarshalUseNumber(b, &l)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(l.FrontAll(), a)
|
||||
})
|
||||
}
|
||||
@ -739,7 +739,7 @@ func TestList_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"list": []byte(`[1,2,3]`),
|
||||
}, &tlist)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(tlist.Name, "john")
|
||||
t.Assert(tlist.List.FrontAll(), []interface{}{1, 2, 3})
|
||||
})
|
||||
@ -750,7 +750,7 @@ func TestList_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"list": []interface{}{1, 2, 3},
|
||||
}, &tlist)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(tlist.Name, "john")
|
||||
t.Assert(tlist.List.FrontAll(), []interface{}{1, 2, 3})
|
||||
})
|
||||
|
@ -253,11 +253,11 @@ func Test_AnyAnyMap_Json(t *testing.T) {
|
||||
"k2": "v2",
|
||||
}
|
||||
b, err := json.Marshal(gconv.Map(data))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
m := gmap.New()
|
||||
err = json.UnmarshalUseNumber(b, m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get("k1"), data["k1"])
|
||||
t.Assert(m.Get("k2"), data["k2"])
|
||||
})
|
||||
@ -267,11 +267,11 @@ func Test_AnyAnyMap_Json(t *testing.T) {
|
||||
"k2": "v2",
|
||||
}
|
||||
b, err := json.Marshal(gconv.Map(data))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
var m gmap.Map
|
||||
err = json.UnmarshalUseNumber(b, &m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get("k1"), data["k1"])
|
||||
t.Assert(m.Get("k2"), data["k2"])
|
||||
})
|
||||
@ -342,7 +342,7 @@ func TestAnyAnyMap_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"map": []byte(`{"k1":"v1","k2":"v2"}`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get("k1"), "v1")
|
||||
@ -358,7 +358,7 @@ func TestAnyAnyMap_UnmarshalValue(t *testing.T) {
|
||||
"k2": "v2",
|
||||
},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get("k1"), "v1")
|
||||
|
@ -242,11 +242,11 @@ func Test_IntAnyMap_Json(t *testing.T) {
|
||||
2: "v2",
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
m := gmap.NewIntAnyMap()
|
||||
err = json.UnmarshalUseNumber(b, m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get(1), data[1])
|
||||
t.Assert(m.Get(2), data[2])
|
||||
})
|
||||
@ -317,7 +317,7 @@ func TestIntAnyMap_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"map": []byte(`{"1":"v1","2":"v2"}`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get(1), "v1")
|
||||
@ -333,7 +333,7 @@ func TestIntAnyMap_UnmarshalValue(t *testing.T) {
|
||||
2: "v2",
|
||||
},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get(1), "v1")
|
||||
|
@ -248,11 +248,11 @@ func Test_IntIntMap_Json(t *testing.T) {
|
||||
2: 20,
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
m := gmap.NewIntIntMap()
|
||||
err = json.UnmarshalUseNumber(b, m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get(1), data[1])
|
||||
t.Assert(m.Get(2), data[2])
|
||||
})
|
||||
@ -323,7 +323,7 @@ func TestIntIntMap_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"map": []byte(`{"1":1,"2":2}`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get(1), "1")
|
||||
@ -339,7 +339,7 @@ func TestIntIntMap_UnmarshalValue(t *testing.T) {
|
||||
2: 2,
|
||||
},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get(1), "1")
|
||||
|
@ -246,11 +246,11 @@ func Test_IntStrMap_Json(t *testing.T) {
|
||||
2: "v2",
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
m := gmap.NewIntStrMap()
|
||||
err = json.UnmarshalUseNumber(b, m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get(1), data[1])
|
||||
t.Assert(m.Get(2), data[2])
|
||||
})
|
||||
@ -321,7 +321,7 @@ func TestIntStrMap_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"map": []byte(`{"1":"v1","2":"v2"}`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get(1), "v1")
|
||||
@ -337,7 +337,7 @@ func TestIntStrMap_UnmarshalValue(t *testing.T) {
|
||||
2: "v2",
|
||||
},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get(1), "v1")
|
||||
|
@ -240,11 +240,11 @@ func Test_StrAnyMap_Json(t *testing.T) {
|
||||
"k2": "v2",
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
m := gmap.NewStrAnyMap()
|
||||
err = json.UnmarshalUseNumber(b, m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get("k1"), data["k1"])
|
||||
t.Assert(m.Get("k2"), data["k2"])
|
||||
})
|
||||
@ -254,11 +254,11 @@ func Test_StrAnyMap_Json(t *testing.T) {
|
||||
"k2": "v2",
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
var m gmap.StrAnyMap
|
||||
err = json.UnmarshalUseNumber(b, &m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get("k1"), data["k1"])
|
||||
t.Assert(m.Get("k2"), data["k2"])
|
||||
})
|
||||
@ -329,7 +329,7 @@ func TestStrAnyMap_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"map": []byte(`{"k1":"v1","k2":"v2"}`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get("k1"), "v1")
|
||||
@ -345,7 +345,7 @@ func TestStrAnyMap_UnmarshalValue(t *testing.T) {
|
||||
"k2": "v2",
|
||||
},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get("k1"), "v1")
|
||||
|
@ -244,11 +244,11 @@ func Test_StrIntMap_Json(t *testing.T) {
|
||||
"k2": 2,
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
m := gmap.NewStrIntMap()
|
||||
err = json.UnmarshalUseNumber(b, m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get("k1"), data["k1"])
|
||||
t.Assert(m.Get("k2"), data["k2"])
|
||||
})
|
||||
@ -258,11 +258,11 @@ func Test_StrIntMap_Json(t *testing.T) {
|
||||
"k2": 2,
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
var m gmap.StrIntMap
|
||||
err = json.UnmarshalUseNumber(b, &m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get("k1"), data["k1"])
|
||||
t.Assert(m.Get("k2"), data["k2"])
|
||||
})
|
||||
@ -333,7 +333,7 @@ func TestStrIntMap_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"map": []byte(`{"k1":1,"k2":2}`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get("k1"), 1)
|
||||
@ -349,7 +349,7 @@ func TestStrIntMap_UnmarshalValue(t *testing.T) {
|
||||
"k2": 2,
|
||||
},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get("k1"), 1)
|
||||
|
@ -241,11 +241,11 @@ func Test_StrStrMap_Json(t *testing.T) {
|
||||
"k2": "v2",
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
m := gmap.NewStrStrMap()
|
||||
err = json.UnmarshalUseNumber(b, m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get("k1"), data["k1"])
|
||||
t.Assert(m.Get("k2"), data["k2"])
|
||||
})
|
||||
@ -255,11 +255,11 @@ func Test_StrStrMap_Json(t *testing.T) {
|
||||
"k2": "v2",
|
||||
}
|
||||
b, err := json.Marshal(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
var m gmap.StrStrMap
|
||||
err = json.UnmarshalUseNumber(b, &m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get("k1"), data["k1"])
|
||||
t.Assert(m.Get("k2"), data["k2"])
|
||||
})
|
||||
@ -330,7 +330,7 @@ func TestStrStrMap_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"map": []byte(`{"k1":"v1","k2":"v2"}`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get("k1"), "v1")
|
||||
@ -346,7 +346,7 @@ func TestStrStrMap_UnmarshalValue(t *testing.T) {
|
||||
"k2": "v2",
|
||||
},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get("k1"), "v1")
|
||||
|
@ -201,11 +201,11 @@ func Test_ListMap_Json(t *testing.T) {
|
||||
"k2": "v2",
|
||||
}
|
||||
b, err := json.Marshal(gconv.Map(data))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
m := gmap.NewListMap()
|
||||
err = json.UnmarshalUseNumber(b, m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get("k1"), data["k1"])
|
||||
t.Assert(m.Get("k2"), data["k2"])
|
||||
})
|
||||
@ -216,11 +216,11 @@ func Test_ListMap_Json(t *testing.T) {
|
||||
"k2": "v2",
|
||||
}
|
||||
b, err := json.Marshal(gconv.Map(data))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
var m gmap.ListMap
|
||||
err = json.UnmarshalUseNumber(b, &m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get("k1"), data["k1"])
|
||||
t.Assert(m.Get("k2"), data["k2"])
|
||||
})
|
||||
@ -312,7 +312,7 @@ func TestListMap_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"map": []byte(`{"1":"v1","2":"v2"}`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get("1"), "v1")
|
||||
@ -328,7 +328,7 @@ func TestListMap_UnmarshalValue(t *testing.T) {
|
||||
2: "v2",
|
||||
},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get("1"), "v1")
|
||||
|
@ -185,11 +185,11 @@ func Test_TreeMap_Json(t *testing.T) {
|
||||
"k2": "v2",
|
||||
}
|
||||
b, err := json.Marshal(gconv.Map(data))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
m := gmap.NewTreeMap(gutil.ComparatorString)
|
||||
err = json.UnmarshalUseNumber(b, m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get("k1"), data["k1"])
|
||||
t.Assert(m.Get("k2"), data["k2"])
|
||||
})
|
||||
@ -199,11 +199,11 @@ func Test_TreeMap_Json(t *testing.T) {
|
||||
"k2": "v2",
|
||||
}
|
||||
b, err := json.Marshal(gconv.Map(data))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
var m gmap.TreeMap
|
||||
err = json.UnmarshalUseNumber(b, &m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m.Get("k1"), data["k1"])
|
||||
t.Assert(m.Get("k2"), data["k2"])
|
||||
})
|
||||
@ -221,7 +221,7 @@ func TestTreeMap_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"map": []byte(`{"k1":"v1","k2":"v2"}`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get("k1"), "v1")
|
||||
@ -237,7 +237,7 @@ func TestTreeMap_UnmarshalValue(t *testing.T) {
|
||||
"k2": "v2",
|
||||
},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Map.Size(), 2)
|
||||
t.Assert(v.Map.Get("k1"), "v1")
|
||||
|
@ -336,7 +336,7 @@ func TestSet_Json(t *testing.T) {
|
||||
|
||||
var a3 gset.Set
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Contains("a"), true)
|
||||
t.Assert(a3.Contains("b"), true)
|
||||
t.Assert(a3.Contains("c"), true)
|
||||
@ -438,7 +438,7 @@ func TestSet_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"set": []byte(`["k1","k2","k3"]`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Set.Size(), 3)
|
||||
t.Assert(v.Set.Contains("k1"), true)
|
||||
@ -453,7 +453,7 @@ func TestSet_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"set": g.Slice{"k1", "k2", "k3"},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Set.Size(), 3)
|
||||
t.Assert(v.Set.Contains("k1"), true)
|
||||
|
@ -368,7 +368,7 @@ func TestIntSet_Json(t *testing.T) {
|
||||
|
||||
var a3 gset.IntSet
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a2.Contains(1), true)
|
||||
t.Assert(a2.Contains(2), true)
|
||||
t.Assert(a2.Contains(3), true)
|
||||
@ -402,7 +402,7 @@ func TestIntSet_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"set": []byte(`[1,2,3]`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Set.Size(), 3)
|
||||
t.Assert(v.Set.Contains(1), true)
|
||||
@ -417,7 +417,7 @@ func TestIntSet_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"set": g.Slice{1, 2, 3},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Set.Size(), 3)
|
||||
t.Assert(v.Set.Contains(1), true)
|
||||
|
@ -414,7 +414,7 @@ func TestStrSet_Json(t *testing.T) {
|
||||
|
||||
var a3 gset.StrSet
|
||||
err := json.UnmarshalUseNumber(b2, &a3)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a3.Contains("a"), true)
|
||||
t.Assert(a3.Contains("b"), true)
|
||||
t.Assert(a3.Contains("c"), true)
|
||||
@ -453,7 +453,7 @@ func TestStrSet_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"set": []byte(`["1","2","3"]`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Set.Size(), 3)
|
||||
t.Assert(v.Set.Contains("1"), true)
|
||||
@ -468,7 +468,7 @@ func TestStrSet_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"set": g.SliceStr{"1", "2", "3"},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Set.Size(), 3)
|
||||
t.Assert(v.Set.Contains("1"), true)
|
||||
|
@ -56,16 +56,16 @@ func Test_Bool_JSON(t *testing.T) {
|
||||
var err error
|
||||
i := gtype.NewBool()
|
||||
err = json.UnmarshalUseNumber([]byte("true"), &i)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i.Val(), true)
|
||||
err = json.UnmarshalUseNumber([]byte("false"), &i)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i.Val(), false)
|
||||
err = json.UnmarshalUseNumber([]byte("1"), &i)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i.Val(), true)
|
||||
err = json.UnmarshalUseNumber([]byte("0"), &i)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i.Val(), false)
|
||||
})
|
||||
|
||||
@ -79,7 +79,7 @@ func Test_Bool_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.NewBool()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), i.Val())
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
@ -92,7 +92,7 @@ func Test_Bool_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.NewBool()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), i.Val())
|
||||
})
|
||||
}
|
||||
@ -108,7 +108,7 @@ func Test_Bool_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "true",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), true)
|
||||
})
|
||||
@ -118,7 +118,7 @@ func Test_Bool_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "false",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), false)
|
||||
})
|
||||
|
@ -54,7 +54,7 @@ func Test_Byte_JSON(t *testing.T) {
|
||||
var err error
|
||||
i := gtype.NewByte()
|
||||
err = json.UnmarshalUseNumber([]byte("49"), &i)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i.Val(), "49")
|
||||
})
|
||||
}
|
||||
@ -70,7 +70,7 @@ func Test_Byte_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "2",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), "2")
|
||||
})
|
||||
|
@ -40,7 +40,7 @@ func Test_Bytes_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.NewBytes()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), b)
|
||||
})
|
||||
}
|
||||
@ -56,7 +56,7 @@ func Test_Bytes_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "123",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), "123")
|
||||
})
|
||||
|
@ -42,7 +42,7 @@ func Test_Float32_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.NewFloat32()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), v)
|
||||
})
|
||||
}
|
||||
@ -58,7 +58,7 @@ func Test_Float32_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "123.456",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), "123.456")
|
||||
})
|
||||
|
@ -40,7 +40,7 @@ func Test_Float64_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.NewFloat64()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), v)
|
||||
})
|
||||
}
|
||||
@ -56,7 +56,7 @@ func Test_Float64_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "123.456",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), "123.456")
|
||||
})
|
||||
|
@ -53,7 +53,7 @@ func Test_Int32_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.NewInt32()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), v)
|
||||
})
|
||||
}
|
||||
@ -69,7 +69,7 @@ func Test_Int32_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "123",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), "123")
|
||||
})
|
||||
|
@ -52,7 +52,7 @@ func Test_Int64_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.NewInt64()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), i)
|
||||
})
|
||||
}
|
||||
@ -68,7 +68,7 @@ func Test_Int64_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "123",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), "123")
|
||||
})
|
||||
|
@ -52,7 +52,7 @@ func Test_Int_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.NewInt()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), v)
|
||||
})
|
||||
}
|
||||
@ -68,7 +68,7 @@ func Test_Int_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "123",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), "123")
|
||||
})
|
||||
|
@ -42,7 +42,7 @@ func Test_Interface_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.New()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), s)
|
||||
})
|
||||
}
|
||||
@ -58,7 +58,7 @@ func Test_Interface_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "123",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), "123")
|
||||
})
|
||||
|
@ -40,7 +40,7 @@ func Test_String_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.NewString()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), s)
|
||||
})
|
||||
}
|
||||
@ -56,7 +56,7 @@ func Test_String_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "123",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), "123")
|
||||
})
|
||||
|
@ -52,7 +52,7 @@ func Test_Uint32_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.NewUint32()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), i)
|
||||
})
|
||||
}
|
||||
@ -68,7 +68,7 @@ func Test_Uint32_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "123",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), "123")
|
||||
})
|
||||
|
@ -56,7 +56,7 @@ func Test_Uint64_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.NewUint64()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), i)
|
||||
})
|
||||
}
|
||||
@ -72,7 +72,7 @@ func Test_Uint64_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "123",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), "123")
|
||||
})
|
||||
|
@ -51,7 +51,7 @@ func Test_Uint_JSON(t *testing.T) {
|
||||
|
||||
i2 := gtype.NewUint()
|
||||
err := json.UnmarshalUseNumber(b2, &i2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(i2.Val(), i)
|
||||
})
|
||||
}
|
||||
@ -67,7 +67,7 @@ func Test_Uint_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "123",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.Val(), "123")
|
||||
})
|
||||
|
@ -253,7 +253,7 @@ func Test_UnmarshalJson(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "v",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.String(), "v")
|
||||
})
|
||||
@ -267,7 +267,7 @@ func Test_UnmarshalJson(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "v",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.String(), "v")
|
||||
})
|
||||
@ -284,7 +284,7 @@ func Test_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "v",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.String(), "v")
|
||||
})
|
||||
@ -298,7 +298,7 @@ func Test_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"var": "v",
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Var.String(), "v")
|
||||
})
|
||||
|
@ -40,10 +40,10 @@ func TestVar_Json(t *testing.T) {
|
||||
s := "i love gf"
|
||||
v := gvar.New(nil)
|
||||
b, err := json.Marshal(s)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = json.UnmarshalUseNumber(b, v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.String(), s)
|
||||
})
|
||||
|
||||
@ -51,10 +51,10 @@ func TestVar_Json(t *testing.T) {
|
||||
var v gvar.Var
|
||||
s := "i love gf"
|
||||
b, err := json.Marshal(s)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = json.UnmarshalUseNumber(b, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.String(), s)
|
||||
})
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func TestVar_Var_Attribute_Struct(t *testing.T) {
|
||||
"uid": gvar.New(1),
|
||||
"name": gvar.New("john"),
|
||||
}, user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Uid, 1)
|
||||
t.Assert(user.Name, "john")
|
||||
})
|
||||
@ -70,7 +70,7 @@ func TestVar_Var_Attribute_Struct(t *testing.T) {
|
||||
"uid": gvar.New(1),
|
||||
"name": gvar.New("john"),
|
||||
}, &user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user.Uid, 1)
|
||||
t.Assert(user.Name, "john")
|
||||
})
|
||||
|
@ -41,19 +41,19 @@ var (
|
||||
func TestEncrypt(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
data, err := gaes.Encrypt(content, key_16)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(data, []byte(content_16))
|
||||
data, err = gaes.Encrypt(content, key_24)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(data, []byte(content_24))
|
||||
data, err = gaes.Encrypt(content, key_32)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(data, []byte(content_32))
|
||||
data, err = gaes.Encrypt(content, key_16, iv)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(data, []byte(content_16_iv))
|
||||
data, err = gaes.Encrypt(content, key_32, iv)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(data, []byte(content_32_iv))
|
||||
})
|
||||
}
|
||||
@ -61,23 +61,23 @@ func TestEncrypt(t *testing.T) {
|
||||
func TestDecrypt(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
decrypt, err := gaes.Decrypt([]byte(content_16), key_16)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(decrypt, content)
|
||||
|
||||
decrypt, err = gaes.Decrypt([]byte(content_24), key_24)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(decrypt, content)
|
||||
|
||||
decrypt, err = gaes.Decrypt([]byte(content_32), key_32)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(decrypt, content)
|
||||
|
||||
decrypt, err = gaes.Decrypt([]byte(content_16_iv), key_16, iv)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(decrypt, content)
|
||||
|
||||
decrypt, err = gaes.Decrypt([]byte(content_32_iv), key_32, iv)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(decrypt, content)
|
||||
|
||||
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) {
|
||||
var padding int = 0
|
||||
data, err := gaes.EncryptCFB(content, key_16, &padding, iv)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(padding, padding_size)
|
||||
t.Assert(data, []byte(content_16_cfb))
|
||||
})
|
||||
@ -143,7 +143,7 @@ func TestEncryptCFB(t *testing.T) {
|
||||
func TestDecryptCFB(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
decrypt, err := gaes.DecryptCFB([]byte(content_16_cfb), key_16, padding_size, iv)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(decrypt, content)
|
||||
})
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ func TestEncryptFile(t *testing.T) {
|
||||
file, err := os.Create(path)
|
||||
defer os.Remove(path)
|
||||
defer file.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
_, _ = file.Write([]byte("Hello Go Frame"))
|
||||
encryptFile, _ := gmd5.EncryptFile(path)
|
||||
t.AssertEQ(encryptFile, result)
|
||||
|
@ -48,7 +48,7 @@ func TestEncryptFile(t *testing.T) {
|
||||
file, err := os.Create(path)
|
||||
defer os.Remove(path)
|
||||
defer file.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
_, _ = file.Write([]byte("Hello Go Frame"))
|
||||
encryptFile, _ := gsha1.EncryptFile(path)
|
||||
t.AssertEQ(encryptFile, result)
|
||||
|
@ -353,20 +353,20 @@ PRIMARY KEY (id)
|
||||
"id": i,
|
||||
"name": fmt.Sprintf(`name_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Detail.
|
||||
_, err = db.Insert(ctx, tableUserDetail, g.Map{
|
||||
"uid": i,
|
||||
"address": fmt.Sprintf(`address_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Scores.
|
||||
for j := 1; j <= 5; j++ {
|
||||
_, err = db.Insert(ctx, tableUserScores, g.Map{
|
||||
"uid": i,
|
||||
"score": j,
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -553,20 +553,20 @@ PRIMARY KEY (id)
|
||||
"id": i,
|
||||
"name": fmt.Sprintf(`name_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Detail.
|
||||
_, err = db.Insert(ctx, tableUserDetail, g.Map{
|
||||
"uid": i,
|
||||
"address": fmt.Sprintf(`address_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Scores.
|
||||
for j := 1; j <= 5; j++ {
|
||||
_, err = db.Insert(ctx, tableUserScores, g.Map{
|
||||
"uid": i,
|
||||
"score": j,
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
}
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
@ -668,20 +668,20 @@ PRIMARY KEY (id)
|
||||
"id": i,
|
||||
"name": fmt.Sprintf(`name_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Detail.
|
||||
_, err = db.Insert(ctx, tableUserDetail, g.Map{
|
||||
"uid": i,
|
||||
"address": fmt.Sprintf(`address_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Scores.
|
||||
for j := 1; j <= 5; j++ {
|
||||
_, err = db.Insert(ctx, tableUserScores, g.Map{
|
||||
"uid": i,
|
||||
"score": j,
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
}
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
@ -809,20 +809,20 @@ PRIMARY KEY (id)
|
||||
"id": i,
|
||||
"name": fmt.Sprintf(`name_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Detail.
|
||||
_, err = db.Insert(ctx, tableUserDetail, g.Map{
|
||||
"uid": i,
|
||||
"address": fmt.Sprintf(`address_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Scores.
|
||||
for j := 1; j <= 5; j++ {
|
||||
_, err = db.Insert(ctx, tableUserScores, g.Map{
|
||||
"uid": i,
|
||||
"score": j,
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -945,20 +945,20 @@ PRIMARY KEY (id)
|
||||
"id": i,
|
||||
"name": fmt.Sprintf(`name_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Detail.
|
||||
_, err = db.Insert(ctx, tableUserDetail, g.Map{
|
||||
"uid": i,
|
||||
"address": fmt.Sprintf(`address_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Scores.
|
||||
for j := 1; j <= 5; j++ {
|
||||
_, err = db.Insert(ctx, tableUserScores, g.Map{
|
||||
"uid": i,
|
||||
"score": j,
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
}
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
@ -1065,20 +1065,20 @@ PRIMARY KEY (id)
|
||||
"id": i,
|
||||
"name": fmt.Sprintf(`name_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Detail.
|
||||
_, err = db.Insert(ctx, tableUserDetail, g.Map{
|
||||
"uid": i,
|
||||
"address": fmt.Sprintf(`address_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Scores.
|
||||
for j := 1; j <= 5; j++ {
|
||||
_, err = db.Insert(ctx, tableUserScores, g.Map{
|
||||
"uid": i,
|
||||
"score": j,
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
}
|
||||
db.SetDebug(true)
|
||||
@ -1184,20 +1184,20 @@ PRIMARY KEY (id)
|
||||
"id": i,
|
||||
"name": fmt.Sprintf(`name_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Detail.
|
||||
_, err = db.Insert(ctx, tableUserDetail, g.Map{
|
||||
"uid": i,
|
||||
"address": fmt.Sprintf(`address_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Scores.
|
||||
for j := 1; j <= 5; j++ {
|
||||
_, err = db.Insert(ctx, tableUserScores, g.Map{
|
||||
"uid": i,
|
||||
"score": j,
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
}
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
@ -1299,20 +1299,20 @@ PRIMARY KEY (id)
|
||||
"id": i,
|
||||
"name": fmt.Sprintf(`name_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Detail.
|
||||
_, err = db.Insert(ctx, tableUserDetail, g.Map{
|
||||
"uid": i,
|
||||
"address": fmt.Sprintf(`address_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Scores.
|
||||
for j := 1; j <= 5; j++ {
|
||||
_, err = db.Insert(ctx, tableUserScores, g.Map{
|
||||
"uid": i,
|
||||
"score": j,
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1439,20 +1439,20 @@ PRIMARY KEY (id)
|
||||
"id": i,
|
||||
"name": fmt.Sprintf(`name_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Detail.
|
||||
_, err = db.Insert(ctx, tableUserDetail, g.Map{
|
||||
"uid": i,
|
||||
"address": fmt.Sprintf(`address_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Scores.
|
||||
for j := 1; j <= 5; j++ {
|
||||
_, err = db.Insert(ctx, tableUserScores, g.Map{
|
||||
"uid": i,
|
||||
"score": j,
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1585,20 +1585,20 @@ PRIMARY KEY (id)
|
||||
"id": i,
|
||||
"name": fmt.Sprintf(`name_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Detail.
|
||||
_, err = db.Insert(ctx, tableUserDetail, g.Map{
|
||||
"uid": i,
|
||||
"address": fmt.Sprintf(`address_%d`, i),
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
// Scores.
|
||||
for j := 1; j <= 5; j++ {
|
||||
_, err = db.Insert(ctx, tableUserScores, g.Map{
|
||||
"uid": i,
|
||||
"score": j,
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2067,7 +2067,7 @@ func Test_Model_OmitEmpty(t *testing.T) {
|
||||
"id": 1,
|
||||
"name": "",
|
||||
}).Save()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
}
|
||||
|
||||
@ -2096,14 +2096,14 @@ func Test_Model_OmitNil(t *testing.T) {
|
||||
"id": 1,
|
||||
"name": "",
|
||||
}).Save()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
_, err := db.Model(table).OmitNilWhere().Data(g.Map{
|
||||
"id": 1,
|
||||
"name": "",
|
||||
}).Save()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -30,11 +30,11 @@ func TestConn_DoWithTimeout(t *testing.T) {
|
||||
defer conn.Close(ctx)
|
||||
|
||||
_, err = conn.Do(ctx, "set", "test", "123")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Do(ctx, "del", "test")
|
||||
|
||||
r, err := conn.Do(ctx, "get", "test")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r.String(), "123")
|
||||
})
|
||||
}
|
||||
|
@ -46,16 +46,16 @@ func Test_Do(t *testing.T) {
|
||||
defer redis.Close(ctx)
|
||||
|
||||
_, err = redis.Do(ctx, "SET", "k", "v")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
r, err := redis.Do(ctx, "GET", "k")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r, []byte("v"))
|
||||
|
||||
_, err = redis.Do(ctx, "DEL", "k")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
r, err = redis.Do(ctx, "GET", "k")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r, nil)
|
||||
})
|
||||
}
|
||||
@ -74,16 +74,16 @@ func Test_Conn(t *testing.T) {
|
||||
key := gconv.String(gtime.TimestampNano())
|
||||
value := []byte("v")
|
||||
r, err := conn.Do(ctx, "SET", key, value)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
r, err = conn.Do(ctx, "GET", key)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r, value)
|
||||
|
||||
_, err = conn.Do(ctx, "DEL", key)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
r, err = conn.Do(ctx, "GET", key)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r, nil)
|
||||
})
|
||||
}
|
||||
@ -102,16 +102,16 @@ func Test_Instance(t *testing.T) {
|
||||
defer conn.Close(ctx)
|
||||
|
||||
_, err = conn.Do(ctx, "SET", "k", "v")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
r, err := conn.Do(ctx, "GET", "k")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r, []byte("v"))
|
||||
|
||||
_, err = conn.Do(ctx, "DEL", "k")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
r, err = conn.Do(ctx, "GET", "k")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r, nil)
|
||||
})
|
||||
}
|
||||
@ -153,10 +153,10 @@ func Test_Error(t *testing.T) {
|
||||
defer redis.Close(ctx)
|
||||
|
||||
_, err = redis.Do(ctx, "SET", "k", "v")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
v, err := redis.Do(ctx, "GET", "k")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.String(), "v")
|
||||
|
||||
conn, err := redis.Conn(ctx)
|
||||
@ -197,17 +197,17 @@ func Test_Bool(t *testing.T) {
|
||||
}()
|
||||
|
||||
_, err = redis.Do(ctx, "SET", "key-true", true)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
_, err = redis.Do(ctx, "SET", "key-false", false)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
r, err := redis.Do(ctx, "GET", "key-true")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r.Bool(), true)
|
||||
|
||||
r, err = redis.Do(ctx, "GET", "key-false")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r.Bool(), false)
|
||||
})
|
||||
}
|
||||
@ -223,10 +223,10 @@ func Test_Int(t *testing.T) {
|
||||
defer redis.Do(ctx, "DEL", key)
|
||||
|
||||
_, err = redis.Do(ctx, "SET", key, 1)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
r, err := redis.Do(ctx, "GET", key)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r.Int(), 1)
|
||||
})
|
||||
}
|
||||
@ -242,10 +242,10 @@ func Test_HSet(t *testing.T) {
|
||||
defer redis.Do(ctx, "DEL", key)
|
||||
|
||||
_, err = redis.Do(ctx, "HSET", key, "name", "john")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
r, err := redis.Do(ctx, "HGETALL", key)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r.Strings(), g.ArrayStr{"name", "john"})
|
||||
})
|
||||
}
|
||||
@ -262,12 +262,12 @@ func Test_HGetAll1(t *testing.T) {
|
||||
defer redis.Do(ctx, "DEL", key)
|
||||
|
||||
_, err = redis.Do(ctx, "HSET", key, "id", 100)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
_, err = redis.Do(ctx, "HSET", key, "name", "john")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
r, err := redis.Do(ctx, "HGETALL", key)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r.Map(), g.MapStrAny{
|
||||
"id": 100,
|
||||
"name": "john",
|
||||
@ -287,12 +287,12 @@ func Test_HGetAll2(t *testing.T) {
|
||||
defer redis.Do(ctx, "DEL", key)
|
||||
|
||||
_, err = redis.Do(ctx, "HSET", key, "id", 100)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
_, err = redis.Do(ctx, "HSET", key, "name", "john")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
result, err := redis.Do(ctx, "HGETALL", key)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gconv.Uint(result.MapStrVar()["id"]), 100)
|
||||
t.Assert(result.MapStrVar()["id"].Uint(), 100)
|
||||
@ -317,9 +317,9 @@ func Test_HMSet(t *testing.T) {
|
||||
defer redis.Do(ctx, "DEL", key)
|
||||
|
||||
_, 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")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Slice(), g.Slice{data["name"]})
|
||||
})
|
||||
// struct
|
||||
@ -344,9 +344,9 @@ func Test_HMSet(t *testing.T) {
|
||||
defer redis.Do(ctx, "DEL", key)
|
||||
|
||||
_, 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")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
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)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
r, err := redis.Do(ctx, "GET", key)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r.Map(), g.MapStrAny{
|
||||
"Id": user.Id,
|
||||
"Name": user.Name,
|
||||
@ -418,14 +418,14 @@ func Test_Auto_MarshalSlice(t *testing.T) {
|
||||
)
|
||||
|
||||
_, err = redis.Do(ctx, "SET", key, users1)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
result, err = redis.Do(ctx, "GET", key)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
var users2 []User
|
||||
err = result.Structs(&users2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(users2, users1)
|
||||
})
|
||||
}
|
||||
|
@ -70,12 +70,12 @@ func Test_File(t *testing.T) {
|
||||
expect := "dGVzdA=="
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
b, err := gbase64.EncodeFile(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(b), expect)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
s, err := gbase64.EncodeFileToString(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(s, expect)
|
||||
})
|
||||
}
|
||||
|
@ -50,13 +50,13 @@ func Test_Gzip_UnGzip_File(t *testing.T) {
|
||||
// Compress.
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
err := gcompress.GzipFile(srcPath, dstPath1, 9)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(dstPath1)
|
||||
t.Assert(gfile.Exists(dstPath1), true)
|
||||
|
||||
// Decompress.
|
||||
err = gcompress.UnGzipFile(dstPath1, dstPath2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(dstPath2)
|
||||
t.Assert(gfile.Exists(dstPath2), true)
|
||||
|
||||
|
@ -52,7 +52,7 @@ func Test_ZipPath(t *testing.T) {
|
||||
|
||||
t.Assert(gfile.Exists(dstPath), false)
|
||||
err := gcompress.ZipPath(srcPath1+","+srcPath2, dstPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(dstPath), true)
|
||||
defer gfile.Remove(dstPath)
|
||||
|
||||
@ -60,7 +60,7 @@ func Test_ZipPath(t *testing.T) {
|
||||
tempDirPath := gfile.Temp(gtime.TimestampNanoStr())
|
||||
t.Assert(gfile.Mkdir(tempDirPath), nil)
|
||||
err = gcompress.UnZipFile(dstPath, tempDirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(tempDirPath)
|
||||
|
||||
t.Assert(
|
||||
@ -85,7 +85,7 @@ func Test_ZipPath(t *testing.T) {
|
||||
|
||||
t.Assert(gfile.Exists(dstPath), false)
|
||||
err := gcompress.ZipPath(srcPath1+","+srcPath2, dstPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(dstPath), true)
|
||||
defer gfile.Remove(dstPath)
|
||||
|
||||
@ -93,7 +93,7 @@ func Test_ZipPath(t *testing.T) {
|
||||
tempDirPath := gfile.Temp(gtime.TimestampNanoStr())
|
||||
t.Assert(gfile.Mkdir(tempDirPath), nil)
|
||||
err = gcompress.UnZipFile(dstPath, tempDirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(tempDirPath)
|
||||
|
||||
t.Assert(
|
||||
@ -113,20 +113,20 @@ func Test_ZipPath(t *testing.T) {
|
||||
pwd := gfile.Pwd()
|
||||
err := gfile.Chdir(srcPath)
|
||||
defer gfile.Chdir(pwd)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gfile.Exists(dstPath), false)
|
||||
err = gcompress.ZipPath(srcPath, dstPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(dstPath), true)
|
||||
defer gfile.Remove(dstPath)
|
||||
|
||||
tempDirPath := gfile.Temp(gtime.TimestampNanoStr())
|
||||
err = gfile.Mkdir(tempDirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gcompress.UnZipFile(dstPath, tempDirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(tempDirPath)
|
||||
|
||||
t.Assert(
|
||||
@ -149,22 +149,22 @@ func Test_ZipPath(t *testing.T) {
|
||||
pwd := gfile.Pwd()
|
||||
err := gfile.Chdir(srcPath)
|
||||
defer gfile.Chdir(pwd)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gfile.Exists(dstPath), false)
|
||||
err = gcompress.ZipPath(srcPath1+", "+srcPath2, dstPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Exists(dstPath), true)
|
||||
defer gfile.Remove(dstPath)
|
||||
|
||||
tempDirPath := gfile.Temp(gtime.TimestampNanoStr())
|
||||
err = gfile.Mkdir(tempDirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
zipContent := gfile.GetBytes(dstPath)
|
||||
t.AssertGT(len(zipContent), 0)
|
||||
err = gcompress.UnZipContent(zipContent, tempDirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(tempDirPath)
|
||||
|
||||
t.Assert(
|
||||
@ -188,22 +188,22 @@ func Test_ZipPathWriter(t *testing.T) {
|
||||
pwd := gfile.Pwd()
|
||||
err := gfile.Chdir(srcPath)
|
||||
defer gfile.Chdir(pwd)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
writer := bytes.NewBuffer(nil)
|
||||
t.Assert(writer.Len(), 0)
|
||||
err = gcompress.ZipPathWriter(srcPath1+", "+srcPath2, writer)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertGT(writer.Len(), 0)
|
||||
|
||||
tempDirPath := gfile.Temp(gtime.TimestampNanoStr())
|
||||
err = gfile.Mkdir(tempDirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
zipContent := writer.Bytes()
|
||||
t.AssertGT(len(zipContent), 0)
|
||||
err = gcompress.UnZipContent(zipContent, tempDirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(tempDirPath)
|
||||
|
||||
t.Assert(
|
||||
|
@ -47,7 +47,7 @@ func Test_SpecialCharsMapOrStruct_Map(t *testing.T) {
|
||||
"Content": "<div>C</div>",
|
||||
}
|
||||
err := ghtml.SpecialCharsMapOrStruct(a)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a["Title"], `<h1>T</h1>`)
|
||||
t.Assert(a["Content"], `<div>C</div>`)
|
||||
})
|
||||
@ -57,7 +57,7 @@ func Test_SpecialCharsMapOrStruct_Map(t *testing.T) {
|
||||
"Content": "<div>C</div>",
|
||||
}
|
||||
err := ghtml.SpecialCharsMapOrStruct(a)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a["Title"], `<h1>T</h1>`)
|
||||
t.Assert(a["Content"], `<div>C</div>`)
|
||||
})
|
||||
@ -74,7 +74,7 @@ func Test_SpecialCharsMapOrStruct_Struct(t *testing.T) {
|
||||
Content: "<div>C</div>",
|
||||
}
|
||||
err := ghtml.SpecialCharsMapOrStruct(a)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(a.Title, `<h1>T</h1>`)
|
||||
t.Assert(a.Content, `<div>C</div>`)
|
||||
})
|
||||
|
@ -97,7 +97,7 @@ func TestToJson(t *testing.T) {
|
||||
}
|
||||
|
||||
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{})["port"], json.Get("addr.port").String())
|
||||
|
@ -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}`
|
||||
var info MediaRequestModifyInfo
|
||||
err := gjson.DecodeTo(jsonContent, &info)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
content := gjson.New(info).MustToJsonString()
|
||||
t.Assert(gstr.Contains(content, `"feed_id":""`), 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) {
|
||||
j, err := gjson.LoadContent(data)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
|
||||
tx := struct {
|
||||
Title map[string]interface{}
|
||||
}{}
|
||||
|
||||
err = j.Var().Scan(&tx)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
t.Assert(tx.Title, g.Map{
|
||||
"l1": "标签1", "l2": "标签2",
|
||||
})
|
||||
@ -76,14 +76,14 @@ func Test_MapAttributeConvert(t *testing.T) {
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.LoadContent(data)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
|
||||
tx := struct {
|
||||
Title map[string]string
|
||||
}{}
|
||||
|
||||
err = j.Var().Scan(&tx)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
t.Assert(tx.Title, g.Map{
|
||||
"l1": "标签1", "l2": "标签2",
|
||||
})
|
||||
|
@ -20,7 +20,7 @@ func Test_Load_JSON1(t *testing.T) {
|
||||
// JSON
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.LoadContent(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
|
||||
t.Assert(j.Get("m.k").String(), "v")
|
||||
@ -39,7 +39,7 @@ func Test_Load_JSON1(t *testing.T) {
|
||||
gfile.PutBytes(path, data)
|
||||
defer gfile.Remove(path)
|
||||
j, err := gjson.Load(path, true)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "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]}`)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.LoadContent(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789000000000000")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
|
||||
t.Assert(j.Get("m.k").String(), "v")
|
||||
@ -66,7 +66,7 @@ func Test_Load_XML(t *testing.T) {
|
||||
// XML
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
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.m").Map(), g.Map{"k": "v"})
|
||||
t.Assert(j.Get("doc.m.k").String(), "v")
|
||||
@ -76,7 +76,7 @@ func Test_Load_XML(t *testing.T) {
|
||||
// XML
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
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.m").Map(), g.Map{"k": "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)
|
||||
defer gfile.Remove(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.m").Map(), g.Map{"k": "v"})
|
||||
t.Assert(j.Get("doc.m.k").String(), "v")
|
||||
@ -116,7 +116,7 @@ func Test_Load_XML(t *testing.T) {
|
||||
<nworkOrderFrontXML/>
|
||||
</Output>`
|
||||
j, err := gjson.LoadContent(xml)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("Output.ipageIndex"), "2")
|
||||
t.Assert(j.Get("Output.itotalRecords"), "GF框架")
|
||||
})
|
||||
@ -135,7 +135,7 @@ m:
|
||||
// YAML
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.LoadContent(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
|
||||
t.Assert(j.Get("m.k").String(), "v")
|
||||
@ -145,7 +145,7 @@ m:
|
||||
// YAML
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.LoadYaml(data, true)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
|
||||
t.Assert(j.Get("m.k").String(), "v")
|
||||
@ -158,7 +158,7 @@ m:
|
||||
gfile.PutBytes(path, data)
|
||||
defer gfile.Remove(path)
|
||||
j, err := gjson.Load(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
|
||||
t.Assert(j.Get("m.k").String(), "v")
|
||||
@ -171,7 +171,7 @@ func Test_Load_YAML2(t *testing.T) {
|
||||
data := []byte("i : 123456789")
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.LoadContent(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("i"), "123456789")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
@ -192,7 +192,7 @@ n = 123456789
|
||||
// TOML
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.LoadContent(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
|
||||
t.Assert(j.Get("m.k").String(), "v")
|
||||
@ -202,7 +202,7 @@ n = 123456789
|
||||
// TOML
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.LoadToml(data, true)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
|
||||
t.Assert(j.Get("m.k").String(), "v")
|
||||
@ -215,7 +215,7 @@ n = 123456789
|
||||
gfile.PutBytes(path, data)
|
||||
defer gfile.Remove(path)
|
||||
j, err := gjson.Load(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
|
||||
t.Assert(j.Get("m.k").String(), "v")
|
||||
@ -228,7 +228,7 @@ func Test_Load_TOML2(t *testing.T) {
|
||||
data := []byte("i=123456789")
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.LoadContent(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("i"), "123456789")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
@ -247,11 +247,11 @@ func Test_Load_Basic(t *testing.T) {
|
||||
_, err = gjson.DecodeToJson(nil)
|
||||
t.AssertNE(err, nil)
|
||||
j, err = gjson.LoadContent(nil)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Interface(), nil)
|
||||
|
||||
j, err = gjson.LoadContent(`{"name": "gf"}`)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
j, err = gjson.LoadContent(`{"name": "gf"""}`)
|
||||
t.AssertNE(err, nil)
|
||||
|
@ -65,7 +65,7 @@ func Test_New_CustomStruct(t *testing.T) {
|
||||
t.AssertNE(j, nil)
|
||||
|
||||
s, err := j.ToJsonString()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(s == `{"Id":1,"Name":"john"}` || s == `{"Name":"john","Id":1}`, true)
|
||||
})
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ func Test_Set15(t *testing.T) {
|
||||
t.Assert(j.Set("k", "v"), nil)
|
||||
|
||||
s, err := j.ToJsonString()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(
|
||||
gstr.Contains(s, `"root":[{"k1":"v1"},{"k2":"v2"}`) ||
|
||||
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)
|
||||
|
||||
s, err := j.ToJsonString()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(
|
||||
gstr.Contains(s, `"processors":[{"set":{"0field":"2","0value":"1"}}]`) ||
|
||||
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)
|
||||
|
||||
s, err := j.ToJsonString()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
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.2.k2", "v2"), nil)
|
||||
s, err := j.ToJsonString()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
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.2.1.k2", "v2"), nil)
|
||||
s, err := j.ToJsonString()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
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.2", g.Map{"k3": "v3"}), nil)
|
||||
s, err := j.ToJsonString()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(gstr.InArray(
|
||||
g.SliceStr{
|
||||
`{"k1":"v1","k2":[1,20,{"k3":"v3"}]}`,
|
||||
|
@ -22,7 +22,7 @@ func Test_GetScan(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var user *User
|
||||
err := j.Get("1").Scan(&user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user, &User{
|
||||
Name: "smith",
|
||||
Score: 60,
|
||||
@ -31,7 +31,7 @@ func Test_GetScan(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var users []User
|
||||
err := j.Get(".").Scan(&users)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(users, []User{
|
||||
{
|
||||
Name: "john",
|
||||
@ -54,7 +54,7 @@ func Test_GetScanDeep(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var user *User
|
||||
err := j.Get("1").Scan(&user)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(user, &User{
|
||||
Name: "smith",
|
||||
Score: 60,
|
||||
@ -63,7 +63,7 @@ func Test_GetScanDeep(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var users []User
|
||||
err := j.Get(".").Scan(&users)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(users, []User{
|
||||
{
|
||||
Name: "john",
|
||||
@ -86,7 +86,7 @@ func Test_Scan1(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var users []User
|
||||
err := j.Var().Scan(&users)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(users, []User{
|
||||
{
|
||||
Name: "john",
|
||||
@ -109,7 +109,7 @@ func Test_Scan2(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var users []User
|
||||
err := j.Var().Scan(&users)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(users, []User{
|
||||
{
|
||||
Name: "john",
|
||||
@ -198,9 +198,9 @@ func Test_Struct1(t *testing.T) {
|
||||
}`
|
||||
data := new(UserCollectionAddReq)
|
||||
j, err := gjson.LoadJson(jsonContent, true)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
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)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("me.name").String(), "mikey")
|
||||
t.Assert(j.Get("items").String(), "")
|
||||
t.Assert(j.Get("items").Bool(), false)
|
||||
t.Assert(j.Get("items").Array(), nil)
|
||||
m := new(M)
|
||||
err = j.Scan(m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertNE(m.Me, nil)
|
||||
t.Assert(m.Me["day"], "20009")
|
||||
t.Assert(m.Items, nil)
|
||||
@ -289,10 +289,10 @@ func Test_Struct_Complicated(t *testing.T) {
|
||||
]
|
||||
}`
|
||||
j, err := gjson.LoadContent(jsonContent)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
var response = new(Response)
|
||||
err = j.Scan(response)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(response.CertList), 3)
|
||||
t.Assert(response.CertList[0].CertID, 2023313)
|
||||
t.Assert(response.CertList[1].CertID, 2023314)
|
||||
|
@ -24,7 +24,7 @@ func TestJson_UnmarshalJSON(t *testing.T) {
|
||||
j = gjson.New(nil)
|
||||
err = json.UnmarshalUseNumber(data, j)
|
||||
)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get(".").String(), `["a","b","c"]`)
|
||||
t.Assert(j.Get("2").String(), `c`)
|
||||
})
|
||||
@ -35,7 +35,7 @@ func TestJson_UnmarshalJSON(t *testing.T) {
|
||||
j = gjson.New(nil)
|
||||
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("2.c").String(), `3`)
|
||||
})
|
||||
@ -46,7 +46,7 @@ func TestJson_UnmarshalJSON(t *testing.T) {
|
||||
j = gjson.New(nil)
|
||||
err = json.UnmarshalUseNumber(data, j)
|
||||
)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
|
||||
t.Assert(j.Get("m.k").String(), "v")
|
||||
@ -68,7 +68,7 @@ func TestJson_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"json": []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`),
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Json.Get("n").String(), "123456789")
|
||||
t.Assert(v.Json.Get("m").Map(), g.Map{"k": "v"})
|
||||
@ -83,7 +83,7 @@ func TestJson_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"json": `["a", "b", "c"]`,
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Json.Get(".").String(), `["a","b","c"]`)
|
||||
t.Assert(v.Json.Get("2").String(), `c`)
|
||||
@ -95,7 +95,7 @@ func TestJson_UnmarshalValue(t *testing.T) {
|
||||
"name": "john",
|
||||
"json": `[{"a":1},{"b":2},{"c":3}]`,
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Json.Get(".").String(), `[{"a":1},{"b":2},{"c":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},
|
||||
},
|
||||
}, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v.Name, "john")
|
||||
t.Assert(v.Json.Get("n").String(), "123456789")
|
||||
t.Assert(v.Json.Get("m").Map(), g.Map{"k": "v"})
|
||||
|
@ -66,7 +66,7 @@ func Test_Encode(t *testing.T) {
|
||||
value := g.Slice{1, 2, 3}
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
b, err := gjson.Encode(value)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
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]}`)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
v, err := gjson.Decode(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v, g.Map{
|
||||
"n": 123456789,
|
||||
"a": g.Slice{1, 2, 3},
|
||||
@ -87,7 +87,7 @@ func Test_Decode(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
var v interface{}
|
||||
err := gjson.DecodeTo(data, &v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(v, g.Map{
|
||||
"n": 123456789,
|
||||
"a": g.Slice{1, 2, 3},
|
||||
@ -98,7 +98,7 @@ func Test_Decode(t *testing.T) {
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.DecodeToJson(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"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) {
|
||||
j, err := gjson.DecodeToJson(data)
|
||||
j.SetSplitChar(byte('#'))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "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"}}`)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
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.v1.v2"), nil)
|
||||
j.SetViolenceCheck(true)
|
||||
@ -137,7 +137,7 @@ func Test_GetVar(t *testing.T) {
|
||||
data := []byte(`{"n":123456789, "m":{"k":"v"}, "a":[1,2,3]}`)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.DecodeToJson(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").String(), "123456789")
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
|
||||
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]}`)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.DecodeToJson(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("n").Map(), nil)
|
||||
t.Assert(j.Get("m").Map(), g.Map{"k": "v"})
|
||||
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]}`)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.DecodeToJson(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
j2 := j.GetJson("m")
|
||||
t.AssertNE(j2, nil)
|
||||
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]}`)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
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("m").Array(), g.Array{g.Map{"k": "v"}})
|
||||
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]}`)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
j, err := gjson.DecodeToJson(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertEQ(j.Get("n").String(), "123456789")
|
||||
t.AssertEQ(j.Get("m").String(), `{"k":"v"}`)
|
||||
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]}`)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
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("m").Strings(), g.SliceStr{`{"k":"v"}`})
|
||||
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]}`)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
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("m").Interfaces(), g.Array{g.Map{"k": "v"}})
|
||||
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) {
|
||||
j := gjson.New(`{"name":"gf"}`)
|
||||
arr, err := j.ToXml()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(arr), "<name>gf</name>")
|
||||
arr, err = j.ToXmlIndent()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(arr), "<name>gf</name>")
|
||||
str, err := j.ToXmlString()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(str, "<name>gf</name>")
|
||||
str, err = j.ToXmlIndentString()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(str, "<name>gf</name>")
|
||||
|
||||
arr, err = j.ToJsonIndent()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(arr), "{\n\t\"name\": \"gf\"\n}")
|
||||
str, err = j.ToJsonIndentString()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(arr), "{\n\t\"name\": \"gf\"\n}")
|
||||
|
||||
arr, err = j.ToYaml()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(arr), "name: gf\n")
|
||||
str, err = j.ToYamlString()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(arr), "name: gf\n")
|
||||
|
||||
arr, err = j.ToToml()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(arr), "name = \"gf\"\n")
|
||||
str, err = j.ToTomlString()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
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")
|
||||
|
||||
err := j.Var().Scan(&name)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(name.Name, "gf")
|
||||
// j.Dump()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
j = gjson.New(`{"person":{"name":"gf"}}`)
|
||||
err = j.Get("person").Scan(&name)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(name.Name, "gf")
|
||||
|
||||
j = gjson.New(`{"name":"gf""}`)
|
||||
// j.Dump()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
j = gjson.New(`[1,2,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")
|
||||
|
||||
err := j.Set("name", "gf1")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("name"), "gf1")
|
||||
|
||||
j = gjson.New(`[1,2,3]`)
|
||||
err = j.Set("\"0\".1", 11)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("1"), 11)
|
||||
|
||||
j = gjson.New(`[1,2,3]`)
|
||||
@ -431,7 +431,7 @@ func Test_Basic(t *testing.T) {
|
||||
|
||||
j = gjson.New(`[1,2,3]`)
|
||||
err = j.Remove("1")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("0"), 1)
|
||||
t.Assert(len(j.Var().Array()), 2)
|
||||
|
||||
@ -445,18 +445,18 @@ func Test_Basic(t *testing.T) {
|
||||
|
||||
j = gjson.New(`[1,2,3]`)
|
||||
err = j.Remove("3")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("0"), 1)
|
||||
t.Assert(len(j.Var().Array()), 3)
|
||||
|
||||
j = gjson.New(`[1,2,3]`)
|
||||
err = j.Remove("0.3")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("0"), 1)
|
||||
|
||||
j = gjson.New(`[1,2,3]`)
|
||||
err = j.Remove("0.a")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("0"), 1)
|
||||
|
||||
name := struct {
|
||||
@ -465,35 +465,35 @@ func Test_Basic(t *testing.T) {
|
||||
j = gjson.New(name)
|
||||
t.Assert(j.Get("Name"), "gf")
|
||||
err = j.Remove("Name")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("Name"), nil)
|
||||
|
||||
err = j.Set("Name", "gf1")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("Name"), "gf1")
|
||||
|
||||
j = gjson.New(nil)
|
||||
err = j.Remove("Name")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("Name"), nil)
|
||||
|
||||
j = gjson.New(name)
|
||||
t.Assert(j.Get("Name"), "gf")
|
||||
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")
|
||||
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)
|
||||
err = j.Set("Name3", name)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("Name3").Interface().(g.Map)["Name"], "gf")
|
||||
err = j.Set("Name4", &name)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("Name4").Interface().(g.Map)["Name"], "gf")
|
||||
arr := [3]int{1, 2, 3}
|
||||
err = j.Set("Name5", arr)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(j.Get("Name5").Interface().(g.Array)[0], 1)
|
||||
|
||||
})
|
||||
|
@ -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>
|
||||
`
|
||||
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{})["password1"], "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>
|
||||
`
|
||||
m, err := gxml.DecodeWithoutRoot([]byte(content))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(m["username"], "johngcn")
|
||||
t.Assert(m["password1"], "123456")
|
||||
t.Assert(m["password2"], "123456")
|
||||
|
@ -74,7 +74,7 @@ func Test_EncodeIndent(t *testing.T) {
|
||||
func Test_Decode(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result, err := gyaml.Decode([]byte(yamlStr))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
m, ok := result.(map[string]interface{})
|
||||
t.Assert(ok, true)
|
||||
@ -92,7 +92,7 @@ func Test_DecodeTo(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
result := make(map[string]interface{})
|
||||
err := gyaml.DecodeTo([]byte(yamlStr), &result)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, map[string]interface{}{
|
||||
"url": "https://goframe.org",
|
||||
"server": g.Slice{"120.168.117.21", "120.168.117.22"},
|
||||
@ -121,9 +121,9 @@ m:
|
||||
k: v
|
||||
`)
|
||||
v, err := gyaml.Decode(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
b, err := json.Marshal(v)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(b, `{"m":{"k":"v"}}`)
|
||||
})
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ func Test_Next(t *testing.T) {
|
||||
t.Assert(err.Error(), "1")
|
||||
|
||||
err = gerror.Next(err)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -42,15 +42,15 @@ func Test_Config2(t *testing.T) {
|
||||
var err error
|
||||
dirPath := gfile.Temp(gtime.TimestampNanoStr())
|
||||
err = gfile.Mkdir(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(dirPath)
|
||||
|
||||
name := "config.toml"
|
||||
err = gfile.PutContents(gfile.Join(dirPath, name), configContent)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gins.Config().GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear()
|
||||
|
||||
@ -91,15 +91,15 @@ func Test_Config3(t *testing.T) {
|
||||
var err error
|
||||
dirPath := gfile.Temp(gtime.TimestampNanoStr())
|
||||
err = gfile.Mkdir(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(dirPath)
|
||||
|
||||
name := "test.toml"
|
||||
err = gfile.PutContents(gfile.Join(dirPath, name), configContent)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gins.Config("test").GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
defer gins.Config("test").GetAdapter().(*gcfg.AdapterFile).Clear()
|
||||
gins.Config("test").GetAdapter().(*gcfg.AdapterFile).SetFileName("test.toml")
|
||||
@ -115,15 +115,15 @@ func Test_Config3(t *testing.T) {
|
||||
var err error
|
||||
dirPath := gfile.Temp(gtime.TimestampNanoStr())
|
||||
err = gfile.Mkdir(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(dirPath)
|
||||
|
||||
name := "config/test.toml"
|
||||
err = gfile.PutContents(gfile.Join(dirPath, name), configContent)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gins.Config("test").GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
defer gins.Config("test").GetAdapter().(*gcfg.AdapterFile).Clear()
|
||||
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())
|
||||
file := fmt.Sprintf(`%s/%s`, path, "config.toml")
|
||||
err := gfile.PutContents(file, configContent)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(file)
|
||||
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())
|
||||
file := fmt.Sprintf(`%s/%s`, path, "config.toml")
|
||||
err := gfile.PutContents(file, configContent)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(file)
|
||||
defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear()
|
||||
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())
|
||||
file := fmt.Sprintf(`%s/%s`, path, "test.toml")
|
||||
err := gfile.PutContents(file, configContent)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(file)
|
||||
defer gins.Config("test").GetAdapter().(*gcfg.AdapterFile).Clear()
|
||||
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())
|
||||
file := fmt.Sprintf(`%s/%s`, path, "test.toml")
|
||||
err := gfile.PutContents(file, configContent)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(file)
|
||||
defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear()
|
||||
gins.Config("test").GetAdapter().(*gcfg.AdapterFile).SetFileName("test.toml")
|
||||
|
@ -26,15 +26,15 @@ func Test_Database(t *testing.T) {
|
||||
var err error
|
||||
dirPath := gfile.Temp(gtime.TimestampNanoStr())
|
||||
err = gfile.Mkdir(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(dirPath)
|
||||
|
||||
name := "config.toml"
|
||||
err = gfile.PutContents(gfile.Join(dirPath, name), databaseContent)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gins.Config().GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear()
|
||||
|
||||
|
@ -27,15 +27,15 @@ func Test_Redis(t *testing.T) {
|
||||
var err error
|
||||
dirPath := gfile.Temp(gtime.TimestampNanoStr())
|
||||
err = gfile.Mkdir(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(dirPath)
|
||||
|
||||
name := "config.toml"
|
||||
err = gfile.PutContents(gfile.Join(dirPath, name), redisContent)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gins.Config().GetAdapter().(*gcfg.AdapterFile).AddPath(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
defer gins.Config().GetAdapter().(*gcfg.AdapterFile).Clear()
|
||||
|
||||
@ -58,13 +58,13 @@ func Test_Redis(t *testing.T) {
|
||||
t.Assert(r, "PONG")
|
||||
|
||||
r, err = redisCache.Do(ctx, "PING")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r, "PONG")
|
||||
|
||||
_, err = redisDisk.Do(ctx, "SET", "k", "v")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
r, err = redisDisk.Do(ctx, "GET", "k")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r, []byte("v"))
|
||||
})
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ func Test_View(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
tpl := "t.tpl"
|
||||
err := gfile.PutContents(tpl, `{{"我是中国人" | substr 2 -1}}`)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(tpl)
|
||||
|
||||
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())
|
||||
tpl := fmt.Sprintf(`%s/%s`, path, "t.tpl")
|
||||
err := gfile.PutContents(tpl, `{{"我是中国人" | substr 2 -1}}`)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(tpl)
|
||||
err = View().AddPath(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
b, e := View().Parse(context.TODO(), "t.tpl", nil)
|
||||
t.Assert(e, nil)
|
||||
@ -61,16 +61,16 @@ func Test_View_Config(t *testing.T) {
|
||||
view := View("test1")
|
||||
t.AssertNE(view, nil)
|
||||
err := view.AddPath(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
str := `hello ${.name},version:${.version}`
|
||||
view.Assigns(map[string]interface{}{"version": "1.9.0"})
|
||||
result, err := view.ParseContent(context.TODO(), str, nil)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, "hello test1,version:1.9.0")
|
||||
|
||||
result, err = view.ParseDefault(context.TODO())
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, "test1:test1")
|
||||
})
|
||||
// view1 test2
|
||||
@ -83,16 +83,16 @@ func Test_View_Config(t *testing.T) {
|
||||
view := View("test2")
|
||||
t.AssertNE(view, nil)
|
||||
err := view.AddPath(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
str := `hello #{.name},version:#{.version}`
|
||||
view.Assigns(map[string]interface{}{"version": "1.9.0"})
|
||||
result, err := view.ParseContent(context.TODO(), str, nil)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, "hello test2,version:1.9.0")
|
||||
|
||||
result, err = view.ParseDefault(context.TODO())
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, "test2:test2")
|
||||
})
|
||||
// view2
|
||||
@ -105,16 +105,16 @@ func Test_View_Config(t *testing.T) {
|
||||
view := View()
|
||||
t.AssertNE(view, nil)
|
||||
err := view.AddPath(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
str := `hello {.name},version:{.version}`
|
||||
view.Assigns(map[string]interface{}{"version": "1.9.0"})
|
||||
result, err := view.ParseContent(context.TODO(), str, nil)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, "hello test,version:1.9.0")
|
||||
|
||||
result, err = view.ParseDefault(context.TODO())
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, "test:test")
|
||||
})
|
||||
// view2
|
||||
@ -127,16 +127,16 @@ func Test_View_Config(t *testing.T) {
|
||||
view := View("test100")
|
||||
t.AssertNE(view, nil)
|
||||
err := view.AddPath(dirPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
str := `hello {.name},version:{.version}`
|
||||
view.Assigns(map[string]interface{}{"version": "1.9.0"})
|
||||
result, err := view.ParseContent(context.TODO(), str, nil)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, "hello test,version:1.9.0")
|
||||
|
||||
result, err = view.ParseDefault(context.TODO())
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, "test:test")
|
||||
})
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func Test_TranslateFormat(t *testing.T) {
|
||||
func Test_DefaultManager(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
err := gi18n.SetPath(gdebug.TestDataPath("i18n"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
gi18n.SetLanguage("none")
|
||||
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) {
|
||||
err := gi18n.SetPath(gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n-dir")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
gi18n.SetLanguage("none")
|
||||
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) {
|
||||
m := gi18n.Instance()
|
||||
err := m.SetPath("i18n-dir")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
m.SetLanguage("zh-CN")
|
||||
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) {
|
||||
m := g.I18n("resource")
|
||||
err := m.SetPath("i18n-dir")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
m.SetLanguage("none")
|
||||
t.Assert(m.T(context.Background(), "{#hello}{#world}"), "{#hello}{#world}")
|
||||
|
@ -144,7 +144,7 @@ func Test_Client_Cookies(t *testing.T) {
|
||||
c.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
resp, err := c.Get(ctx, "/cookie")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer resp.Close()
|
||||
|
||||
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) {
|
||||
tmpPath := gfile.Temp(guid.S())
|
||||
err := gfile.Mkdir(tmpPath)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
defer gfile.Remove(tmpPath)
|
||||
|
||||
file := r.GetUploadFile("file")
|
||||
_, err = file.Save(tmpPath)
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
r.Response.Write(
|
||||
r.Get("json"),
|
||||
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, "/")
|
||||
t.Assert(str1, "acefdb")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp.ReadAllString(), str2)
|
||||
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)
|
||||
client := g.Client().SetPrefix(url).ContentJson()
|
||||
r, err := client.Post(ctx, "/hello", g.Map{"field": "test_for_request_body"})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
dumpedText := r.RawRequest()
|
||||
t.Assert(gstr.Contains(dumpedText, "test_for_request_body"), true)
|
||||
dumpedText2 := r.RawResponse()
|
||||
@ -482,7 +482,7 @@ func Test_Client_Request_13_Dump(t *testing.T) {
|
||||
|
||||
client2 := g.Client().SetPrefix(url).ContentType("text/html")
|
||||
r2, err := client2.Post(ctx, "/hello2", g.Map{"field": "test_for_request_body"})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
dumpedText3 := r2.RawRequest()
|
||||
t.Assert(gstr.Contains(dumpedText3, "test_for_request_body"), true)
|
||||
dumpedText4 := r2.RawResponse()
|
||||
@ -520,15 +520,15 @@ func Test_WebSocketClient(t *testing.T) {
|
||||
client.HandshakeTimeout = time.Minute
|
||||
|
||||
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()
|
||||
|
||||
msg := []byte("hello")
|
||||
err = conn.WriteMessage(websocket.TextMessage, msg)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
mt, data, err := conn.ReadMessage()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(mt, websocket.TextMessage)
|
||||
t.Assert(data, msg)
|
||||
})
|
||||
|
@ -34,7 +34,7 @@ func Test_ConfigFromMap(t *testing.T) {
|
||||
"cookieHttpOnly": true,
|
||||
}
|
||||
config, err := ghttp.ConfigFromMap(m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
d1, _ := time.ParseDuration(gconv.String(m["readTimeout"]))
|
||||
d2, _ := time.ParseDuration(gconv.String(m["cookieMaxAge"]))
|
||||
t.Assert(config.Address, m["address"])
|
||||
@ -67,7 +67,7 @@ func Test_SetConfigWithMap(t *testing.T) {
|
||||
}
|
||||
s := g.Server()
|
||||
err := s.SetConfigWithMap(m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ func Test_Middleware_Status(t *testing.T) {
|
||||
|
||||
resp, err := client.Get(ctx, "/")
|
||||
defer resp.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
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")
|
||||
// CORS Checks.
|
||||
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(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")
|
||||
|
@ -38,14 +38,14 @@ func Test_Middleware_CORS1(t *testing.T) {
|
||||
|
||||
// GET request does not any route.
|
||||
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(resp.StatusCode, 404)
|
||||
resp.Close()
|
||||
|
||||
// POST request matches the route and CORS middleware.
|
||||
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(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")
|
||||
@ -59,7 +59,7 @@ func Test_Middleware_CORS1(t *testing.T) {
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
|
||||
client.SetHeader("Access-Control-Request-Method", "GET")
|
||||
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(resp.ReadAllString(), "Not Found")
|
||||
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.SetHeader("Access-Control-Request-Method", "POST")
|
||||
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(resp.StatusCode, 200)
|
||||
resp.Close()
|
||||
@ -98,7 +98,7 @@ func Test_Middleware_CORS2(t *testing.T) {
|
||||
t.Assert(client.GetContent(ctx, "/api.v2"), "Not Found")
|
||||
// Get request.
|
||||
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(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")
|
||||
@ -113,7 +113,7 @@ func Test_Middleware_CORS2(t *testing.T) {
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
|
||||
client.SetHeader("Access-Control-Request-Method", "GET")
|
||||
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(resp.StatusCode, 404)
|
||||
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.SetHeader("Access-Control-Request-Method", "GET")
|
||||
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(resp.StatusCode, 200)
|
||||
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.SetHeader("Access-Control-Request-Method", "POST")
|
||||
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(resp.StatusCode, 404)
|
||||
resp.Close()
|
||||
|
@ -115,22 +115,22 @@ func Test_Router_Method(t *testing.T) {
|
||||
|
||||
resp1, err := client.Get(ctx, "/get")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp1.StatusCode, 200)
|
||||
|
||||
resp2, err := client.Post(ctx, "/get")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp2.StatusCode, 404)
|
||||
|
||||
resp3, err := client.Get(ctx, "/post")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp3.StatusCode, 404)
|
||||
|
||||
resp4, err := client.Post(ctx, "/post")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp4.StatusCode, 200)
|
||||
})
|
||||
}
|
||||
@ -187,27 +187,27 @@ func Test_Router_Status(t *testing.T) {
|
||||
|
||||
resp1, err := client.Get(ctx, "/200")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp1.StatusCode, 200)
|
||||
|
||||
resp2, err := client.Get(ctx, "/300")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp2.StatusCode, 300)
|
||||
|
||||
resp3, err := client.Get(ctx, "/400")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp3.StatusCode, 400)
|
||||
|
||||
resp4, err := client.Get(ctx, "/500")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp4.StatusCode, 500)
|
||||
|
||||
resp5, err := client.Get(ctx, "/404")
|
||||
defer resp5.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp5.StatusCode, 404)
|
||||
})
|
||||
}
|
||||
@ -232,7 +232,7 @@ func Test_Router_CustomStatusHandler(t *testing.T) {
|
||||
t.Assert(client.GetContent(ctx, "/"), "hello")
|
||||
resp, err := client.Get(ctx, "/ThisDoesNotExist")
|
||||
defer resp.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp.StatusCode, 404)
|
||||
t.Assert(resp.ReadAllString(), "404 page")
|
||||
})
|
||||
@ -256,7 +256,7 @@ func Test_Router_404(t *testing.T) {
|
||||
t.Assert(client.GetContent(ctx, "/"), "hello")
|
||||
resp, err := client.Get(ctx, "/ThisDoesNotExist")
|
||||
defer resp.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp.StatusCode, 404)
|
||||
})
|
||||
}
|
||||
|
@ -87,22 +87,22 @@ func Test_Router_DomainMethod(t *testing.T) {
|
||||
|
||||
resp1, err := client.Get(ctx, "/get")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp1.StatusCode, 404)
|
||||
|
||||
resp2, err := client.Post(ctx, "/get")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp2.StatusCode, 404)
|
||||
|
||||
resp3, err := client.Get(ctx, "/post")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp3.StatusCode, 404)
|
||||
|
||||
resp4, err := client.Post(ctx, "/post")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp4.StatusCode, 404)
|
||||
})
|
||||
|
||||
@ -112,22 +112,22 @@ func Test_Router_DomainMethod(t *testing.T) {
|
||||
|
||||
resp1, err := client.Get(ctx, "/get")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp1.StatusCode, 200)
|
||||
|
||||
resp2, err := client.Post(ctx, "/get")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp2.StatusCode, 404)
|
||||
|
||||
resp3, err := client.Get(ctx, "/post")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp3.StatusCode, 404)
|
||||
|
||||
resp4, err := client.Post(ctx, "/post")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp4.StatusCode, 200)
|
||||
})
|
||||
|
||||
@ -137,22 +137,22 @@ func Test_Router_DomainMethod(t *testing.T) {
|
||||
|
||||
resp1, err := client.Get(ctx, "/get")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp1.StatusCode, 200)
|
||||
|
||||
resp2, err := client.Post(ctx, "/get")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp2.StatusCode, 404)
|
||||
|
||||
resp3, err := client.Get(ctx, "/post")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp3.StatusCode, 404)
|
||||
|
||||
resp4, err := client.Post(ctx, "/post")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp4.StatusCode, 200)
|
||||
})
|
||||
}
|
||||
@ -183,22 +183,22 @@ func Test_Router_DomainStatus(t *testing.T) {
|
||||
|
||||
resp1, err := client.Get(ctx, "/200")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp1.StatusCode, 404)
|
||||
|
||||
resp2, err := client.Get(ctx, "/300")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp2.StatusCode, 404)
|
||||
|
||||
resp3, err := client.Get(ctx, "/400")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp3.StatusCode, 404)
|
||||
|
||||
resp4, err := client.Get(ctx, "/500")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp4.StatusCode, 404)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
@ -207,22 +207,22 @@ func Test_Router_DomainStatus(t *testing.T) {
|
||||
|
||||
resp1, err := client.Get(ctx, "/200")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp1.StatusCode, 200)
|
||||
|
||||
resp2, err := client.Get(ctx, "/300")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp2.StatusCode, 300)
|
||||
|
||||
resp3, err := client.Get(ctx, "/400")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp3.StatusCode, 400)
|
||||
|
||||
resp4, err := client.Get(ctx, "/500")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp4.StatusCode, 500)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
@ -231,22 +231,22 @@ func Test_Router_DomainStatus(t *testing.T) {
|
||||
|
||||
resp1, err := client.Get(ctx, "/200")
|
||||
defer resp1.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp1.StatusCode, 200)
|
||||
|
||||
resp2, err := client.Get(ctx, "/300")
|
||||
defer resp2.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp2.StatusCode, 300)
|
||||
|
||||
resp3, err := client.Get(ctx, "/400")
|
||||
defer resp3.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp3.StatusCode, 400)
|
||||
|
||||
resp4, err := client.Get(ctx, "/500")
|
||||
defer resp4.Close()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp4.StatusCode, 500)
|
||||
})
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ func Test_Router_DomainObjectRest(t *testing.T) {
|
||||
if err == nil {
|
||||
defer resp1.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp1.Header.Get("head-ok"), "")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
@ -96,7 +96,7 @@ func Test_Router_DomainObjectRest(t *testing.T) {
|
||||
if err == nil {
|
||||
defer resp1.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp1.Header.Get("head-ok"), "1")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
@ -114,7 +114,7 @@ func Test_Router_DomainObjectRest(t *testing.T) {
|
||||
if err == nil {
|
||||
defer resp1.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp1.Header.Get("head-ok"), "1")
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
})
|
||||
|
@ -80,7 +80,7 @@ func Test_Router_GroupRest1(t *testing.T) {
|
||||
if err == nil {
|
||||
defer resp2.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp2.Header.Get("head-ok"), "1")
|
||||
|
||||
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 {
|
||||
defer resp4.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp4.Header.Get("head-ok"), "1")
|
||||
})
|
||||
}
|
||||
@ -125,7 +125,7 @@ func Test_Router_GroupRest2(t *testing.T) {
|
||||
if err == nil {
|
||||
defer resp2.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp2.Header.Get("head-ok"), "1")
|
||||
|
||||
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 {
|
||||
defer resp4.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp4.Header.Get("head-ok"), "1")
|
||||
})
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ func Test_Router_ObjectRest(t *testing.T) {
|
||||
if err == nil {
|
||||
defer resp1.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp1.Header.Get("head-ok"), "1")
|
||||
|
||||
t.Assert(client.GetContent(ctx, "/object-rest/get"), "1Object Get2")
|
||||
@ -91,7 +91,7 @@ func Test_Router_ObjectRest(t *testing.T) {
|
||||
if err == nil {
|
||||
defer resp2.Close()
|
||||
}
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resp2.Header.Get("head-ok"), "1")
|
||||
|
||||
t.Assert(client.GetContent(ctx, "/none-exist"), "Not Found")
|
||||
|
@ -179,7 +179,7 @@ func Test_Session_Custom_Id(t *testing.T) {
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", s.GetListenedPort()))
|
||||
r, err := client.Get(ctx, "/id")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer r.Close()
|
||||
t.Assert(r.ReadAllString(), sessionId)
|
||||
t.Assert(r.GetCookie(s.GetSessionIdName()), sessionId)
|
||||
|
@ -31,7 +31,7 @@ func Test_Template_Basic(t *testing.T) {
|
||||
err := r.Response.WriteTpl("index.html", g.Map{
|
||||
"name": "john",
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
s.SetDumpRouterMap(false)
|
||||
s.Start()
|
||||
@ -55,7 +55,7 @@ func Test_Template_Encode(t *testing.T) {
|
||||
err := r.Response.WriteTpl("index.html", g.Map{
|
||||
"name": "john",
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
s.SetDumpRouterMap(false)
|
||||
s.Start()
|
||||
@ -78,11 +78,11 @@ func Test_Template_Layout1(t *testing.T) {
|
||||
err := r.Response.WriteTpl("layout.html", g.Map{
|
||||
"mainTpl": "main/main1.html",
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
s.BindHandler("/nil", func(r *ghttp.Request) {
|
||||
err := r.Response.WriteTpl("layout.html", nil)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
s.SetDumpRouterMap(false)
|
||||
s.Start()
|
||||
@ -106,17 +106,17 @@ func Test_Template_Layout2(t *testing.T) {
|
||||
err := r.Response.WriteTpl("layout.html", g.Map{
|
||||
"mainTpl": "main/main1.html",
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
s.BindHandler("/main2", func(r *ghttp.Request) {
|
||||
err := r.Response.WriteTpl("layout.html", g.Map{
|
||||
"mainTpl": "main/main2.html",
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
s.BindHandler("/nil", func(r *ghttp.Request) {
|
||||
err := r.Response.WriteTpl("layout.html", nil)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
s.SetDumpRouterMap(false)
|
||||
s.Start()
|
||||
@ -137,7 +137,7 @@ func Test_Template_BuildInVarRequest(t *testing.T) {
|
||||
s := g.Server(guid.S())
|
||||
s.BindHandler("/:table/test", func(r *ghttp.Request) {
|
||||
err := r.Response.WriteTplContent("{{.Request.table}}")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
s.SetDumpRouterMap(false)
|
||||
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{
|
||||
"v": c,
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
s.SetDumpRouterMap(false)
|
||||
s.Start()
|
||||
|
@ -44,15 +44,15 @@ func Test_WebSocket(t *testing.T) {
|
||||
conn, _, err := websocket.DefaultDialer.Dial(fmt.Sprintf(
|
||||
"ws://127.0.0.1:%d/ws", s.GetListenedPort(),
|
||||
), nil)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
|
||||
msg := []byte("hello")
|
||||
err = conn.WriteMessage(websocket.TextMessage, msg)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
mt, data, err := conn.ReadMessage()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(mt, websocket.TextMessage)
|
||||
t.Assert(data, msg)
|
||||
})
|
||||
|
@ -34,21 +34,21 @@ func Test_Package_Basic(t *testing.T) {
|
||||
// SendPkg
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
for i := 0; i < 100; i++ {
|
||||
err := conn.SendPkg([]byte(gconv.String(i)))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
}
|
||||
for i := 0; i < 100; i++ {
|
||||
err := conn.SendPkgWithTimeout([]byte(gconv.String(i)), time.Second)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
}
|
||||
})
|
||||
// SendPkg with big data - failure.
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := make([]byte, 65536)
|
||||
err = conn.SendPkg(data)
|
||||
@ -57,25 +57,25 @@ func Test_Package_Basic(t *testing.T) {
|
||||
// SendRecvPkg
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
for i := 100; i < 200; i++ {
|
||||
data := []byte(gconv.String(i))
|
||||
result, err := conn.SendRecvPkg(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, data)
|
||||
}
|
||||
for i := 100; i < 200; i++ {
|
||||
data := []byte(gconv.String(i))
|
||||
result, err := conn.SendRecvPkgWithTimeout(data, time.Second)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, data)
|
||||
}
|
||||
})
|
||||
// SendRecvPkg with big data - failure.
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := make([]byte, 65536)
|
||||
result, err := conn.SendRecvPkg(data)
|
||||
@ -85,13 +85,13 @@ func Test_Package_Basic(t *testing.T) {
|
||||
// SendRecvPkg with big data - success.
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := make([]byte, 65500)
|
||||
data[100] = byte(65)
|
||||
data[65400] = byte(85)
|
||||
result, err := conn.SendRecvPkg(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, data)
|
||||
})
|
||||
}
|
||||
@ -114,7 +114,7 @@ func Test_Package_Timeout(t *testing.T) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := []byte("10000")
|
||||
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) {
|
||||
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := []byte("10000")
|
||||
result, err := conn.SendRecvPkgWithTimeout(data, time.Second*2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, data)
|
||||
})
|
||||
}
|
||||
@ -151,7 +151,7 @@ func Test_Package_Option(t *testing.T) {
|
||||
// SendRecvPkg with big data - failure.
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := make([]byte, 0xFF+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.
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := make([]byte, 0xFF)
|
||||
data[100] = byte(65)
|
||||
data[200] = byte(85)
|
||||
result, err := conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 1})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, data)
|
||||
})
|
||||
}
|
||||
|
@ -34,21 +34,21 @@ func Test_Pool_Package_Basic(t *testing.T) {
|
||||
// SendPkg
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
for i := 0; i < 100; i++ {
|
||||
err := conn.SendPkg([]byte(gconv.String(i)))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
}
|
||||
for i := 0; i < 100; i++ {
|
||||
err := conn.SendPkgWithTimeout([]byte(gconv.String(i)), time.Second)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
}
|
||||
})
|
||||
// SendPkg with big data - failure.
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := make([]byte, 65536)
|
||||
err = conn.SendPkg(data)
|
||||
@ -57,25 +57,25 @@ func Test_Pool_Package_Basic(t *testing.T) {
|
||||
// SendRecvPkg
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
for i := 100; i < 200; i++ {
|
||||
data := []byte(gconv.String(i))
|
||||
result, err := conn.SendRecvPkg(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, data)
|
||||
}
|
||||
for i := 100; i < 200; i++ {
|
||||
data := []byte(gconv.String(i))
|
||||
result, err := conn.SendRecvPkgWithTimeout(data, time.Second)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, data)
|
||||
}
|
||||
})
|
||||
// SendRecvPkg with big data - failure.
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := make([]byte, 65536)
|
||||
result, err := conn.SendRecvPkg(data)
|
||||
@ -85,13 +85,13 @@ func Test_Pool_Package_Basic(t *testing.T) {
|
||||
// SendRecvPkg with big data - success.
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := make([]byte, 65500)
|
||||
data[100] = byte(65)
|
||||
data[65400] = byte(85)
|
||||
result, err := conn.SendRecvPkg(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, data)
|
||||
})
|
||||
}
|
||||
@ -114,7 +114,7 @@ func Test_Pool_Package_Timeout(t *testing.T) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := []byte("10000")
|
||||
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) {
|
||||
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := []byte("10000")
|
||||
result, err := conn.SendRecvPkgWithTimeout(data, time.Second*2)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, data)
|
||||
})
|
||||
}
|
||||
@ -151,7 +151,7 @@ func Test_Pool_Package_Option(t *testing.T) {
|
||||
// SendRecvPkg with big data - failure.
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := make([]byte, 0xFF+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.
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := make([]byte, 0xFF)
|
||||
data[100] = byte(65)
|
||||
data[200] = byte(85)
|
||||
result, err := conn.SendRecvPkg(data, gtcp.PkgOption{HeaderSize: 1})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, data)
|
||||
})
|
||||
}
|
||||
|
@ -32,13 +32,13 @@ func Test_Pool_Basic1(t *testing.T) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := []byte("9999")
|
||||
err = conn.SendPkg(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
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)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
conn, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:%d", p))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer conn.Close()
|
||||
data := []byte("9999")
|
||||
err = conn.SendPkg(data)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
//err = conn.SendPkgWithTimeout(data, time.Second)
|
||||
//t.Assert(err, nil)
|
||||
//t.AssertNil(err)
|
||||
|
||||
_, err = conn.SendRecv(data, -1)
|
||||
t.AssertNE(err, nil)
|
||||
|
@ -44,7 +44,7 @@ func Test_Basic(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
for i := 0; i < 100; i++ {
|
||||
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)
|
||||
conn.Close()
|
||||
}
|
||||
@ -53,9 +53,9 @@ func Test_Basic(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
for i := 0; i < 100; i++ {
|
||||
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)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
//t.Assert(string(result), fmt.Sprintf(`> %d`, i))
|
||||
conn.Close()
|
||||
}
|
||||
@ -64,14 +64,14 @@ func Test_Basic(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
for i := 0; i < 100; 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
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
for i := 0; i < 100; i++ {
|
||||
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))
|
||||
}
|
||||
})
|
||||
@ -103,12 +103,12 @@ func Test_Buffer(t *testing.T) {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
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")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
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")
|
||||
})
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ func Test_SetFileName(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
path := "config.json"
|
||||
err := gfile.PutContents(path, config)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer func() {
|
||||
_ = gfile.Remove(path)
|
||||
}()
|
||||
@ -155,18 +155,18 @@ func TestCfg_Get_WrongConfigFile(t *testing.T) {
|
||||
var err error
|
||||
configPath := gfile.Temp(gtime.TimestampNanoStr())
|
||||
err = gfile.Mkdir(configPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(configPath)
|
||||
|
||||
defer gfile.Chdir(gfile.Pwd())
|
||||
err = gfile.Chdir(configPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gfile.PutContents(
|
||||
gfile.Join(configPath, "config.yml"),
|
||||
"wrong config",
|
||||
)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
adapterFile, err := gcfg.NewAdapterFile("config.yml")
|
||||
t.AssertNil(err)
|
||||
|
||||
|
@ -25,7 +25,7 @@ func Test_Parse(t *testing.T) {
|
||||
"f,force": false,
|
||||
"q,quiet": false,
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(p.GetArgAll()), 3)
|
||||
t.Assert(p.GetArg(0), "gf")
|
||||
t.Assert(p.GetArg(1), "remove")
|
||||
@ -64,7 +64,7 @@ func Test_ParseArgs(t *testing.T) {
|
||||
"f,force": false,
|
||||
"q,quiet": false,
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(p.GetArgAll()), 3)
|
||||
t.Assert(p.GetArg(0), "gf")
|
||||
t.Assert(p.GetArg(1), "remove")
|
||||
|
@ -29,7 +29,7 @@ func Test_GEnv_Map(t *testing.T) {
|
||||
value := gconv.String(gtime.TimestampNano())
|
||||
key := "TEST_ENV_" + value
|
||||
err := os.Setenv(key, "TEST")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(genv.Map()[key], "TEST")
|
||||
})
|
||||
}
|
||||
@ -39,7 +39,7 @@ func Test_GEnv_Get(t *testing.T) {
|
||||
value := gconv.String(gtime.TimestampNano())
|
||||
key := "TEST_ENV_" + value
|
||||
err := os.Setenv(key, "TEST")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertEQ(genv.Get(key).String(), "TEST")
|
||||
})
|
||||
}
|
||||
@ -49,7 +49,7 @@ func Test_GEnv_GetVar(t *testing.T) {
|
||||
value := gconv.String(gtime.TimestampNano())
|
||||
key := "TEST_ENV_" + value
|
||||
err := os.Setenv(key, "TEST")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertEQ(genv.Get(key).String(), "TEST")
|
||||
})
|
||||
}
|
||||
@ -59,7 +59,7 @@ func Test_GEnv_Contains(t *testing.T) {
|
||||
value := gconv.String(gtime.TimestampNano())
|
||||
key := "TEST_ENV_" + value
|
||||
err := os.Setenv(key, "TEST")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertEQ(genv.Contains(key), true)
|
||||
t.AssertEQ(genv.Contains("none"), false)
|
||||
})
|
||||
@ -70,7 +70,7 @@ func Test_GEnv_Set(t *testing.T) {
|
||||
value := gconv.String(gtime.TimestampNano())
|
||||
key := "TEST_ENV_" + value
|
||||
err := genv.Set(key, "TEST")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertEQ(os.Getenv(key), "TEST")
|
||||
})
|
||||
}
|
||||
@ -81,7 +81,7 @@ func Test_GEnv_SetMap(t *testing.T) {
|
||||
"K1": "TEST1",
|
||||
"K2": "TEST2",
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertEQ(os.Getenv("K1"), "TEST1")
|
||||
t.AssertEQ(os.Getenv("K2"), "TEST2")
|
||||
})
|
||||
@ -102,9 +102,9 @@ func Test_GEnv_Remove(t *testing.T) {
|
||||
value := gconv.String(gtime.TimestampNano())
|
||||
key := "TEST_ENV_" + value
|
||||
err := os.Setenv(key, "TEST")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
err = genv.Remove(key)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertEQ(os.Getenv(key), "")
|
||||
})
|
||||
}
|
||||
|
@ -100,10 +100,10 @@ func Test_Truncate(t *testing.T) {
|
||||
createTestFile(filepaths1, "abcdefghijkmln")
|
||||
defer delTestFiles(filepaths1)
|
||||
err = gfile.Truncate(testpath()+filepaths1, 10)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
files, err = os.Open(testpath() + filepaths1)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer files.Close()
|
||||
fileinfo, err2 := files.Stat()
|
||||
t.Assert(err2, nil)
|
||||
@ -126,10 +126,10 @@ func Test_PutContents(t *testing.T) {
|
||||
defer delTestFiles(filepaths)
|
||||
|
||||
err = gfile.PutContents(testpath()+filepaths, "test!")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
readcontent, err = ioutil.ReadFile(testpath() + filepaths)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(readcontent), "test!")
|
||||
|
||||
err = gfile.PutContents("", "test!")
|
||||
@ -149,10 +149,10 @@ func Test_PutContentsAppend(t *testing.T) {
|
||||
createTestFile(filepaths, "a")
|
||||
defer delTestFiles(filepaths)
|
||||
err = gfile.PutContentsAppend(testpath()+filepaths, "hello")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
readcontent, err = ioutil.ReadFile(testpath() + filepaths)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(readcontent), "ahello")
|
||||
|
||||
err = gfile.PutContentsAppend("", "hello")
|
||||
@ -173,10 +173,10 @@ func Test_PutBinContents(t *testing.T) {
|
||||
defer delTestFiles(filepaths)
|
||||
|
||||
err = gfile.PutBytes(testpath()+filepaths, []byte("test!!"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
readcontent, err = ioutil.ReadFile(testpath() + filepaths)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(readcontent), "test!!")
|
||||
|
||||
err = gfile.PutBytes("", []byte("test!!"))
|
||||
@ -195,10 +195,10 @@ func Test_PutBinContentsAppend(t *testing.T) {
|
||||
createTestFile(filepaths, "test!!")
|
||||
defer delTestFiles(filepaths)
|
||||
err = gfile.PutBytesAppend(testpath()+filepaths, []byte("word"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
readcontent, err = ioutil.ReadFile(testpath() + filepaths)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(readcontent), "test!!word")
|
||||
|
||||
err = gfile.PutBytesAppend("", []byte("word"))
|
||||
@ -324,7 +324,7 @@ func Test_Home(t *testing.T) {
|
||||
)
|
||||
|
||||
reads, err = gfile.Home("a", "b")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertNE(reads, "")
|
||||
})
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ func Test_CopyDir(t *testing.T) {
|
||||
t.Assert(gfile.GetContents(dst), dstContent)
|
||||
|
||||
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(dst), srcContent)
|
||||
|
||||
|
@ -19,14 +19,14 @@ func Test_ScanDir(t *testing.T) {
|
||||
teatPath := gdebug.TestDataPath()
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
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+"dir2", files)
|
||||
t.AssertNE(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
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+"dir2", files)
|
||||
t.AssertIN(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files)
|
||||
@ -43,7 +43,7 @@ func Test_ScanDirFunc(t *testing.T) {
|
||||
}
|
||||
return path
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(files), 1)
|
||||
t.Assert(gfile.Name(files[0]), "file1")
|
||||
})
|
||||
@ -53,12 +53,12 @@ func Test_ScanDirFile(t *testing.T) {
|
||||
teatPath := gdebug.TestDataPath()
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
files, err := gfile.ScanDirFile(teatPath, "*", false)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(files), 0)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
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+"dir2", files)
|
||||
t.AssertIN(teatPath+gfile.Separator+"dir1"+gfile.Separator+"file1", files)
|
||||
@ -74,7 +74,7 @@ func Test_ScanDirFileFunc(t *testing.T) {
|
||||
array.Append(1)
|
||||
return path
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(files), 0)
|
||||
t.Assert(array.Len(), 0)
|
||||
})
|
||||
@ -87,7 +87,7 @@ func Test_ScanDirFileFunc(t *testing.T) {
|
||||
}
|
||||
return ""
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(files), 1)
|
||||
t.Assert(array.Len(), 3)
|
||||
})
|
||||
|
@ -31,13 +31,13 @@ func Test_Search(t *testing.T) {
|
||||
ypaths1 = paths1
|
||||
|
||||
tpath, err = gfile.Search(testpath() + paths1)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
tpath = filepath.ToSlash(tpath)
|
||||
|
||||
// 自定义优先路径
|
||||
tpath2, err = gfile.Search(testpath() + paths1)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
tpath2 = filepath.ToSlash(tpath2)
|
||||
|
||||
tempstr = testpath()
|
||||
|
@ -69,7 +69,7 @@ func Test_Create(t *testing.T) {
|
||||
fileobj, err = gfile.Create(testpath() + v)
|
||||
defer delTestFiles(v)
|
||||
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.Close()
|
||||
if flags[k] {
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
} else {
|
||||
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.Close()
|
||||
if flags[k] {
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
} else {
|
||||
t.AssertNE(err, nil)
|
||||
}
|
||||
@ -162,7 +162,7 @@ func Test_OpenWithFlag(t *testing.T) {
|
||||
fileobj, err = gfile.OpenWithFlag(testpath()+v, os.O_RDWR)
|
||||
fileobj.Close()
|
||||
if flags[k] {
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
} else {
|
||||
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.Close()
|
||||
if flags[k] {
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
} else {
|
||||
t.AssertNE(err, nil)
|
||||
}
|
||||
@ -238,7 +238,7 @@ func Test_Exists(t *testing.T) {
|
||||
func Test_Pwd(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
paths, err := os.Getwd()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(gfile.Pwd(), paths)
|
||||
|
||||
})
|
||||
@ -292,10 +292,10 @@ func Test_Info(t *testing.T) {
|
||||
createTestFile(paths, "")
|
||||
defer delTestFiles(paths)
|
||||
files, err = gfile.Stat(testpath() + paths)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
files2, err = os.Stat(testpath() + paths)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(files, files2)
|
||||
|
||||
@ -370,7 +370,7 @@ func Test_DirNames(t *testing.T) {
|
||||
|
||||
readlist, err = gfile.DirNames(testpath() + paths)
|
||||
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertIN(readlist, havelist)
|
||||
|
||||
_, err = gfile.DirNames("")
|
||||
@ -406,16 +406,16 @@ func Test_Glob(t *testing.T) {
|
||||
defer delTestFiles(dirpath)
|
||||
|
||||
resultlist, err = gfile.Glob(testpath()+paths, true)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(resultlist, havelist1)
|
||||
|
||||
resultlist, err = gfile.Glob(testpath()+paths, false)
|
||||
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(formatpaths(resultlist), formatpaths(havelist2))
|
||||
|
||||
_, err = gfile.Glob("", true)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
})
|
||||
}
|
||||
@ -628,13 +628,13 @@ func Test_Mkdir(t *testing.T) {
|
||||
defer delTestFiles("/testfile")
|
||||
|
||||
err = gfile.Mkdir(testpath() + tpath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gfile.Mkdir("")
|
||||
t.AssertNE(err, nil)
|
||||
|
||||
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)
|
||||
|
||||
fileiofo, err = gfile.Stat(testpath() + tpath1)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(fileiofo.Size(), 1)
|
||||
|
||||
|
@ -27,7 +27,7 @@ func Test_MTime(t *testing.T) {
|
||||
createTestFile(file1, "")
|
||||
defer delTestFiles(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(""), "")
|
||||
@ -45,7 +45,7 @@ func Test_MTimeMillisecond(t *testing.T) {
|
||||
createTestFile(file1, "")
|
||||
defer delTestFiles(file1)
|
||||
fileobj, err = os.Stat(testpath() + file1)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
t.AssertGE(
|
||||
|
@ -150,29 +150,29 @@ func Test_ConcurrentOS(t *testing.T) {
|
||||
path := gfile.Temp(gtime.TimestampNanoStr())
|
||||
defer gfile.Remove(path)
|
||||
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()
|
||||
|
||||
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()
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
_, err = f1.Write([]byte("@1234567890#"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
}
|
||||
for i := 0; i < 100; i++ {
|
||||
_, err = f2.Write([]byte("@1234567890#"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
}
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
_, err = f1.Write([]byte("@1234567890#"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
}
|
||||
for i := 0; i < 1000; i++ {
|
||||
_, err = f2.Write([]byte("@1234567890#"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
}
|
||||
t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2200)
|
||||
})
|
||||
@ -181,20 +181,20 @@ func Test_ConcurrentOS(t *testing.T) {
|
||||
path := gfile.Temp(gtime.TimestampNanoStr())
|
||||
defer gfile.Remove(path)
|
||||
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()
|
||||
|
||||
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()
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
_, err = f1.Write([]byte("@1234567890#"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
}
|
||||
for i := 0; i < 1000; i++ {
|
||||
_, err = f2.Write([]byte("@1234567890#"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
}
|
||||
t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000)
|
||||
})
|
||||
@ -202,11 +202,11 @@ func Test_ConcurrentOS(t *testing.T) {
|
||||
path := gfile.Temp(gtime.TimestampNanoStr())
|
||||
defer gfile.Remove(path)
|
||||
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()
|
||||
|
||||
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()
|
||||
|
||||
s1 := ""
|
||||
@ -214,14 +214,14 @@ func Test_ConcurrentOS(t *testing.T) {
|
||||
s1 += "@1234567890#"
|
||||
}
|
||||
_, err = f2.Write([]byte(s1))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
s2 := ""
|
||||
for i := 0; i < 1000; i++ {
|
||||
s2 += "@1234567890#"
|
||||
}
|
||||
_, err = f2.Write([]byte(s2))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000)
|
||||
})
|
||||
@ -230,11 +230,11 @@ func Test_ConcurrentOS(t *testing.T) {
|
||||
// path := gfile.Temp(gtime.TimestampNanoStr())
|
||||
// defer gfile.Remove(path)
|
||||
// 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()
|
||||
//
|
||||
// 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()
|
||||
//
|
||||
// wg := sync.WaitGroup{}
|
||||
@ -245,7 +245,7 @@ func Test_ConcurrentOS(t *testing.T) {
|
||||
// defer wg.Done()
|
||||
// <-ch
|
||||
// _, err = f1.Write([]byte("@1234567890#"))
|
||||
// t.Assert(err, nil)
|
||||
// t.AssertNil(err)
|
||||
// }()
|
||||
// }
|
||||
// for i := 0; i < 1000; i++ {
|
||||
@ -254,7 +254,7 @@ func Test_ConcurrentOS(t *testing.T) {
|
||||
// defer wg.Done()
|
||||
// <-ch
|
||||
// _, err = f2.Write([]byte("@1234567890#"))
|
||||
// t.Assert(err, nil)
|
||||
// t.AssertNil(err)
|
||||
// }()
|
||||
// }
|
||||
// close(ch)
|
||||
@ -268,20 +268,20 @@ func Test_ConcurrentGFPool(t *testing.T) {
|
||||
path := gfile.Temp(gtime.TimestampNanoStr())
|
||||
defer gfile.Remove(path)
|
||||
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()
|
||||
|
||||
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()
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
_, err = f1.Write([]byte("@1234567890#"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
}
|
||||
for i := 0; i < 1000; i++ {
|
||||
_, err = f2.Write([]byte("@1234567890#"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
}
|
||||
t.Assert(gstr.Count(gfile.GetContents(path), "@1234567890#"), 2000)
|
||||
})
|
||||
@ -290,11 +290,11 @@ func Test_ConcurrentGFPool(t *testing.T) {
|
||||
// path := gfile.Temp(gtime.TimestampNanoStr())
|
||||
// defer gfile.Remove(path)
|
||||
// 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()
|
||||
//
|
||||
// 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()
|
||||
//
|
||||
// wg := sync.WaitGroup{}
|
||||
@ -305,7 +305,7 @@ func Test_ConcurrentGFPool(t *testing.T) {
|
||||
// defer wg.Done()
|
||||
// <-ch
|
||||
// _, err = f1.Write([]byte("@1234567890#"))
|
||||
// t.Assert(err, nil)
|
||||
// t.AssertNil(err)
|
||||
// }()
|
||||
// }
|
||||
// for i := 0; i < 1000; i++ {
|
||||
@ -314,7 +314,7 @@ func Test_ConcurrentGFPool(t *testing.T) {
|
||||
// defer wg.Done()
|
||||
// <-ch
|
||||
// _, err = f2.Write([]byte("@1234567890#"))
|
||||
// t.Assert(err, nil)
|
||||
// t.AssertNil(err)
|
||||
// }()
|
||||
// }
|
||||
// close(ch)
|
||||
|
@ -24,31 +24,31 @@ func TestWatcher_AddOnce(t *testing.T) {
|
||||
value := gtype.New()
|
||||
path := gfile.Temp(gconv.String(gtime.TimestampNano()))
|
||||
err := gfile.PutContents(path, "init")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
callback1, err := gfsnotify.AddOnce("mywatch", path, func(event *gfsnotify.Event) {
|
||||
value.Set(1)
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
callback2, err := gfsnotify.AddOnce("mywatch", path, func(event *gfsnotify.Event) {
|
||||
value.Set(2)
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(callback2, nil)
|
||||
|
||||
err = gfile.PutContents(path, "1")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
t.Assert(value, 1)
|
||||
|
||||
err = gfsnotify.RemoveCallback(callback1.Id)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
err = gfile.PutContents(path, "2")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
t.Assert(value, 1)
|
||||
@ -76,7 +76,7 @@ func TestWatcher_AddRemove(t *testing.T) {
|
||||
return
|
||||
}
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertNE(callback, nil)
|
||||
|
||||
gfile.PutContents(path1, "2")
|
||||
@ -105,7 +105,7 @@ func TestWatcher_AddRemove(t *testing.T) {
|
||||
return
|
||||
}
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertNE(callback, nil)
|
||||
|
||||
gfile.PutContents(path1, "2")
|
||||
@ -136,7 +136,7 @@ func TestWatcher_Callback1(t *testing.T) {
|
||||
return
|
||||
}
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.AssertNE(callback, nil)
|
||||
|
||||
gfile.PutContents(path1, "2")
|
||||
|
@ -24,7 +24,7 @@ func Test_SetConfigWithMap(t *testing.T) {
|
||||
"StStatus": 0,
|
||||
}
|
||||
err := l.SetConfigWithMap(m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(l.config.Path, m["path"])
|
||||
t.Assert(l.config.Level, LEVEL_ALL)
|
||||
t.Assert(l.config.StdoutPrint, m["stdout"])
|
||||
@ -39,7 +39,7 @@ func Test_SetConfigWithMap_LevelStr(t *testing.T) {
|
||||
"level": "all",
|
||||
}
|
||||
err := l.SetConfigWithMap(m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
l.SetWriter(buffer)
|
||||
|
||||
@ -56,7 +56,7 @@ func Test_SetConfigWithMap_LevelStr(t *testing.T) {
|
||||
"level": "warn",
|
||||
}
|
||||
err := l.SetConfigWithMap(m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
l.SetWriter(buffer)
|
||||
l.Debug(ctx, "test")
|
||||
l.Warning(ctx, "test")
|
||||
|
@ -34,7 +34,7 @@ func Test_Path(t *testing.T) {
|
||||
file := fmt.Sprintf(`%d.log`, gtime.TimestampNano())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
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())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
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())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
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())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
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())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
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())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
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())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
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())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
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())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
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())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
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())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
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())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
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())
|
||||
|
||||
err := gfile.Mkdir(path)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(path)
|
||||
|
||||
Path(path).File(file).Async(false).Stdout(false).Debug(ctx, 1, 2, 3)
|
||||
|
@ -38,7 +38,7 @@ func Test_Rotate_Size(t *testing.T) {
|
||||
"RotateBackupCompress": 9,
|
||||
"RotateCheckInterval": time.Second, // For unit testing only.
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(p)
|
||||
|
||||
s := "1234567890abcdefg"
|
||||
@ -50,7 +50,7 @@ func Test_Rotate_Size(t *testing.T) {
|
||||
time.Sleep(time.Second * 3)
|
||||
|
||||
files, err := gfile.ScanDirFile(p, "*.gz")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(files), 2)
|
||||
|
||||
content := gfile.GetContents(gfile.Join(p, "access.log"))
|
||||
@ -58,7 +58,7 @@ func Test_Rotate_Size(t *testing.T) {
|
||||
|
||||
time.Sleep(time.Second * 5)
|
||||
files, err = gfile.ScanDirFile(p, "*.gz")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(files), 0)
|
||||
})
|
||||
}
|
||||
@ -77,7 +77,7 @@ func Test_Rotate_Expire(t *testing.T) {
|
||||
"RotateBackupCompress": 9,
|
||||
"RotateCheckInterval": time.Second, // For unit testing only.
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer gfile.Remove(p)
|
||||
|
||||
s := "1234567890abcdefg"
|
||||
@ -86,7 +86,7 @@ func Test_Rotate_Expire(t *testing.T) {
|
||||
}
|
||||
|
||||
files, err := gfile.ScanDirFile(p, "*.gz")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(files), 0)
|
||||
|
||||
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)
|
||||
|
||||
files, err = gfile.ScanDirFile(p, "*.gz")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(files), 1)
|
||||
|
||||
t.Assert(gstr.Count(gfile.GetContents(gfile.Join(p, "access.log")), s), 0)
|
||||
|
||||
time.Sleep(time.Second * 5)
|
||||
files, err = gfile.ScanDirFile(p, "*.gz")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(len(files), 0)
|
||||
})
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func Test_Ctx_Config(t *testing.T) {
|
||||
"CtxKeys": g.SliceStr{"Trace-Id", "Span-Id", "Test"},
|
||||
}
|
||||
err := l.SetConfigWithMap(m)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
ctx := context.WithValue(context.Background(), "Trace-Id", "1234567890")
|
||||
ctx = context.WithValue(ctx, "Span-Id", "abcdefg")
|
||||
|
||||
|
@ -28,7 +28,7 @@ func Test_PackToGoFile(t *testing.T) {
|
||||
pkgName = "testdata"
|
||||
err = gres.PackToGoFile(srcPath, goFilePath, pkgName)
|
||||
)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
_ = gfile.Remove(goFilePath)
|
||||
})
|
||||
}
|
||||
@ -39,11 +39,11 @@ func Test_Pack(t *testing.T) {
|
||||
srcPath = gdebug.TestDataPath("files")
|
||||
data, err = gres.Pack(srcPath)
|
||||
)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
r := gres.New()
|
||||
err = r.Add(string(data))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r.Contains("files/"), true)
|
||||
})
|
||||
}
|
||||
@ -55,13 +55,13 @@ func Test_PackToFile(t *testing.T) {
|
||||
dstPath = gfile.Temp(gtime.TimestampNanoStr())
|
||||
err = gres.PackToFile(srcPath, dstPath)
|
||||
)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
defer gfile.Remove(dstPath)
|
||||
|
||||
r := gres.New()
|
||||
err = r.Load(dstPath)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(r.Contains("files"), true)
|
||||
})
|
||||
}
|
||||
@ -74,9 +74,9 @@ func Test_PackMulti(t *testing.T) {
|
||||
pkgName = "data"
|
||||
array, err = gfile.ScanDir(srcPath, "*", false)
|
||||
)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
err = gres.PackToGoFile(strings.Join(array, ","), goFilePath, pkgName)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
_ = gfile.Remove(goFilePath)
|
||||
})
|
||||
}
|
||||
@ -102,7 +102,7 @@ func Test_PackWithPrefix2(t *testing.T) {
|
||||
pkgName = "testdata"
|
||||
err = gres.PackToGoFile(srcPath, goFilePath, pkgName, "/var/www/gf-site/test")
|
||||
)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
_ = gfile.Remove(goFilePath)
|
||||
})
|
||||
}
|
||||
@ -127,13 +127,13 @@ func Test_Basic(t *testing.T) {
|
||||
t.Assert(info.Name(), "test1")
|
||||
|
||||
rc, err := file.Open()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer rc.Close()
|
||||
|
||||
b := make([]byte, 5)
|
||||
n, err := rc.Read(b)
|
||||
t.Assert(n, 5)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(b), "test1")
|
||||
|
||||
t.Assert(file.Content(), "test1 content")
|
||||
@ -151,7 +151,7 @@ func Test_Basic(t *testing.T) {
|
||||
t.Assert(info.Name(), "dir2")
|
||||
|
||||
rc, err := file.Open()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
defer rc.Close()
|
||||
|
||||
t.Assert(file.Content(), nil)
|
||||
|
@ -88,7 +88,7 @@ func Test_StorageRedisHashTablePrefix(t *testing.T) {
|
||||
Db: 0,
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
})
|
||||
|
||||
prefix := "s_"
|
||||
|
@ -22,7 +22,7 @@ func Test_StorageRedis(t *testing.T) {
|
||||
Address: "127.0.0.1:6379",
|
||||
Db: 0,
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
|
||||
storage := gsession.NewStorageRedis(redis)
|
||||
manager := gsession.New(time.Second, storage)
|
||||
@ -86,7 +86,7 @@ func Test_StorageRedisPrefix(t *testing.T) {
|
||||
Address: "127.0.0.1:6379",
|
||||
Db: 0,
|
||||
})
|
||||
gtest.Assert(err, nil)
|
||||
gtest.AssertNil(err)
|
||||
|
||||
prefix := "s_"
|
||||
storage := gsession.NewStorageRedis(redis, prefix)
|
||||
|
@ -45,7 +45,7 @@ func TestSPath_Basic(t *testing.T) {
|
||||
defer gfile.Remove(gfile.Join(root, "gf_tmp"))
|
||||
gsp := gspath.New(root, false)
|
||||
realPath, err := gsp.Add(gfile.Join(root, "gf_tmp"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(realPath, gfile.Join(root, "gf_tmp"))
|
||||
realPath, err = gsp.Add("gf_tmp1")
|
||||
t.Assert(err != nil, true)
|
||||
@ -65,7 +65,7 @@ func TestSPath_Basic(t *testing.T) {
|
||||
t.Assert(realPath, "")
|
||||
|
||||
realPath, err = gsp.Set(root)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(realPath, root)
|
||||
|
||||
fp, isDir := gsp.Search("gf_tmp")
|
||||
@ -80,7 +80,7 @@ func TestSPath_Basic(t *testing.T) {
|
||||
|
||||
gsp = gspath.New(root, true)
|
||||
realPath, err = gsp.Add(gfile.Join(root, "gf_tmp"))
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(realPath, gfile.Join(root, "gf_tmp"))
|
||||
|
||||
gfile.Mkdir(gfile.Join(root, "gf_tmp1"))
|
||||
|
@ -30,12 +30,12 @@ func TestTime_Value(t1 *testing.T) {
|
||||
gtest.C(t1, func(t *gtest.T) {
|
||||
tt := gtime.Now()
|
||||
s, err := tt.Value()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(s, tt.Time)
|
||||
// test nil
|
||||
none := (*gtime.Time)(nil)
|
||||
s, err = none.Value()
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(s, nil)
|
||||
|
||||
})
|
||||
|
@ -105,7 +105,7 @@ func Test_StrToTime(t *testing.T) {
|
||||
|
||||
for _, item := range testDateTimes {
|
||||
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")
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ func Test_StrToTime(t *testing.T) {
|
||||
|
||||
for _, item := range testDates {
|
||||
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")
|
||||
}
|
||||
|
||||
@ -130,9 +130,9 @@ func Test_StrToTime(t *testing.T) {
|
||||
|
||||
for k, v := range testTimes {
|
||||
time1, err := gtime.StrToTime(k)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
time2, err := time.ParseInLocation(v, k, time.Local)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(time1.Time, time2)
|
||||
}
|
||||
|
||||
@ -232,22 +232,22 @@ func Test_ConvertZone(t *testing.T) {
|
||||
func Test_ParseDuration(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
d, err := gtime.ParseDuration("1d")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(d.String(), "24h0m0s")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
d, err := gtime.ParseDuration("1d2h3m")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(d.String(), "26h3m0s")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
d, err := gtime.ParseDuration("-1d2h3m")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(d.String(), "-26h3m0s")
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
d, err := gtime.ParseDuration("3m")
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(d.String(), "3m0s")
|
||||
})
|
||||
// error
|
||||
|
@ -28,16 +28,16 @@ func Test_Config(t *testing.T) {
|
||||
}
|
||||
view := gview.New()
|
||||
err := view.SetConfig(config)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
str := `hello ${.name},version:${.version}`
|
||||
view.Assigns(g.Map{"version": "1.7.0"})
|
||||
result, err := view.ParseContent(context.TODO(), str, nil)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, "hello gf,version:1.7.0")
|
||||
|
||||
result, err = view.ParseDefault(context.TODO())
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, "name:gf")
|
||||
})
|
||||
}
|
||||
@ -53,16 +53,16 @@ func Test_ConfigWithMap(t *testing.T) {
|
||||
"name": "gf",
|
||||
},
|
||||
})
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
|
||||
str := `hello ${.name},version:${.version}`
|
||||
view.Assigns(g.Map{"version": "1.7.0"})
|
||||
result, err := view.ParseContent(context.TODO(), str, nil)
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, "hello gf,version:1.7.0")
|
||||
|
||||
result, err = view.ParseDefault(context.TODO())
|
||||
t.Assert(err, nil)
|
||||
t.AssertNil(err)
|
||||
t.Assert(result, "name:gf")
|
||||
})
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user