From 6876ee10f6fcede51ef42bce2c5fc02998dc0220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20S=C3=B6derlund?= Date: Tue, 21 Jul 2020 21:15:59 +0200 Subject: [PATCH] chore: migrate from testify to gotest Works better with protobuf comparisons. --- go.mod | 2 +- go.sum | 6 ++++++ pkg/external/clock_test.go | 41 +++++++++++++++++++------------------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index e3504c0..7de7ce3 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.13 require ( github.com/golang/mock v1.3.1 github.com/golang/protobuf v1.3.2 - github.com/stretchr/testify v1.4.0 go.uber.org/zap v1.13.0 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e + gotest.tools/v3 v3.0.2 ) diff --git a/go.sum b/go.sum index 5518b71..8f1c24a 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,8 @@ github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -19,6 +21,7 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= @@ -50,6 +53,7 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190425150028-36563e24a262 h1:qsl9y/CJx34tuA7QCPNp86JNJe4spst6Ff8MjvPUdPg= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -60,5 +64,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E= +gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= diff --git a/pkg/external/clock_test.go b/pkg/external/clock_test.go index 626e978..f89aec0 100644 --- a/pkg/external/clock_test.go +++ b/pkg/external/clock_test.go @@ -6,9 +6,10 @@ import ( "time" "github.com/golang/protobuf/ptypes" - "github.com/stretchr/testify/require" "go.uber.org/zap" "golang.org/x/sync/errgroup" + "gotest.tools/v3/assert" + is "gotest.tools/v3/assert/cmp" ) func TestExternalClock_NewTicker(t *testing.T) { @@ -21,7 +22,7 @@ func TestExternalClock_NewTicker(t *testing.T) { defer loopTicker.Stop() // should find a new one. - require.Len(t, externalClock.tickers, 1) + assert.Assert(t, is.Len(externalClock.tickers, 1)) } func TestExternalClock_Stop(t *testing.T) { @@ -37,14 +38,14 @@ func TestExternalClock_Stop(t *testing.T) { loopTicks := loopTicker.C() nanoTime, _ := ptypes.TimestampProto(time.Unix(0, tickTime.Nanoseconds()+1)) err := externalClock.SetTimestamp(nanoTime) - require.NoError(t, err) + assert.NilError(t, err) didSet := false select { case <-time.After(1 * time.Millisecond): case <-loopTicks: didSet = true } - require.False(t, didSet) + assert.Assert(t, !didSet) } func TestExternalClock_RemoveTicker(t *testing.T) { @@ -58,7 +59,7 @@ func TestExternalClock_RemoveTicker(t *testing.T) { loopTicker.Stop() // should be empty - require.Len(t, externalClock.tickers, 0, "should be empty %+v", externalClock.tickers) + assert.Assert(t, is.Len(externalClock.tickers, 0), "should be empty %+v", externalClock.tickers) } func TestExternalClock_Tick(t *testing.T) { @@ -71,7 +72,7 @@ func TestExternalClock_Tick(t *testing.T) { // Send a tick tickTimeProto, _ := ptypes.TimestampProto(time.Unix(0, tickTime.Nanoseconds())) err := externalClock.SetTimestamp(tickTimeProto) - require.NoError(t, err) + assert.NilError(t, err) // exect didSet to be true didSet := false @@ -81,7 +82,7 @@ func TestExternalClock_Tick(t *testing.T) { case <-loopTicks: didSet = true } - require.True(t, didSet) + assert.Assert(t, didSet) } func TestExternalClock_After(t *testing.T) { @@ -94,7 +95,7 @@ func TestExternalClock_After(t *testing.T) { // Send a tick tickTimeProto, _ := ptypes.TimestampProto(time.Unix(0, tickTime.Nanoseconds()+1)) err := externalClock.SetTimestamp(tickTimeProto) - require.NoError(t, err) + assert.NilError(t, err) // exect didSet to be true didSet := false @@ -104,7 +105,7 @@ func TestExternalClock_After(t *testing.T) { case <-afterChan: didSet = true } - require.True(t, didSet) + assert.Assert(t, didSet) } func TestExternalClock_Removed(t *testing.T) { @@ -117,14 +118,14 @@ func TestExternalClock_Removed(t *testing.T) { // Send a tick tickTimeProto, _ := ptypes.TimestampProto(time.Unix(0, tickTime.Nanoseconds())) err := externalClock.SetTimestamp(tickTimeProto) - require.NoError(t, err) + assert.NilError(t, err) // exect didSet to be true select { case <-time.After(2 * time.Millisecond): t.FailNow() case <-afterChan: - require.Len(t, externalClock.tickers, 0) + assert.Assert(t, is.Len(externalClock.tickers, 0)) } } @@ -138,7 +139,7 @@ func TestExternalClock_AfterFailToShortTime(t *testing.T) { // Send a tick tickTimeProto, _ := ptypes.TimestampProto(time.Unix(0, 0)) err := externalClock.SetTimestamp(tickTimeProto) - require.NoError(t, err) + assert.NilError(t, err) // exect didSet to be true select { @@ -159,7 +160,7 @@ func TestExternalClock_NewTicker_Tick_Periodically(t *testing.T) { for i := range make([]int64, 1000) { tickTimeProto, _ := ptypes.TimestampProto(time.Unix(0, int64(i+1)*tickTime.Nanoseconds()+1)) err := externalClock.SetTimestamp(tickTimeProto) - require.NoError(t, err) + assert.NilError(t, err) // exect didSet to be true didSet := false @@ -169,7 +170,7 @@ func TestExternalClock_NewTicker_Tick_Periodically(t *testing.T) { case <-loopTicks: didSet = true } - require.True(t, didSet) + assert.Assert(t, didSet) } } @@ -188,7 +189,7 @@ func TestExternalClock_TestLooper(t *testing.T) { } else { tickProto, _ := ptypes.TimestampProto(time.Unix(0, (tick+1)*time.Millisecond.Nanoseconds())) err := externalClock.SetTimestamp(tickProto) - require.NoError(t, err) + assert.NilError(t, err) } }, } @@ -199,10 +200,10 @@ func TestExternalClock_TestLooper(t *testing.T) { <-looper.init tickProto, _ := ptypes.TimestampProto(time.Unix(0, 1*time.Millisecond.Nanoseconds())) err := externalClock.SetTimestamp(tickProto) - require.NoError(t, err) + assert.NilError(t, err) err = g.Wait() - require.NoError(t, err) - require.Equal(t, looper.Target, looper.counter) + assert.NilError(t, err) + assert.Equal(t, looper.Target, looper.counter) } func TestExternalClock_TestLooper_AddTicker(t *testing.T) { @@ -223,9 +224,9 @@ func TestExternalClock_TestLooper_AddTicker(t *testing.T) { <-looper.init tickProto, _ := ptypes.TimestampProto(time.Unix(0, 1*time.Millisecond.Nanoseconds()+1)) err := externalClock.SetTimestamp(tickProto) - require.NoError(t, err) + assert.NilError(t, err) err = g.Wait() - require.NoError(t, err) + assert.NilError(t, err) } type testLooper struct {