Replacing custom testing helpers with testify, where possible
This commit is contained in:
1 parent
21e07c0db9
commit
cdee7a5d6f
24 files changed
+509
-607
No files matched your search
@@ -1,10 +1,12 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
wt "github.com/weaveworks/weave/testing"
|
||||
)
|
||||
|
||||
@@ -255,7 +257,7 @@ func (g *testGossiper) checkHas(t *testing.T, vs ...byte) {
|
||||
defer g.RUnlock()
|
||||
for _, v := range vs {
|
||||
if _, found := g.state[v]; !found {
|
||||
wt.Fatalf(t, "%d is missing", v)
|
||||
require.FailNow(t, fmt.Sprintf("%d is missing", v))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -3,7 +3,7 @@ package router
|
||||
import (
|
||||
"testing"
|
||||
|
||||
wt "github.com/weaveworks/weave/testing"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestFieldValidator(t *testing.T) {
|
||||
@@ -11,20 +11,20 @@ func TestFieldValidator(t *testing.T) {
|
||||
|
||||
fv := NewFieldValidator(testMap)
|
||||
val, err := fv.Value("a")
|
||||
wt.AssertNoErr(t, err)
|
||||
wt.AssertNoErr(t, fv.Err())
|
||||
wt.AssertEqualString(t, val, "a", "")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, fv.Err())
|
||||
require.Equal(t, "a", val, "")
|
||||
_, err = fv.Value("x")
|
||||
wt.AssertFalse(t, err == nil || fv.Err() == nil, "Expected error")
|
||||
require.False(t, err == nil || fv.Err() == nil, "Expected error")
|
||||
_, err = fv.Value("a")
|
||||
wt.AssertFalse(t, err == nil || fv.Err() == nil, "Previous error should be retained")
|
||||
require.False(t, err == nil || fv.Err() == nil, "Previous error should be retained")
|
||||
|
||||
fv = NewFieldValidator(testMap)
|
||||
err = fv.CheckEqual("a", "a")
|
||||
wt.AssertNoErr(t, err)
|
||||
wt.AssertNoErr(t, fv.Err())
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, fv.Err())
|
||||
err = fv.CheckEqual("a", "b")
|
||||
wt.AssertFalse(t, err == nil || fv.Err() == nil, "Expected error")
|
||||
require.False(t, err == nil || fv.Err() == nil, "Expected error")
|
||||
err = fv.CheckEqual("a", "a")
|
||||
wt.AssertFalse(t, err == nil || fv.Err() == nil, "Previous error should be retained")
|
||||
require.False(t, err == nil || fv.Err() == nil, "Previous error should be retained")
|
||||
}
|
||||
@@ -6,9 +6,10 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
wt "github.com/weaveworks/weave/testing"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// Add to peers a connection from peers.ourself to p
|
||||
@@ -58,11 +59,11 @@ func checkEqualConns(t *testing.T, ourName PeerName, got, wanted map[PeerName]Co
|
||||
if _, found := checkConns[remoteName]; found {
|
||||
delete(checkConns, remoteName)
|
||||
} else {
|
||||
wt.Fatalf(t, "Unexpected connection from %s to %s", ourName, remoteName)
|
||||
require.FailNow(t, fmt.Sprintf("Unexpected connection from %s to %s", ourName, remoteName))
|
||||
}
|
||||
}
|
||||
if len(checkConns) > 0 {
|
||||
wt.Fatalf(t, "Expected connections not found: from %s to %v", ourName, checkConns)
|
||||
require.FailNow(t, fmt.Sprintf("Expected connections not found: from %s to %v", ourName, checkConns))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,10 +106,10 @@ func checkTopologyPeers(t *testing.T, checkConns bool, peers []*Peer, wantedPeer
|
||||
}
|
||||
delete(check, name)
|
||||
} else {
|
||||
wt.Fatalf(t, "Unexpected peer: %s", name)
|
||||
require.FailNow(t, fmt.Sprintf("Unexpected peer: %s", name))
|
||||
}
|
||||
}
|
||||
if len(check) > 0 {
|
||||
wt.Fatalf(t, "Expected peers not found: %v", check)
|
||||
require.FailNow(t, fmt.Sprintf("Expected peers not found: %v", check))
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
wt "github.com/weaveworks/weave/testing"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// TODO we should also test:
|
||||
@@ -98,14 +98,14 @@ func TestPeersGarbageCollection(t *testing.T) {
|
||||
ps2.AddTestRemoteConnection(p3, p1)
|
||||
|
||||
// Every peer is referenced, so nothing should be dropped
|
||||
wt.AssertEmpty(t, ps1.GarbageCollect(), "peers removed")
|
||||
wt.AssertEmpty(t, ps2.GarbageCollect(), "peers removed")
|
||||
wt.AssertEmpty(t, ps3.GarbageCollect(), "peers removed")
|
||||
require.Empty(t, ps1.GarbageCollect(), "peers removed")
|
||||
require.Empty(t, ps2.GarbageCollect(), "peers removed")
|
||||
require.Empty(t, ps3.GarbageCollect(), "peers removed")
|
||||
|
||||
// Drop the connection from 2 to 3, and 3 isn't garbage-collected
|
||||
// because 1 has a connection to 3
|
||||
ps2.DeleteTestConnection(p3)
|
||||
wt.AssertEmpty(t, ps2.GarbageCollect(), "peers removed")
|
||||
require.Empty(t, ps2.GarbageCollect(), "peers removed")
|
||||
|
||||
// Drop the connection from 1 to 3, and 3 will get removed by
|
||||
// garbage-collection
|
||||
|
||||
Reference in new issue
Block a user