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:
@@ -23,7 +23,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
|
||||
evictionapi "k8s.io/kubernetes/pkg/kubelet/eviction/api"
|
||||
@@ -130,18 +129,15 @@ func TestUpdateThreshold(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
notifierFactory := NewMockNotifierFactory(mockCtrl)
|
||||
notifier := NewMockCgroupNotifier(mockCtrl)
|
||||
notifierFactory := NewMockNotifierFactory(t)
|
||||
notifier := NewMockCgroupNotifier(t)
|
||||
|
||||
m := newTestMemoryThresholdNotifier(tc.evictionThreshold, notifierFactory, nil)
|
||||
notifierFactory.EXPECT().NewCgroupNotifier(testCgroupPath, memoryUsageAttribute, tc.expectedThreshold.Value()).Return(notifier, tc.updateThresholdErr).Times(1)
|
||||
var events chan<- struct{} = m.events
|
||||
notifier.EXPECT().Start(events).Return().AnyTimes()
|
||||
notifier.EXPECT().Start(events).Return().Maybe()
|
||||
err := m.UpdateThreshold(nodeSummary(tc.available, tc.workingSet, tc.usage, isAllocatableEvictionThreshold(tc.evictionThreshold)))
|
||||
if err != nil && !tc.expectErr {
|
||||
t.Errorf("Unexpected error updating threshold: %v", err)
|
||||
@@ -161,10 +157,8 @@ func TestStart(t *testing.T) {
|
||||
Quantity: &noResources,
|
||||
},
|
||||
}
|
||||
mockCtrl := gomock.NewController(t)
|
||||
defer mockCtrl.Finish()
|
||||
notifierFactory := NewMockNotifierFactory(mockCtrl)
|
||||
notifier := NewMockCgroupNotifier(mockCtrl)
|
||||
notifierFactory := NewMockNotifierFactory(t)
|
||||
notifier := NewMockCgroupNotifier(t)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(4)
|
||||
@@ -174,7 +168,7 @@ func TestStart(t *testing.T) {
|
||||
notifierFactory.EXPECT().NewCgroupNotifier(testCgroupPath, memoryUsageAttribute, int64(0)).Return(notifier, nil).Times(1)
|
||||
|
||||
var events chan<- struct{} = m.events
|
||||
notifier.EXPECT().Start(events).DoAndReturn(func(events chan<- struct{}) {
|
||||
notifier.EXPECT().Start(events).Run(func(events chan<- struct{}) {
|
||||
for i := 0; i < 4; i++ {
|
||||
events <- struct{}{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user