Replace testify with gotest.tools (#553)
* vendor gotest.tools * Run gotest.tools migration tools * Fixup tests that were improperly converted * Remove unused testify package vendors
This commit is contained in:
52
providers/vic/cache/pod_cache_test.go
vendored
52
providers/vic/cache/pod_cache_test.go
vendored
@@ -4,15 +4,16 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/virtual-kubelet/virtual-kubelet/providers/vic/pod"
|
||||
"k8s.io/api/core/v1"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
|
||||
"github.com/vmware/vic/pkg/trace"
|
||||
)
|
||||
|
||||
var (
|
||||
testpod *v1.Pod
|
||||
testpod *v1.Pod
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -21,11 +22,11 @@ func init() {
|
||||
|
||||
func setup(t *testing.T, op trace.Operation) PodCache {
|
||||
c := NewVicPodCache()
|
||||
assert.NotNil(t, c, "NewPod did not return a valid cache")
|
||||
assert.Check(t, c != nil, "NewPod did not return a valid cache")
|
||||
|
||||
//populate with dummy data
|
||||
vp := pod.VicPod{
|
||||
ID: "123",
|
||||
ID: "123",
|
||||
Pod: testpod,
|
||||
}
|
||||
c.Add(op, "namespace1", "testpod1a", &vp)
|
||||
@@ -40,10 +41,10 @@ func TestRehydrate(t *testing.T) {
|
||||
op := trace.NewOperation(context.Background(), "")
|
||||
|
||||
c := NewVicPodCache()
|
||||
assert.NotNil(t, c, "NewPod did not return a valid cache")
|
||||
assert.Check(t, c != nil, "NewPod did not return a valid cache")
|
||||
|
||||
err := c.Rehydrate(op)
|
||||
assert.Nil(t, err, "PodCache.Rehydrate failed with error: %s", err)
|
||||
assert.Check(t, err, "PodCache.Rehydrate failed with error: %s", err)
|
||||
}
|
||||
|
||||
func TestAdd(t *testing.T) {
|
||||
@@ -51,26 +52,26 @@ func TestAdd(t *testing.T) {
|
||||
op := trace.NewOperation(context.Background(), "")
|
||||
|
||||
c := NewVicPodCache()
|
||||
assert.NotNil(t, c, "NewPod did not return a valid cache")
|
||||
assert.Check(t, c != nil, "NewPod did not return a valid cache")
|
||||
|
||||
//populate with dummy data
|
||||
vp := pod.VicPod{
|
||||
ID: "123",
|
||||
ID: "123",
|
||||
Pod: testpod,
|
||||
}
|
||||
|
||||
// Positive cases
|
||||
err = c.Add(op, "namespace1", "testpod1a", &vp)
|
||||
assert.Nil(t, err, "PodCache.Add failed with error: %s", err)
|
||||
assert.Check(t, err, "PodCache.Add failed with error: %s", err)
|
||||
|
||||
// Negative cases
|
||||
err = c.Add(op, "namespace1", "", &vp)
|
||||
assert.NotNil(t, err, "PodCache.Add expected error for empty name")
|
||||
assert.Equal(t, err, PodCachePodNameError)
|
||||
assert.Check(t, err != nil, "PodCache.Add expected error for empty name")
|
||||
assert.Check(t, is.DeepEqual(err, PodCachePodNameError))
|
||||
|
||||
err = c.Add(op, "namespace1", "test2", nil)
|
||||
assert.NotNil(t, err, "PodCache.Add expected error for nil pod")
|
||||
assert.Equal(t, err, PodCacheNilPodError)
|
||||
assert.Check(t, err != nil, "PodCache.Add expected error for nil pod")
|
||||
assert.Check(t, is.DeepEqual(err, PodCacheNilPodError))
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
@@ -82,17 +83,17 @@ func TestGet(t *testing.T) {
|
||||
|
||||
// Positive cases
|
||||
vpod, err = c.Get(op, "namespace1", "testpod1a")
|
||||
assert.Nil(t, err, "PodCache.Get failed with error: %s", err)
|
||||
assert.NotNil(t, vpod, "PodCache.Get expected to return non-nil pod but received nil")
|
||||
assert.Check(t, err, "PodCache.Get failed with error: %s", err)
|
||||
assert.Check(t, vpod != nil, "PodCache.Get expected to return non-nil pod but received nil")
|
||||
|
||||
vpod, err = c.Get(op, "namespace2", "testpod2a")
|
||||
assert.Nil(t, err, "PodCache.Get failed with error: %s", err)
|
||||
assert.NotNil(t, vpod, "PodCache.Get expected to return non-nil pod but received nil")
|
||||
assert.Check(t, err, "PodCache.Get failed with error: %s", err)
|
||||
assert.Check(t, vpod != nil, "PodCache.Get expected to return non-nil pod but received nil")
|
||||
|
||||
// Negative cases
|
||||
vpod, err = c.Get(op, "namespace1", "")
|
||||
assert.Equal(t, err, PodCachePodNameError)
|
||||
assert.Nil(t, vpod, "PodCache.Get expected to return nil pod but received non-nil")
|
||||
assert.Check(t, is.DeepEqual(err, PodCachePodNameError))
|
||||
assert.Check(t, is.Nil(vpod), "PodCache.Get expected to return nil pod but received non-nil")
|
||||
|
||||
//TODO: uncomment out once namespace support added to cache
|
||||
//vpod, err = c.Get(op, "namespace1", "testpod2a")
|
||||
@@ -108,8 +109,8 @@ func TestGetAll(t *testing.T) {
|
||||
c := setup(t, op)
|
||||
|
||||
vps := c.GetAll(op)
|
||||
assert.NotNil(t, vps, "PodCache.GetAll returned nil slice")
|
||||
assert.Len(t, vps, 4, "PodCache.Get did not return all pod definitions. Returned %d pods.", len(vps))
|
||||
assert.Check(t, vps != nil, "PodCache.GetAll returned nil slice")
|
||||
assert.Check(t, is.Len(vps, 4), "PodCache.Get did not return all pod definitions. Returned %d pods.", len(vps))
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
@@ -120,13 +121,13 @@ func TestDelete(t *testing.T) {
|
||||
|
||||
// Positive cases
|
||||
err = c.Delete(op, "namespace1", "testpod1a")
|
||||
assert.Nil(t, err, "PodCache.Delete failed with error: %s", err)
|
||||
assert.Check(t, err, "PodCache.Delete failed with error: %s", err)
|
||||
vps := c.GetAll(op)
|
||||
assert.Len(t, vps, 3, "PodCache.Delete did not delete pod.")
|
||||
assert.Check(t, is.Len(vps, 3), "PodCache.Delete did not delete pod.")
|
||||
|
||||
// Negative cases
|
||||
err = c.Delete(op, "namespace2", "")
|
||||
assert.Equal(t, err, PodCachePodNameError)
|
||||
assert.Check(t, is.DeepEqual(err, PodCachePodNameError))
|
||||
|
||||
//TODO: uncomment the tests below once namespace support added to cache
|
||||
//vps = c.GetAll(op)
|
||||
@@ -136,4 +137,3 @@ func TestDelete(t *testing.T) {
|
||||
//vps = c.GetAll(op)
|
||||
//assert.Len(t, vps, currCount, "PodCache.Delete ignored namespace")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user