diff --git a/go/cache/lru_cache_test.go b/go/cache/lru_cache_test.go index e0dbfcda117..af9db72852e 100644 --- a/go/cache/lru_cache_test.go +++ b/go/cache/lru_cache_test.go @@ -18,6 +18,8 @@ package cache import ( "testing" + + "github.com/stretchr/testify/assert" ) type CacheValue struct { @@ -27,24 +29,12 @@ type CacheValue struct { func TestInitialState(t *testing.T) { cache := NewLRUCache[*CacheValue](5) l, sz, c, e, h, m := cache.Len(), cache.UsedCapacity(), cache.MaxCapacity(), cache.Evictions(), cache.Hits(), cache.Misses() - if l != 0 { - t.Errorf("length = %v, want 0", l) - } - if sz != 0 { - t.Errorf("size = %v, want 0", sz) - } - if c != 5 { - t.Errorf("capacity = %v, want 5", c) - } - if e != 0 { - t.Errorf("evictions = %v, want 0", c) - } - if h != 0 { - t.Errorf("hits = %v, want 0", c) - } - if m != 0 { - t.Errorf("misses = %v, want 0", c) - } + assert.Zero(t, l) + assert.EqualValues(t, 0, sz) + assert.EqualValues(t, 5, c) + assert.EqualValues(t, 0, e) + assert.EqualValues(t, 0, h) + assert.EqualValues(t, 0, m) } func TestSetInsertsValue(t *testing.T) { @@ -137,12 +127,8 @@ func TestCapacityIsObeyed(t *testing.T) { // Insert one more; something should be evicted to make room. cache.Set("key4", value) sz, evictions := cache.UsedCapacity(), cache.Evictions() - if sz != size { - t.Errorf("post-evict cache.UsedCapacity() = %v, expected %v", sz, size) - } - if evictions != 1 { - t.Errorf("post-evict cache.Evictions() = %v, expected 1", evictions) - } + assert.Equal(t, size, sz) + assert.EqualValues(t, 1, evictions) // Check various other stats if l := cache.Len(); int64(l) != size { diff --git a/go/cache/theine/singleflight_test.go b/go/cache/theine/singleflight_test.go index 4ae235f97e2..bf5018a8891 100644 --- a/go/cache/theine/singleflight_test.go +++ b/go/cache/theine/singleflight_test.go @@ -43,8 +43,8 @@ func TestDo(t *testing.T) { return "bar", nil }) - assert.Equal(t, "bar (string)", fmt.Sprintf("%v (%T)", v, v), "incorrect Do value") - assert.NoError(t, err, "got Do error") + assert.Equal(t, "bar (string)", fmt.Sprintf("%v (%T)", v, v)) + assert.NoError(t, err) } func TestDoErr(t *testing.T) { @@ -85,11 +85,11 @@ func TestDoDupSuppress(t *testing.T) { defer wg2.Done() wg1.Done() v, err, _ := g.Do("key", fn) - if !assert.NoError(t, err, "unexpected Do error") { + if !assert.NoError(t, err) { return } - assert.Equal(t, "bar", v, "unexpected Do value") + assert.Equal(t, "bar", v) }() } wg1.Wait() @@ -98,7 +98,8 @@ func TestDoDupSuppress(t *testing.T) { c <- "bar" wg2.Wait() got := atomic.LoadInt32(&calls) - assert.True(t, got > 0 && got < n, "number of calls not between 0 and %d", n) + assert.Greater(t, got, int32(0)) + assert.Less(t, got, int32(n)) } // Test singleflight behaves correctly after Do panic. @@ -131,7 +132,7 @@ func TestPanicDo(t *testing.T) { select { case <-done: - assert.Equal(t, int32(n), panicCount, "unexpected number of panics") + assert.EqualValues(t, n, panicCount) case <-time.After(time.Second): require.Fail(t, "Do hangs") } @@ -152,6 +153,7 @@ func TestGoexitDo(t *testing.T) { var err error defer func() { assert.NoError(t, err) + if atomic.AddInt32(&waited, -1) == 0 { close(done) } diff --git a/go/event/event_test.go b/go/event/event_test.go index f7356a98f3e..cdca98abd85 100644 --- a/go/event/event_test.go +++ b/go/event/event_test.go @@ -20,6 +20,8 @@ import ( "reflect" "testing" "time" + + "github.com/stretchr/testify/assert" ) type testInterface1 interface { @@ -56,10 +58,7 @@ func TestStaticListener(t *testing.T) { AddListener(func(testEvent1) { triggered = true }) AddListener(func(testEvent2) { t.Errorf("wrong listener type triggered") }) Dispatch(testEvent1{}) - - if !triggered { - t.Errorf("static listener failed to trigger") - } + assert.True(t, triggered, "static listener failed to trigger") } func TestPointerListener(t *testing.T) { @@ -69,10 +68,7 @@ func TestPointerListener(t *testing.T) { AddListener(func(ev *testEvent2) { ev.triggered = true }) AddListener(func(testEvent2) { t.Errorf("non-pointer listener triggered on pointer type") }) Dispatch(testEvent) - - if !testEvent.triggered { - t.Errorf("pointer listener failed to trigger") - } + assert.True(t, testEvent.triggered, "pointer listener failed to trigger") } func TestInterfaceListener(t *testing.T) { @@ -82,10 +78,7 @@ func TestInterfaceListener(t *testing.T) { AddListener(func(testInterface1) { triggered = true }) AddListener(func(testInterface2) { t.Errorf("interface listener triggered on non-matching type") }) Dispatch(testEvent1{}) - - if !triggered { - t.Errorf("interface listener failed to trigger") - } + assert.True(t, triggered, "interface listener failed to trigger") } func TestEmptyInterfaceListener(t *testing.T) { @@ -94,10 +87,7 @@ func TestEmptyInterfaceListener(t *testing.T) { triggered := false AddListener(func(any) { triggered = true }) Dispatch("this should match any") - - if !triggered { - t.Errorf("any listener failed to trigger") - } + assert.True(t, triggered, "empty listener failed to trigger") } func TestMultipleListeners(t *testing.T) { @@ -144,7 +134,6 @@ func TestBadListenerWrongType(t *testing.T) { defer func() { err := recover() - if err == nil { t.Errorf("bad listener type (not a func) failed to trigger panic") } @@ -186,10 +175,8 @@ func TestDispatchPointerToValueInterfaceListener(t *testing.T) { triggered = true }) Dispatch(&testEvent1{}) + assert.True(t, triggered, "Dispatch by pointer failed to trigger interface listener") - if !triggered { - t.Errorf("Dispatch by pointer failed to trigger interface listener") - } } func TestDispatchValueToValueInterfaceListener(t *testing.T) { @@ -200,10 +187,7 @@ func TestDispatchValueToValueInterfaceListener(t *testing.T) { triggered = true }) Dispatch(testEvent1{}) - - if !triggered { - t.Errorf("Dispatch by value failed to trigger interface listener") - } + assert.True(t, triggered, "Dispatch by value failed to trigger interface listener") } func TestDispatchPointerToPointerInterfaceListener(t *testing.T) { @@ -212,10 +196,8 @@ func TestDispatchPointerToPointerInterfaceListener(t *testing.T) { triggered := false AddListener(func(testInterface2) { triggered = true }) Dispatch(&testEvent2{}) + assert.True(t, triggered, "interface listener failed to trigger for pointer") - if !triggered { - t.Errorf("interface listener failed to trigger for pointer") - } } func TestDispatchValueToPointerInterfaceListener(t *testing.T) { @@ -245,10 +227,8 @@ func TestDispatchUpdate(t *testing.T) { ev := &testUpdateEvent{} DispatchUpdate(ev, "hello") + assert.True(t, triggered, "listener failed to trigger on DispatchUpdate()") - if !triggered { - t.Errorf("listener failed to trigger on DispatchUpdate()") - } want := "hello" if got := ev.update.(string); got != want { t.Errorf("ev.update = %#v, want %#v", got, want) diff --git a/go/event/syslogger/syslogger_test.go b/go/event/syslogger/syslogger_test.go index 28925d2ac52..6c6a181d2e5 100644 --- a/go/event/syslogger/syslogger_test.go +++ b/go/event/syslogger/syslogger_test.go @@ -25,6 +25,8 @@ import ( "testing" "vitess.io/vitess/go/event" + + "github.com/stretchr/testify/assert" ) type TestEvent struct { @@ -70,10 +72,8 @@ func TestSyslog(t *testing.T) { ev := new(TestEvent) event.Dispatch(ev) + assert.True(t, ev.triggered) - if !ev.triggered { - t.Errorf("Syslog() was not called on event that implements Syslogger") - } } // TestBadWriter verifies we are still triggering (to normal logs) if @@ -87,55 +87,40 @@ func TestBadWriter(t *testing.T) { wantLevel := "ERROR" ev := &TestEvent{priority: syslog.LOG_ALERT, message: wantMsg} event.Dispatch(ev) - if !strings.Contains(tl.getLog().msg, wantMsg) { - t.Errorf("error log msg [%s], want msg [%s]", tl.getLog().msg, wantMsg) - } - if !strings.Contains(tl.getLog().level, wantLevel) { - t.Errorf("error log level [%s], want level [%s]", tl.getLog().level, wantLevel) - } + assert.True(t, strings.Contains(tl.getLog().msg, wantMsg)) + assert.True(t, strings.Contains(tl.getLog().level, wantLevel)) + ev = &TestEvent{priority: syslog.LOG_CRIT, message: wantMsg} event.Dispatch(ev) - if !strings.Contains(tl.getLog().level, wantLevel) { - t.Errorf("error log level [%s], want level [%s]", tl.getLog().level, wantLevel) - } + assert.True(t, strings.Contains(tl.getLog().level, wantLevel)) + ev = &TestEvent{priority: syslog.LOG_ERR, message: wantMsg} event.Dispatch(ev) - if !strings.Contains(tl.getLog().level, wantLevel) { - t.Errorf("error log level [%s], want level [%s]", tl.getLog().level, wantLevel) - } + assert.True(t, strings.Contains(tl.getLog().level, wantLevel)) + ev = &TestEvent{priority: syslog.LOG_EMERG, message: wantMsg} event.Dispatch(ev) - if !strings.Contains(tl.getLog().level, wantLevel) { - t.Errorf("error log level [%s], want level [%s]", tl.getLog().level, wantLevel) - } + assert.True(t, strings.Contains(tl.getLog().level, wantLevel)) wantLevel = "WARNING" ev = &TestEvent{priority: syslog.LOG_WARNING, message: wantMsg} event.Dispatch(ev) - if !strings.Contains(tl.getLog().level, wantLevel) { - t.Errorf("error log level [%s], want level [%s]", tl.getLog().level, wantLevel) - } + assert.True(t, strings.Contains(tl.getLog().level, wantLevel)) wantLevel = "INFO" ev = &TestEvent{priority: syslog.LOG_INFO, message: wantMsg} event.Dispatch(ev) - if !strings.Contains(tl.getLog().level, wantLevel) { - t.Errorf("error log level [%s], want level [%s]", tl.getLog().level, wantLevel) - } + assert.True(t, strings.Contains(tl.getLog().level, wantLevel)) + ev = &TestEvent{priority: syslog.LOG_NOTICE, message: wantMsg} event.Dispatch(ev) - if !strings.Contains(tl.getLog().level, wantLevel) { - t.Errorf("error log level [%s], want level [%s]", tl.getLog().level, wantLevel) - } + assert.True(t, strings.Contains(tl.getLog().level, wantLevel)) + ev = &TestEvent{priority: syslog.LOG_DEBUG, message: wantMsg} event.Dispatch(ev) - if !strings.Contains(tl.getLog().level, wantLevel) { - t.Errorf("error log level [%s], want level [%s]", tl.getLog().level, wantLevel) - } + assert.True(t, strings.Contains(tl.getLog().level, wantLevel)) + assert.True(t, ev.triggered) - if !ev.triggered { - t.Errorf("passed nil writer to client") - } } // TestWriteError checks that we don't panic on a write error. @@ -150,10 +135,8 @@ func TestInvalidSeverity(t *testing.T) { writer = fw event.Dispatch(&TestEvent{priority: syslog.Priority(123), message: "log me"}) + assert.NotEqual(t, "log me", fw.message) - if fw.message == "log me" { - t.Errorf("message was logged despite invalid severity") - } } func testSeverity(sev syslog.Priority, t *testing.T) { @@ -161,13 +144,9 @@ func testSeverity(sev syslog.Priority, t *testing.T) { writer = fw event.Dispatch(&TestEvent{priority: sev, message: "log me"}) + assert.Equal(t, sev, fw.priority) + assert.Equal(t, "log me", fw.message) - if fw.priority != sev { - t.Errorf("wrong priority: got %v, want %v", fw.priority, sev) - } - if fw.message != "log me" { - t.Errorf(`wrong message: got "%v", want "%v"`, fw.message, "log me") - } } func TestEmerg(t *testing.T) { diff --git a/go/flagutil/flagutil_test.go b/go/flagutil/flagutil_test.go index dda17bb13d7..2502213ab73 100644 --- a/go/flagutil/flagutil_test.go +++ b/go/flagutil/flagutil_test.go @@ -21,6 +21,7 @@ import ( "testing" "github.com/spf13/pflag" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -38,12 +39,9 @@ func TestStringList(t *testing.T) { t.Errorf("v.Set(%v): %v", in, err) continue } - if strings.Join(p, ".") != out { - t.Errorf("want %#v, got %#v", strings.Split(out, "."), p) - } - if p.String() != in { - t.Errorf("v.String(): want %#v, got %#v", in, p.String()) - } + assert.Equal(t, out, strings.Join(p, ".")) + assert.Equal(t, in, p.String()) + } } diff --git a/go/history/history_test.go b/go/history/history_test.go index 3e817b34bb2..34c57756315 100644 --- a/go/history/history_test.go +++ b/go/history/history_test.go @@ -18,6 +18,8 @@ package history import ( "testing" + + "github.com/stretchr/testify/assert" ) func TestHistory(t *testing.T) { @@ -33,9 +35,8 @@ func TestHistory(t *testing.T) { t.Errorf("len(records): want %v, got %v. records: %+v", want, got, q) } for i, record := range records { - if record != want[i] { - t.Errorf("record doesn't match: want %v, got %v", want[i], record) - } + assert.Equal(t, want[i], record) + } for ; i < 6; i++ { @@ -48,9 +49,8 @@ func TestHistory(t *testing.T) { t.Errorf("len(records): want %v, got %v. records: %+v", want, got, q) } for i, record := range records { - if record != want[i] { - t.Errorf("record doesn't match: want %v, got %v", want[i], record) - } + assert.Equal(t, want[i], record) + } } diff --git a/go/mysql/decimal/decimal_test.go b/go/mysql/decimal/decimal_test.go index 09819ddcebb..3499ab8f802 100644 --- a/go/mysql/decimal/decimal_test.go +++ b/go/mysql/decimal/decimal_test.go @@ -26,6 +26,8 @@ import ( "strings" "testing" "testing/quick" + + "github.com/stretchr/testify/assert" ) type testEnt struct { @@ -120,11 +122,8 @@ func TestNewFromFloat(t *testing.T) { for _, x := range testTable { s := x.short d := NewFromFloat(x.float) - if d.String() != s { - t.Errorf("expected %s, got %s (float: %v) (%s, %d)", - s, d.String(), x.float, - d.value.String(), d.exp) - } + assert.Equal(t, s, d.String()) + } shouldPanicOn := []float64{ @@ -156,11 +155,8 @@ func TestNewFromFloatRandom(t *testing.T) { continue } got := NewFromFloat(in) - if !want.Equal(got) { - t.Errorf("in: %v, expected %s (%s, %d), got %s (%s, %d) ", - in, want.String(), want.value.String(), want.exp, - got.String(), got.value.String(), got.exp) - } + assert.True(t, want.Equal(got)) + } } @@ -193,11 +189,8 @@ func TestNewFromFloat32Random(t *testing.T) { continue } got := NewFromFloat32(in) - if !want.Equal(got) { - t.Errorf("in: %v, expected %s (%s, %d), got %s (%s, %d) ", - in, want.String(), want.value.String(), want.exp, - got.String(), got.value.String(), got.exp) - } + assert.True(t, want.Equal(got)) + } } @@ -317,14 +310,9 @@ func TestNewFromStringErrs(t *testing.T) { for s, o := range tests { out, err := NewFromString(s) + assert.Error(t, err) + assert.Equal(t, o, out.String()) - if err == nil { - t.Errorf("error expected when parsing %s", s) - } - - if out.String() != o { - t.Errorf("expected %s, got %s", o, out.String()) - } } } @@ -353,11 +341,8 @@ func TestNewFromStringDeepEquals(t *testing.T) { if err1 != nil || err2 != nil { t.Errorf("error parsing strings to decimals") } + assert.Equal(t, cmp.expected, reflect.DeepEqual(d1, d2)) - if reflect.DeepEqual(d1, d2) != cmp.expected { - t.Errorf("comparison result is different from expected results for %s and %s", - cmp.str1, cmp.str2) - } } } @@ -413,11 +398,8 @@ func TestNewFromInt(t *testing.T) { for input, s := range tests { d := NewFromInt(input) - if d.String() != s { - t.Errorf("expected %s, got %s (%s, %d)", - s, d.String(), - d.value.String(), d.exp) - } + assert.Equal(t, s, d.String()) + } } @@ -499,20 +481,15 @@ func TestDecimal_RoundAndStringFixed(t *testing.T) { t.Fatal(err) } got := d.Round(test.places) - if !got.Equal(expected) { - t.Errorf("Rounding %s to %d places, got %s, expected %s", - d, test.places, got, expected) - } + assert.True(t, got.Equal(expected)) // test StringFixed if test.expectedFixed == "" { test.expectedFixed = test.expected } gotStr := d.StringFixed(test.places) - if gotStr != test.expectedFixed { - t.Errorf("(%s).StringFixed(%d): got %s, expected %s", - d, test.places, gotStr, test.expectedFixed) - } + assert.Equal(t, test.expectedFixed, gotStr) + } } @@ -541,9 +518,8 @@ func TestDecimal_Add(t *testing.T) { t.FailNow() } c := a.Add(b) - if c.String() != res { - t.Errorf("expected %s, got %s", res, c.String()) - } + assert.Equal(t, res, c.String()) + } } @@ -576,9 +552,8 @@ func TestDecimal_Sub(t *testing.T) { t.FailNow() } c := a.sub(b) - if c.String() != res { - t.Errorf("expected %s, got %s", res, c.String()) - } + assert.Equal(t, res, c.String()) + } } @@ -597,18 +572,16 @@ func TestDecimal_Neg(t *testing.T) { t.FailNow() } b := a.Neg() - if b.String() != res { - t.Errorf("expected %s, got %s", res, b.String()) - } + assert.Equal(t, res, b.String()) + } } func TestDecimal_NegFromEmpty(t *testing.T) { a := Decimal{} b := a.Neg() - if b.String() != "0" { - t.Errorf("expected %s, got %s", "0", b) - } + assert.Equal(t, "0", b.String()) + } func TestDecimal_Mul(t *testing.T) { @@ -635,16 +608,14 @@ func TestDecimal_Mul(t *testing.T) { t.FailNow() } c := a.mul(b) - if c.String() != res { - t.Errorf("expected %s, got %s", res, c.String()) - } + assert.Equal(t, res, c.String()) + } // positive scale c := New(1234, 5).mul(New(45, -1)) - if c.String() != "555300000" { - t.Errorf("Expected %s, got %s", "555300000", c.String()) - } + assert.Equal(t, "555300000", c.String()) + } func TestDecimal_Div(t *testing.T) { @@ -679,14 +650,11 @@ func TestDecimal_Div(t *testing.T) { } got := num.div(denom) expected, _ := NewFromString(expectedStr) - if !got.Equal(expected) { - t.Errorf("expected %v when dividing %v by %v, got %v", - expected, num, denom, got) - } + assert.True(t, got.Equal(expected)) + got2 := num.divRound(denom, int32(divisionPrecision)) - if !got2.Equal(expected) { - t.Errorf("expected %v on divRound (%v,%v), got %v", expected, num, denom, got2) - } + assert.True(t, got2.Equal(expected)) + } type Inp2 struct { @@ -717,10 +685,8 @@ func TestDecimal_Div(t *testing.T) { expected = "-" + expectedAbs } got := num.div(denom) - if got.String() != expected { - t.Errorf("expected %s when dividing %v by %v, got %v", - expected, num, denom, got) - } + assert.Equal(t, expected, got.String()) + } } } @@ -761,14 +727,8 @@ func TestDecimal_QuoRem(t *testing.T) { t.Errorf("bad QuoRem division %s , %s , %d got %v, %v expected %s , %s", inp4.d, inp4.d2, prec, q, r, inp4.q, inp4.r) } - if !d.Equal(d2.mul(q).Add(r)) { - t.Errorf("not fitting: d=%v, d2= %v, prec=%d, q=%v, r=%v", - d, d2, prec, q, r) - } - if !q.Equal(q.Truncate(prec)) { - t.Errorf("quotient wrong precision: d=%v, d2= %v, prec=%d, q=%v, r=%v", - d, d2, prec, q, r) - } + assert.True(t, d.Equal(d2.mul(q).Add(r))) + assert.True(t, q.Equal(q.Truncate(prec))) if r.Abs().Cmp(d2.Abs().mul(New(1, -prec))) >= 0 { t.Errorf("remainder too large: d=%v, d2= %v, prec=%d, q=%v, r=%v", d, d2, prec, q, r) @@ -823,15 +783,10 @@ func TestDecimal_QuoRem2(t *testing.T) { prec := tc.prec q, r := d.QuoRem(d2, prec) // rule 1: d = d2*q +r - if !d.Equal(d2.mul(q).Add(r)) { - t.Errorf("not fitting, d=%v, d2=%v, prec=%d, q=%v, r=%v", - d, d2, prec, q, r) - } + assert.True(t, d.Equal(d2.mul(q).Add(r))) // rule 2: q is integral multiple of 10^(-prec) - if !q.Equal(q.Truncate(prec)) { - t.Errorf("quotient wrong precision, d=%v, d2=%v, prec=%d, q=%v, r=%v", - d, d2, prec, q, r) - } + assert.True(t, q.Equal(q.Truncate(prec))) + // rule 3: abs(r)= 0 { t.Errorf("remainder too large, d=%v, d2=%v, prec=%d, q=%v, r=%v", @@ -894,9 +849,8 @@ func TestDecimal_DivRound(t *testing.T) { if x.Cmp(d2.Abs().mul(New(-1, -prec))) <= 0 { t.Errorf("wrong rounding, got: %v/%v prec=%d is about %v", d, d2, prec, q) } - if !q.Equal(result) { - t.Errorf("rounded division wrong %s / %s scale %d = %s, got %v", s.d, s.d2, prec, s.result, q) - } + assert.True(t, q.Equal(result)) + } } @@ -953,9 +907,8 @@ func TestDecimal_Mod(t *testing.T) { t.FailNow() } c := a.mod(b) - if c.String() != res { - t.Errorf("expected %s, got %s", res, c.String()) - } + assert.Equal(t, res, c.String()) + } } @@ -972,9 +925,8 @@ func TestDecimal_Overflow(t *testing.T) { func TestDecimal_Scale(t *testing.T) { a := New(1234, -3) - if a.Exponent() != -3 { - t.Errorf("error") - } + assert.EqualValues(t, -3, a.Exponent()) + } func TestDecimal_Abs1(t *testing.T) { @@ -982,9 +934,8 @@ func TestDecimal_Abs1(t *testing.T) { b := New(1234, -4) c := a.Abs() - if c.Cmp(b) != 0 { - t.Errorf("error") - } + assert.Zero(t, c.Cmp(b)) + } func TestDecimal_Abs2(t *testing.T) { @@ -992,9 +943,8 @@ func TestDecimal_Abs2(t *testing.T) { b := New(1234, -4) c := b.Abs() - if c.Cmp(a) == 0 { - t.Errorf("error") - } + assert.NotZero(t, c.Cmp(a)) + } func TestDecimal_ScalesNotEqual(t *testing.T) { @@ -1008,19 +958,15 @@ func TestDecimal_ScalesNotEqual(t *testing.T) { func TestDecimal_Cmp1(t *testing.T) { a := New(123, 3) b := New(-1234, 2) + assert.Equal(t, 1, a.Cmp(b)) - if a.Cmp(b) != 1 { - t.Errorf("Error") - } } func TestDecimal_Cmp2(t *testing.T) { a := New(123, 3) b := New(1234, 2) + assert.Equal(t, -1, a.Cmp(b)) - if a.Cmp(b) != -1 { - t.Errorf("Error") - } } func TestDecimal_IsInteger(t *testing.T) { @@ -1045,26 +991,20 @@ func TestDecimal_IsInteger(t *testing.T) { if err != nil { t.Fatal(err) } - if d.isInteger() != testCase.IsInteger { - t.Errorf("expect %t, got %t, for %s", testCase.IsInteger, d.isInteger(), testCase.Dec) - } + assert.Equal(t, testCase.IsInteger, d.isInteger()) + } } func TestDecimal_Sign(t *testing.T) { - if Zero.Sign() != 0 { - t.Errorf("%q should have sign 0", Zero) - } + assert.Zero(t, Zero.Sign()) one := New(1, 0) - if one.Sign() != 1 { - t.Errorf("%q should have sign 1", one) - } + assert.Equal(t, 1, one.Sign()) mone := New(-1, 0) - if mone.Sign() != -1 { - t.Errorf("%q should have sign -1", mone) - } + assert.Equal(t, -1, mone.Sign()) + } func didPanic(f func()) bool { diff --git a/go/streamlog/streamlog_test.go b/go/streamlog/streamlog_test.go index e653de74ea8..ab01dd4ccb2 100644 --- a/go/streamlog/streamlog_test.go +++ b/go/streamlog/streamlog_test.go @@ -315,7 +315,6 @@ func TestShouldEmitLog(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.sql, func(t *testing.T) { SetQueryLogFilterTag(tt.qLogFilterTag) SetQueryLogRowThreshold(tt.qLogRowThreshold) @@ -360,7 +359,6 @@ func TestGetFormatter(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { var buffer bytes.Buffer logFormatterFunc := GetFormatter[string](tt.logger) diff --git a/go/trace/trace_test.go b/go/trace/trace_test.go index 6b5bdf491bb..7f1f6d8c528 100644 --- a/go/trace/trace_test.go +++ b/go/trace/trace_test.go @@ -96,7 +96,6 @@ func TestNewFromString(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.label, func(t *testing.T) { span, ctx, err := NewFromString(context.Background(), tt.parent, tt.label) if tt.expectedErr == "" {