Skip to content

Commit

Permalink
change to gotest.tools for test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
dropwhile committed May 29, 2021
1 parent b2b8193 commit ced5e47
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 37 deletions.
10 changes: 6 additions & 4 deletions chrono/chrono_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/assert/opt"
)

func TestTimeNow(t *testing.T) {
Expand All @@ -18,7 +20,7 @@ func TestTimeNow(t *testing.T) {

now := time.Now().UTC()
cnow := time.Unix(c.Get(), 0)
assert.WithinDuration(t, now, cnow, 2*time.Second)
assert.Assert(t, is.DeepEqual(now, cnow, opt.TimeWithThreshold(2*time.Second)))
}

func BenchmarkTimeNow(b *testing.B) {
Expand All @@ -39,7 +41,7 @@ func TestTimeNowString(t *testing.T) {

now := time.Now().UTC().Format("Mon, 02 Jan 2006 15:04 GMT")
cnow := c.String()
assert.Equal(t, now, cnow)
assert.Check(t, is.Equal(now, cnow))
}

func TestTimeNowStringDelay(t *testing.T) {
Expand All @@ -51,7 +53,7 @@ func TestTimeNowStringDelay(t *testing.T) {
c.Update()
l := c.String()

assert.NotEqual(t, n, l,
assert.Check(t, n != l,
"Date did not update as expected: %s == %s", n, l)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/cactus/go-misc

go 1.12

require github.com/stretchr/testify v1.3.0
require gotest.tools/v3 v3.0.3
22 changes: 15 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
35 changes: 18 additions & 17 deletions set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ package set
import (
"testing"

"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

func TestHashSetAdd(t *testing.T) {
t.Parallel()
s := NewHashSet(nil)
s.Add("btest")
s.Add("atest")
assert.Equal(t, []string{"atest", "btest"}, s.Items())
assert.Check(t, is.DeepEqual([]string{"atest", "btest"}, s.Items()))
}

func TestHashSetDuplicateAdd(t *testing.T) {
Expand All @@ -25,48 +26,48 @@ func TestHashSetDuplicateAdd(t *testing.T) {
s.Add("atest")
s.Add("atest")
s.Add("btest")
assert.Equal(t, []string{"atest", "btest"}, s.Items())
assert.Check(t, is.DeepEqual([]string{"atest", "btest"}, s.Items()))
}

func TestHashSetNewAdd(t *testing.T) {
t.Parallel()
s := NewHashSet([]string{"btest", "atest"})
assert.Equal(t, []string{"atest", "btest"}, s.Items())
assert.Check(t, is.DeepEqual([]string{"atest", "btest"}, s.Items()))
}

func TestHashSetDelete(t *testing.T) {
t.Parallel()
s := NewHashSet([]string{"btest", "atest"})
s.Del("btest")
assert.Equal(t, []string{"atest"}, s.Items())
assert.Check(t, is.DeepEqual([]string{"atest"}, s.Items()))
}

func TestHashSetClear(t *testing.T) {
t.Parallel()
s := NewHashSet([]string{"btest", "atest"})
s.Clear()
assert.Equal(t, []string{}, s.Items())
assert.Equal(t, 0, s.Count())
assert.Check(t, is.DeepEqual([]string{}, s.Items()))
assert.Check(t, is.Equal(0, s.Count()))
}

func TestHashSetCount(t *testing.T) {
t.Parallel()
s := NewHashSet([]string{"btest", "atest"})
assert.Equal(t, 2, s.Count())
assert.Check(t, is.Equal(2, s.Count()))
s.Add("ctest")
assert.Equal(t, 3, s.Count())
assert.Check(t, is.Equal(3, s.Count()))
s.Del("ctest")
assert.Equal(t, 2, s.Count())
assert.Check(t, is.Equal(2, s.Count()))
s.Clear()
assert.Equal(t, 0, s.Count())
assert.Check(t, is.Equal(0, s.Count()))
}

func TestHashSetContains(t *testing.T) {
t.Parallel()
s := NewHashSet([]string{"btest", "atest"})
assert.Equal(t, true, s.Contains("atest"))
assert.Equal(t, true, s.Contains("btest"))
assert.Equal(t, false, s.Contains("ctest"))
assert.Check(t, is.Equal(true, s.Contains("atest")))
assert.Check(t, is.Equal(true, s.Contains("btest")))
assert.Check(t, is.Equal(false, s.Contains("ctest")))
}

func TestHashSetUnion(t *testing.T) {
Expand All @@ -76,7 +77,7 @@ func TestHashSetUnion(t *testing.T) {
c := a.Union(b)

items := c.Items()
assert.Equal(t, items, []string{"1", "2", "3", "4", "5"})
assert.Check(t, is.DeepEqual(items, []string{"1", "2", "3", "4", "5"}))
}

func TestHashSetIntersection(t *testing.T) {
Expand All @@ -86,7 +87,7 @@ func TestHashSetIntersection(t *testing.T) {
c := a.Intersection(b)

items := c.Items()
assert.Equal(t, items, []string{"3"})
assert.Check(t, is.DeepEqual(items, []string{"3"}))
}

func TestHashSetDifference(t *testing.T) {
Expand All @@ -96,5 +97,5 @@ func TestHashSetDifference(t *testing.T) {
c := a.Difference(b)

items := c.Items()
assert.Equal(t, items, []string{"1", "2"})
assert.Check(t, is.DeepEqual(items, []string{"1", "2"}))
}
17 changes: 9 additions & 8 deletions tally/tally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ import (
"sync"
"testing"

"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

func TestTally(t *testing.T) {
t.Parallel()
c := &Tally{}
assert.Equal(t, uint64(0), c.Get())
assert.Check(t, is.Equal(uint64(0), c.Get()))
c.Inc()
assert.Equal(t, uint64(1), c.Get())
assert.Check(t, is.Equal(uint64(1), c.Get()))
c.Inc()
assert.Equal(t, uint64(2), c.Get())
assert.Check(t, is.Equal(uint64(2), c.Get()))
c.Set(42)
assert.Equal(t, uint64(42), c.Get())
assert.Check(t, is.Equal(uint64(42), c.Get()))
c.Reset()
assert.Equal(t, uint64(0), c.Get())
assert.Check(t, is.Equal(uint64(0), c.Get()))
c.Inc()
assert.Equal(t, uint64(1), c.Get())
assert.Check(t, is.Equal(uint64(1), c.Get()))
}

func TestTallyConcurrent(t *testing.T) {
Expand All @@ -49,5 +50,5 @@ func TestTallyConcurrent(t *testing.T) {
x = append(x, int(y))
}
sort.Ints(x)
assert.Equal(t, []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, x)
assert.Check(t, is.DeepEqual([]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, x))
}

0 comments on commit ced5e47

Please sign in to comment.