Skip to content

Commit

Permalink
chore: migrate from testify to gotest
Browse files Browse the repository at this point in the history
Works better with protobuf comparisons.
  • Loading branch information
odsod committed Jul 21, 2020
1 parent c53c481 commit 6876ee1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
41 changes: 21 additions & 20 deletions pkg/external/clock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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))
}
}

Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -169,7 +170,7 @@ func TestExternalClock_NewTicker_Tick_Periodically(t *testing.T) {
case <-loopTicks:
didSet = true
}
require.True(t, didSet)
assert.Assert(t, didSet)
}
}

Expand All @@ -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)
}
},
}
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit 6876ee1

Please sign in to comment.