diff --git a/container/garray/garray_z_unit_normal_int_test.go b/container/garray/garray_z_unit_normal_int_test.go index 83020871f6d..9d7dd814a49 100644 --- a/container/garray/garray_z_unit_normal_int_test.go +++ b/container/garray/garray_z_unit_normal_int_test.go @@ -642,6 +642,7 @@ func TestIntArray_Json(t *testing.T) { a2 := garray.NewIntArray() err1 = json.UnmarshalUseNumber(b2, &a2) + t.AssertNil(err1) t.Assert(a2.Slice(), s1) var a3 garray.IntArray @@ -660,6 +661,7 @@ func TestIntArray_Json(t *testing.T) { a2 := garray.NewIntArray() err1 = json.UnmarshalUseNumber(b2, &a2) + t.AssertNil(err1) t.Assert(a2.Slice(), s1) var a3 garray.IntArray diff --git a/container/garray/garray_z_unit_normal_str_test.go b/container/garray/garray_z_unit_normal_str_test.go index 7907db0109d..f71ec473d03 100644 --- a/container/garray/garray_z_unit_normal_str_test.go +++ b/container/garray/garray_z_unit_normal_str_test.go @@ -654,6 +654,7 @@ func TestStrArray_Json(t *testing.T) { a2 := garray.NewStrArray() err1 = json.UnmarshalUseNumber(b2, &a2) + t.AssertNil(err1) t.Assert(a2.Slice(), s1) var a3 garray.StrArray @@ -672,6 +673,7 @@ func TestStrArray_Json(t *testing.T) { a2 := garray.NewStrArray() err1 = json.UnmarshalUseNumber(b2, &a2) + t.AssertNil(err1) t.Assert(a2.Slice(), s1) var a3 garray.StrArray diff --git a/container/garray/garray_z_unit_sorted_any_test.go b/container/garray/garray_z_unit_sorted_any_test.go index 1fd45a53cc1..3be78342edc 100644 --- a/container/garray/garray_z_unit_sorted_any_test.go +++ b/container/garray/garray_z_unit_sorted_any_test.go @@ -710,6 +710,7 @@ func TestSortedArray_Json(t *testing.T) { a2 := garray.NewSortedArray(gutil.ComparatorString) err1 = json.UnmarshalUseNumber(b2, &a2) + t.AssertNil(err1) t.Assert(a2.Slice(), s2) var a3 garray.SortedArray @@ -730,6 +731,7 @@ func TestSortedArray_Json(t *testing.T) { a2 := garray.NewSortedArray(gutil.ComparatorString) err1 = json.UnmarshalUseNumber(b2, &a2) + t.AssertNil(err1) t.Assert(a2.Slice(), s2) var a3 garray.SortedArray diff --git a/container/garray/garray_z_unit_sorted_int_test.go b/container/garray/garray_z_unit_sorted_int_test.go index 1fc3ee92a5e..65c921611f0 100644 --- a/container/garray/garray_z_unit_sorted_int_test.go +++ b/container/garray/garray_z_unit_sorted_int_test.go @@ -613,6 +613,7 @@ func TestSortedIntArray_Json(t *testing.T) { a2 := garray.NewSortedIntArray() err1 = json.UnmarshalUseNumber(b2, &a2) + t.AssertNil(err1) t.Assert(a2.Slice(), s2) var a3 garray.SortedIntArray @@ -632,6 +633,7 @@ func TestSortedIntArray_Json(t *testing.T) { a2 := garray.NewSortedIntArray() err1 = json.UnmarshalUseNumber(b2, &a2) + t.AssertNil(err1) t.Assert(a2.Slice(), s2) var a3 garray.SortedIntArray diff --git a/container/garray/garray_z_unit_sorted_str_test.go b/container/garray/garray_z_unit_sorted_str_test.go index 380297f3b11..458f9043a1f 100644 --- a/container/garray/garray_z_unit_sorted_str_test.go +++ b/container/garray/garray_z_unit_sorted_str_test.go @@ -622,6 +622,7 @@ func TestSortedStrArray_Json(t *testing.T) { a2 := garray.NewSortedStrArray() err1 = json.UnmarshalUseNumber(b2, &a2) + t.AssertNil(err1) t.Assert(a2.Slice(), s2) t.Assert(a2.Interfaces(), s2) @@ -643,6 +644,7 @@ func TestSortedStrArray_Json(t *testing.T) { a2 := garray.NewSortedStrArray() err1 = json.UnmarshalUseNumber(b2, &a2) + t.AssertNil(err1) t.Assert(a2.Slice(), s2) t.Assert(a2.Interfaces(), s2) diff --git a/container/glist/glist_z_unit_test.go b/container/glist/glist_z_unit_test.go index 2a6dbc8ec2f..36984790f2a 100644 --- a/container/glist/glist_z_unit_test.go +++ b/container/glist/glist_z_unit_test.go @@ -631,10 +631,7 @@ func TestList_IteratorAsc(t *testing.T) { l.PushFronts(a1) e1 := l.Back() fun1 := func(e *Element) bool { - if gconv.Int(e1.Value) > 2 { - return true - } - return false + return gconv.Int(e1.Value) > 2 } checkList(t, l, []interface{}{4, 3, 6, 5, 2, 1}) l.IteratorAsc(fun1) @@ -649,10 +646,7 @@ func TestList_IteratorDesc(t *testing.T) { l.PushFronts(a1) e1 := l.Back() fun1 := func(e *Element) bool { - if gconv.Int(e1.Value) > 6 { - return true - } - return false + return gconv.Int(e1.Value) > 6 } l.IteratorDesc(fun1) t.Assert(l.Len(), 4) @@ -667,10 +661,7 @@ func TestList_Iterator(t *testing.T) { l.PushFronts(a1) e1 := l.Back() fun1 := func(e *Element) bool { - if gconv.String(e1.Value) > "c" { - return true - } - return false + return gconv.String(e1.Value) > "c" } checkList(t, l, []interface{}{"e", "d", "c", "b", "a"}) l.Iterator(fun1) diff --git a/encoding/gjson/gjson_z_unit_feature_set_test.go b/encoding/gjson/gjson_z_unit_feature_set_test.go index 0e48d52902c..1685e816f4e 100644 --- a/encoding/gjson/gjson_z_unit_feature_set_test.go +++ b/encoding/gjson/gjson_z_unit_feature_set_test.go @@ -26,7 +26,7 @@ func Test_Set1(t *testing.T) { p.Set("k1.k11", []int{1, 2, 3}) if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, []byte(`{"k1":{"k11":[1,2,3]},"k2":"v2"}`)) != 0 { + if !bytes.Equal(c, []byte(`{"k1":{"k11":[1,2,3]},"k2":"v2"}`)) { t.Error("expect:", string(e)) } } else { @@ -51,7 +51,7 @@ func Test_Set3(t *testing.T) { "k1": "v1", }) if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, e) != 0 { + if !bytes.Equal(c, e) { t.Error("expect:", string(e)) } } else { @@ -67,7 +67,7 @@ func Test_Set4(t *testing.T) { }) if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, e) != 0 { + if !bytes.Equal(c, e) { t.Error("expect:", string(e)) } } else { @@ -81,7 +81,7 @@ func Test_Set5(t *testing.T) { p.Set("0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0", []int{1, 2, 3}) if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, e) != 0 { + if !bytes.Equal(c, e) { t.Error("expect:", string(e)) } } else { @@ -95,7 +95,7 @@ func Test_Set6(t *testing.T) { p.Set("1", []int{1, 2, 3}) if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, e) != 0 { + if !bytes.Equal(c, e) { t.Error("expect:", string(e)) } } else { @@ -112,7 +112,7 @@ func Test_Set7(t *testing.T) { p.Set("0.1", []int{1, 2, 3}) if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, e) != 0 { + if !bytes.Equal(c, e) { t.Error("expect:", string(e)) } } else { @@ -129,7 +129,7 @@ func Test_Set8(t *testing.T) { p.Set("0.0.0.0.0.0.1", []int{1, 2, 3}) if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, e) != 0 { + if !bytes.Equal(c, e) { t.Error("expect:", string(e)) } } else { @@ -146,7 +146,7 @@ func Test_Set9(t *testing.T) { p.Set("k1.1", []int{1, 2, 3}) if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, e) != 0 { + if !bytes.Equal(c, e) { t.Error("expect:", string(e)) } } else { @@ -160,7 +160,7 @@ func Test_Set10(t *testing.T) { p.Set("a.b.c", 1) if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, e) != 0 { + if !bytes.Equal(c, e) { t.Error("expect:", string(e)) } } else { @@ -174,7 +174,7 @@ func Test_Set11(t *testing.T) { p.Remove("a.b.c") if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, e) != 0 { + if !bytes.Equal(c, e) { t.Error("expect:", string(e)) } } else { @@ -189,7 +189,7 @@ func Test_Set12(t *testing.T) { p.Set("1", 1) if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, e) != 0 { + if !bytes.Equal(c, e) { t.Error("expect:", string(e)) } } else { @@ -204,7 +204,7 @@ func Test_Set13(t *testing.T) { p.Set("array.1", 1) if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, e) != 0 { + if !bytes.Equal(c, e) { t.Error("expect:", string(e)) } } else { @@ -219,7 +219,7 @@ func Test_Set14(t *testing.T) { p.Set("f.a", 1) if c, err := p.ToJson(); err == nil { - if bytes.Compare(c, e) != 0 { + if !bytes.Equal(c, e) { t.Error("expect:", string(e)) } } else { diff --git a/encoding/gxml/gxml_z_unit_test.go b/encoding/gxml/gxml_z_unit_test.go index 649e730fc7e..28a8a993f3f 100644 --- a/encoding/gxml/gxml_z_unit_test.go +++ b/encoding/gxml/gxml_z_unit_test.go @@ -73,7 +73,7 @@ func Test_XmlToJson(t *testing.T) { t.Errorf("dstXml to json error. %s", dstXml) } - if bytes.Compare(srcJson, dstJson) != 0 { + if !bytes.Equal(srcJson, dstJson) { t.Errorf("convert to json error. srcJson:%s, dstJson:%s", string(srcJson), string(dstJson)) } diff --git a/internal/empty/empty_z_unit_test.go b/internal/empty/empty_z_unit_test.go index 36dc504ab9a..6b9efed1e58 100644 --- a/internal/empty/empty_z_unit_test.go +++ b/internal/empty/empty_z_unit_test.go @@ -35,7 +35,7 @@ func TestIsEmpty(t *testing.T) { tmpT1 := "0" tmpT2 := func() {} tmpT2 = nil - tmpT3 := make(chan int, 0) + tmpT3 := make(chan int) var ( tmpT4 TestPerson = nil tmpT5 *TestPerson = nil diff --git a/internal/utils/utils_str.go b/internal/utils/utils_str.go index 44c9f0db0cb..d222457332f 100644 --- a/internal/utils/utils_str.go +++ b/internal/utils/utils_str.go @@ -73,10 +73,7 @@ func IsNumeric(s string) bool { return false } } - if dotCount > 1 { - return false - } - return true + return dotCount <= 1 } // UcFirst returns a copy of the string s with the first letter mapped to its upper case. diff --git a/net/gtcp/gtcp_z_unit_pool_test.go b/net/gtcp/gtcp_z_unit_pool_test.go index 8dbfd84a847..7fc19d8d8d2 100644 --- a/net/gtcp/gtcp_z_unit_pool_test.go +++ b/net/gtcp/gtcp_z_unit_pool_test.go @@ -7,7 +7,6 @@ package gtcp_test import ( - "fmt" "testing" "time" @@ -42,7 +41,7 @@ func Test_Pool_Basic1(t *testing.T) { }) gtest.C(t, func(t *gtest.T) { - _, err := gtcp.NewPoolConn(fmt.Sprintf("127.0.0.1:80")) + _, err := gtcp.NewPoolConn("127.0.0.1:80") t.AssertNE(err, nil) }) } diff --git a/os/glog/glog_logger_config.go b/os/glog/glog_logger_config.go index fca3d4f79df..916665e2db9 100644 --- a/os/glog/glog_logger_config.go +++ b/os/glog/glog_logger_config.go @@ -102,7 +102,7 @@ func (l *Logger) SetConfig(config Config) error { // SetConfigWithMap set configurations with map for the logger. func (l *Logger) SetConfigWithMap(m map[string]interface{}) error { - if m == nil || len(m) == 0 { + if len(m) == 0 { return gerror.NewCode(gcode.CodeInvalidParameter, "configuration cannot be empty") } // The m now is a shallow copy of m. diff --git a/os/gmlock/gmlock_z_unit_test.go b/os/gmlock/gmlock_z_unit_test.go index 9d2a0871442..ae7aaf94c07 100644 --- a/os/gmlock/gmlock_z_unit_test.go +++ b/os/gmlock/gmlock_z_unit_test.go @@ -160,7 +160,7 @@ func Test_Locker_TryLockFunc(t *testing.T) { func Test_Multiple_Goroutine(t *testing.T) { gtest.C(t, func(t *gtest.T) { - ch := make(chan struct{}, 0) + ch := make(chan struct{}) num := 1000 wait := sync.WaitGroup{} wait.Add(num) @@ -178,7 +178,7 @@ func Test_Multiple_Goroutine(t *testing.T) { }) gtest.C(t, func(t *gtest.T) { - ch := make(chan struct{}, 0) + ch := make(chan struct{}) num := 100 wait := sync.WaitGroup{} wait.Add(num * 2) diff --git a/os/gview/gview_config.go b/os/gview/gview_config.go index 447f75f9e41..cff9e49d5a0 100644 --- a/os/gview/gview_config.go +++ b/os/gview/gview_config.go @@ -75,7 +75,7 @@ func (view *View) SetConfig(config Config) error { // SetConfigWithMap set configurations with map for the view. func (view *View) SetConfigWithMap(m map[string]interface{}) error { - if m == nil || len(m) == 0 { + if len(m) == 0 { return gerror.NewCode(gcode.CodeInvalidParameter, "configuration cannot be empty") } // The m now is a shallow copy of m. diff --git a/text/gregex/gregex_z_unit_test.go b/text/gregex/gregex_z_unit_test.go index ca07f84079e..8de86509bf6 100644 --- a/text/gregex/gregex_z_unit_test.go +++ b/text/gregex/gregex_z_unit_test.go @@ -200,7 +200,7 @@ func Test_ReplaceFun(t *testing.T) { wanted := "acbb[x" + wantSubs + "y]dd" wanted = "acbb" + "3个a" + "dd" replacedStr, err := gregex.ReplaceFunc(re, []byte(s), func(s []byte) []byte { - if strings.Index(string(s), "aaa") >= 0 { + if strings.Contains(string(s), "aaa") { return []byte("3个a") } return []byte("[x" + string(s) + "y]") @@ -258,7 +258,7 @@ func Test_ReplaceStringFunc(t *testing.T) { wanted := "acbb[x" + wantSubs + "y]dd" wanted = "acbb" + "3个a" + "dd" replacedStr, err := gregex.ReplaceStringFunc(re, s, func(s string) string { - if strings.Index(s, "aaa") >= 0 { + if strings.Contains(s, "aaa") { return "3个a" } return "[x" + s + "y]" diff --git a/util/gconv/gconv_map.go b/util/gconv/gconv_map.go index 89bf8fc0fb5..d51583350bd 100644 --- a/util/gconv/gconv_map.go +++ b/util/gconv/gconv_map.go @@ -231,7 +231,7 @@ type doMapConvertForMapOrStructValueInput struct { } func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) interface{} { - if in.IsRoot == false && in.RecursiveOption == false { + if !in.IsRoot && !in.RecursiveOption { return in.Value } diff --git a/util/gconv/gconv_z_unit_all_test.go b/util/gconv/gconv_z_unit_all_test.go index d0faa401b83..d6bc83e0ff4 100644 --- a/util/gconv/gconv_z_unit_all_test.go +++ b/util/gconv/gconv_z_unit_all_test.go @@ -590,11 +590,9 @@ func Test_String_All(t *testing.T) { t.AssertEQ(gconv.String(boolStruct{}), "{}") t.AssertEQ(gconv.String(&boolStruct{}), "{}") - var info iString - info = new(S) + var info = new(S) t.AssertEQ(gconv.String(info), "22222") - var errInfo iError - errInfo = new(S1) + var errInfo = new(S1) t.AssertEQ(gconv.String(errInfo), "22222") }) }