Switch to stretchr/testify / mockery for mocks
testify is used throughout the codebase; this switches mocks from gomock to testify with the help of mockery for code generation. Handlers and mocks in test/utils/oidc are moved to a new package: mockery operates package by package, and requires packages to build correctly; test/utils/oidc/testserver.go relies on the mocks and fails to build when they are removed. Moving the interface and mocks to a different package allows mockery to process that package without having to build testserver.go. Signed-off-by: Stephen Kitt <skitt@redhat.com>
This commit is contained in:
@@ -28,7 +28,6 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uber.org/mock/gomock"
|
||||
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/component-base/metrics/testutil"
|
||||
@@ -352,15 +351,13 @@ func createTestPodsStatusesAndEvents(num int) ([]*kubecontainer.Pod, []*kubecont
|
||||
|
||||
func TestRelistWithCache(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
runtimeMock := containertest.NewMockRuntime(mockCtrl)
|
||||
runtimeMock := containertest.NewMockRuntime(t)
|
||||
|
||||
pleg := newTestGenericPLEGWithRuntimeMock(runtimeMock)
|
||||
ch := pleg.Watch()
|
||||
|
||||
pods, statuses, events := createTestPodsStatusesAndEvents(2)
|
||||
runtimeMock.EXPECT().GetPods(ctx, true).Return(pods, nil).AnyTimes()
|
||||
runtimeMock.EXPECT().GetPods(ctx, true).Return(pods, nil).Maybe()
|
||||
runtimeMock.EXPECT().GetPodStatus(ctx, pods[0].ID, "", "").Return(statuses[0], nil).Times(1)
|
||||
// Inject an error when querying runtime for the pod status for pods[1].
|
||||
statusErr := fmt.Errorf("unable to get status")
|
||||
@@ -409,9 +406,7 @@ func TestRelistWithCache(t *testing.T) {
|
||||
|
||||
func TestRemoveCacheEntry(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
runtimeMock := containertest.NewMockRuntime(mockCtrl)
|
||||
runtimeMock := containertest.NewMockRuntime(t)
|
||||
pleg := newTestGenericPLEGWithRuntimeMock(runtimeMock)
|
||||
|
||||
pods, statuses, _ := createTestPodsStatusesAndEvents(1)
|
||||
@@ -457,9 +452,7 @@ func TestHealthy(t *testing.T) {
|
||||
|
||||
func TestRelistWithReinspection(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
runtimeMock := containertest.NewMockRuntime(mockCtrl)
|
||||
runtimeMock := containertest.NewMockRuntime(t)
|
||||
|
||||
pleg := newTestGenericPLEGWithRuntimeMock(runtimeMock)
|
||||
ch := pleg.Watch()
|
||||
@@ -613,11 +606,8 @@ func TestRelistIPChange(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
for _, tc := range testCases {
|
||||
runtimeMock := containertest.NewMockRuntime(mockCtrl)
|
||||
runtimeMock := containertest.NewMockRuntime(t)
|
||||
|
||||
pleg := newTestGenericPLEGWithRuntimeMock(runtimeMock)
|
||||
ch := pleg.Watch()
|
||||
|
||||
Reference in New Issue
Block a user