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:
Stephen Kitt
2024-06-04 19:29:42 +02:00
parent 78377c4d10
commit 3f36c83c68
97 changed files with 12593 additions and 5640 deletions

View File

@@ -14,373 +14,161 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
// Code generated by MockGen. DO NOT EDIT.
// Source: types.go
//
// Generated by this command:
//
// mockgen -source=types.go -destination=mock_threshold_notifier_test.go -package=eviction NotifierFactory,ThresholdNotifier
//
// Code generated by mockery v2.40.3. DO NOT EDIT.
// Package eviction is a generated GoMock package.
package eviction
import (
context "context"
reflect "reflect"
time "time"
gomock "go.uber.org/mock/gomock"
mock "github.com/stretchr/testify/mock"
v1alpha1 "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
)
// MockManager is a mock of Manager interface.
type MockManager struct {
ctrl *gomock.Controller
recorder *MockManagerMockRecorder
}
// MockManagerMockRecorder is the mock recorder for MockManager.
type MockManagerMockRecorder struct {
mock *MockManager
}
// NewMockManager creates a new mock instance.
func NewMockManager(ctrl *gomock.Controller) *MockManager {
mock := &MockManager{ctrl: ctrl}
mock.recorder = &MockManagerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockManager) EXPECT() *MockManagerMockRecorder {
return m.recorder
}
// IsUnderDiskPressure mocks base method.
func (m *MockManager) IsUnderDiskPressure() bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsUnderDiskPressure")
ret0, _ := ret[0].(bool)
return ret0
}
// IsUnderDiskPressure indicates an expected call of IsUnderDiskPressure.
func (mr *MockManagerMockRecorder) IsUnderDiskPressure() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsUnderDiskPressure", reflect.TypeOf((*MockManager)(nil).IsUnderDiskPressure))
}
// IsUnderMemoryPressure mocks base method.
func (m *MockManager) IsUnderMemoryPressure() bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsUnderMemoryPressure")
ret0, _ := ret[0].(bool)
return ret0
}
// IsUnderMemoryPressure indicates an expected call of IsUnderMemoryPressure.
func (mr *MockManagerMockRecorder) IsUnderMemoryPressure() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsUnderMemoryPressure", reflect.TypeOf((*MockManager)(nil).IsUnderMemoryPressure))
}
// IsUnderPIDPressure mocks base method.
func (m *MockManager) IsUnderPIDPressure() bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsUnderPIDPressure")
ret0, _ := ret[0].(bool)
return ret0
}
// IsUnderPIDPressure indicates an expected call of IsUnderPIDPressure.
func (mr *MockManagerMockRecorder) IsUnderPIDPressure() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsUnderPIDPressure", reflect.TypeOf((*MockManager)(nil).IsUnderPIDPressure))
}
// Start mocks base method.
func (m *MockManager) Start(diskInfoProvider DiskInfoProvider, podFunc ActivePodsFunc, podCleanedUpFunc PodCleanedUpFunc, monitoringInterval time.Duration) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Start", diskInfoProvider, podFunc, podCleanedUpFunc, monitoringInterval)
}
// Start indicates an expected call of Start.
func (mr *MockManagerMockRecorder) Start(diskInfoProvider, podFunc, podCleanedUpFunc, monitoringInterval any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockManager)(nil).Start), diskInfoProvider, podFunc, podCleanedUpFunc, monitoringInterval)
}
// MockDiskInfoProvider is a mock of DiskInfoProvider interface.
type MockDiskInfoProvider struct {
ctrl *gomock.Controller
recorder *MockDiskInfoProviderMockRecorder
}
// MockDiskInfoProviderMockRecorder is the mock recorder for MockDiskInfoProvider.
type MockDiskInfoProviderMockRecorder struct {
mock *MockDiskInfoProvider
}
// NewMockDiskInfoProvider creates a new mock instance.
func NewMockDiskInfoProvider(ctrl *gomock.Controller) *MockDiskInfoProvider {
mock := &MockDiskInfoProvider{ctrl: ctrl}
mock.recorder = &MockDiskInfoProviderMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockDiskInfoProvider) EXPECT() *MockDiskInfoProviderMockRecorder {
return m.recorder
}
// HasDedicatedImageFs mocks base method.
func (m *MockDiskInfoProvider) HasDedicatedImageFs(ctx context.Context) (bool, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "HasDedicatedImageFs", ctx)
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// HasDedicatedImageFs indicates an expected call of HasDedicatedImageFs.
func (mr *MockDiskInfoProviderMockRecorder) HasDedicatedImageFs(ctx any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HasDedicatedImageFs", reflect.TypeOf((*MockDiskInfoProvider)(nil).HasDedicatedImageFs), ctx)
}
// MockImageGC is a mock of ImageGC interface.
type MockImageGC struct {
ctrl *gomock.Controller
recorder *MockImageGCMockRecorder
}
// MockImageGCMockRecorder is the mock recorder for MockImageGC.
type MockImageGCMockRecorder struct {
mock *MockImageGC
}
// NewMockImageGC creates a new mock instance.
func NewMockImageGC(ctrl *gomock.Controller) *MockImageGC {
mock := &MockImageGC{ctrl: ctrl}
mock.recorder = &MockImageGCMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockImageGC) EXPECT() *MockImageGCMockRecorder {
return m.recorder
}
// DeleteUnusedImages mocks base method.
func (m *MockImageGC) DeleteUnusedImages(ctx context.Context) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DeleteUnusedImages", ctx)
ret0, _ := ret[0].(error)
return ret0
}
// DeleteUnusedImages indicates an expected call of DeleteUnusedImages.
func (mr *MockImageGCMockRecorder) DeleteUnusedImages(ctx any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteUnusedImages", reflect.TypeOf((*MockImageGC)(nil).DeleteUnusedImages), ctx)
}
// MockContainerGC is a mock of ContainerGC interface.
type MockContainerGC struct {
ctrl *gomock.Controller
recorder *MockContainerGCMockRecorder
}
// MockContainerGCMockRecorder is the mock recorder for MockContainerGC.
type MockContainerGCMockRecorder struct {
mock *MockContainerGC
}
// NewMockContainerGC creates a new mock instance.
func NewMockContainerGC(ctrl *gomock.Controller) *MockContainerGC {
mock := &MockContainerGC{ctrl: ctrl}
mock.recorder = &MockContainerGCMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockContainerGC) EXPECT() *MockContainerGCMockRecorder {
return m.recorder
}
// DeleteAllUnusedContainers mocks base method.
func (m *MockContainerGC) DeleteAllUnusedContainers(ctx context.Context) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DeleteAllUnusedContainers", ctx)
ret0, _ := ret[0].(error)
return ret0
}
// DeleteAllUnusedContainers indicates an expected call of DeleteAllUnusedContainers.
func (mr *MockContainerGCMockRecorder) DeleteAllUnusedContainers(ctx any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteAllUnusedContainers", reflect.TypeOf((*MockContainerGC)(nil).DeleteAllUnusedContainers), ctx)
}
// IsContainerFsSeparateFromImageFs mocks base method.
func (m *MockContainerGC) IsContainerFsSeparateFromImageFs(ctx context.Context) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsContainerFsSeparateFromImageFs", ctx)
ret0, _ := ret[0].(bool)
return ret0
}
// IsContainerFsSeparateFromImageFs indicates an expected call of IsContainerFsSeparateFromImageFs.
func (mr *MockContainerGCMockRecorder) IsContainerFsSeparateFromImageFs(ctx any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsContainerFsSeparateFromImageFs", reflect.TypeOf((*MockContainerGC)(nil).IsContainerFsSeparateFromImageFs), ctx)
}
// MockCgroupNotifier is a mock of CgroupNotifier interface.
type MockCgroupNotifier struct {
ctrl *gomock.Controller
recorder *MockCgroupNotifierMockRecorder
}
// MockCgroupNotifierMockRecorder is the mock recorder for MockCgroupNotifier.
type MockCgroupNotifierMockRecorder struct {
mock *MockCgroupNotifier
}
// NewMockCgroupNotifier creates a new mock instance.
func NewMockCgroupNotifier(ctrl *gomock.Controller) *MockCgroupNotifier {
mock := &MockCgroupNotifier{ctrl: ctrl}
mock.recorder = &MockCgroupNotifierMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockCgroupNotifier) EXPECT() *MockCgroupNotifierMockRecorder {
return m.recorder
}
// Start mocks base method.
func (m *MockCgroupNotifier) Start(eventCh chan<- struct{}) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Start", eventCh)
}
// Start indicates an expected call of Start.
func (mr *MockCgroupNotifierMockRecorder) Start(eventCh any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockCgroupNotifier)(nil).Start), eventCh)
}
// Stop mocks base method.
func (m *MockCgroupNotifier) Stop() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Stop")
}
// Stop indicates an expected call of Stop.
func (mr *MockCgroupNotifierMockRecorder) Stop() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockCgroupNotifier)(nil).Stop))
}
// MockNotifierFactory is a mock of NotifierFactory interface.
type MockNotifierFactory struct {
ctrl *gomock.Controller
recorder *MockNotifierFactoryMockRecorder
}
// MockNotifierFactoryMockRecorder is the mock recorder for MockNotifierFactory.
type MockNotifierFactoryMockRecorder struct {
mock *MockNotifierFactory
}
// NewMockNotifierFactory creates a new mock instance.
func NewMockNotifierFactory(ctrl *gomock.Controller) *MockNotifierFactory {
mock := &MockNotifierFactory{ctrl: ctrl}
mock.recorder = &MockNotifierFactoryMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockNotifierFactory) EXPECT() *MockNotifierFactoryMockRecorder {
return m.recorder
}
// NewCgroupNotifier mocks base method.
func (m *MockNotifierFactory) NewCgroupNotifier(path, attribute string, threshold int64) (CgroupNotifier, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NewCgroupNotifier", path, attribute, threshold)
ret0, _ := ret[0].(CgroupNotifier)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// NewCgroupNotifier indicates an expected call of NewCgroupNotifier.
func (mr *MockNotifierFactoryMockRecorder) NewCgroupNotifier(path, attribute, threshold any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewCgroupNotifier", reflect.TypeOf((*MockNotifierFactory)(nil).NewCgroupNotifier), path, attribute, threshold)
}
// MockThresholdNotifier is a mock of ThresholdNotifier interface.
// MockThresholdNotifier is an autogenerated mock type for the ThresholdNotifier type
type MockThresholdNotifier struct {
ctrl *gomock.Controller
recorder *MockThresholdNotifierMockRecorder
mock.Mock
}
// MockThresholdNotifierMockRecorder is the mock recorder for MockThresholdNotifier.
type MockThresholdNotifierMockRecorder struct {
mock *MockThresholdNotifier
type MockThresholdNotifier_Expecter struct {
mock *mock.Mock
}
// NewMockThresholdNotifier creates a new mock instance.
func NewMockThresholdNotifier(ctrl *gomock.Controller) *MockThresholdNotifier {
mock := &MockThresholdNotifier{ctrl: ctrl}
mock.recorder = &MockThresholdNotifierMockRecorder{mock}
func (_m *MockThresholdNotifier) EXPECT() *MockThresholdNotifier_Expecter {
return &MockThresholdNotifier_Expecter{mock: &_m.Mock}
}
// Description provides a mock function with given fields:
func (_m *MockThresholdNotifier) Description() string {
ret := _m.Called()
if len(ret) == 0 {
panic("no return value specified for Description")
}
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// MockThresholdNotifier_Description_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Description'
type MockThresholdNotifier_Description_Call struct {
*mock.Call
}
// Description is a helper method to define mock.On call
func (_e *MockThresholdNotifier_Expecter) Description() *MockThresholdNotifier_Description_Call {
return &MockThresholdNotifier_Description_Call{Call: _e.mock.On("Description")}
}
func (_c *MockThresholdNotifier_Description_Call) Run(run func()) *MockThresholdNotifier_Description_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockThresholdNotifier_Description_Call) Return(_a0 string) *MockThresholdNotifier_Description_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockThresholdNotifier_Description_Call) RunAndReturn(run func() string) *MockThresholdNotifier_Description_Call {
_c.Call.Return(run)
return _c
}
// Start provides a mock function with given fields:
func (_m *MockThresholdNotifier) Start() {
_m.Called()
}
// MockThresholdNotifier_Start_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Start'
type MockThresholdNotifier_Start_Call struct {
*mock.Call
}
// Start is a helper method to define mock.On call
func (_e *MockThresholdNotifier_Expecter) Start() *MockThresholdNotifier_Start_Call {
return &MockThresholdNotifier_Start_Call{Call: _e.mock.On("Start")}
}
func (_c *MockThresholdNotifier_Start_Call) Run(run func()) *MockThresholdNotifier_Start_Call {
_c.Call.Run(func(args mock.Arguments) {
run()
})
return _c
}
func (_c *MockThresholdNotifier_Start_Call) Return() *MockThresholdNotifier_Start_Call {
_c.Call.Return()
return _c
}
func (_c *MockThresholdNotifier_Start_Call) RunAndReturn(run func()) *MockThresholdNotifier_Start_Call {
_c.Call.Return(run)
return _c
}
// UpdateThreshold provides a mock function with given fields: summary
func (_m *MockThresholdNotifier) UpdateThreshold(summary *v1alpha1.Summary) error {
ret := _m.Called(summary)
if len(ret) == 0 {
panic("no return value specified for UpdateThreshold")
}
var r0 error
if rf, ok := ret.Get(0).(func(*v1alpha1.Summary) error); ok {
r0 = rf(summary)
} else {
r0 = ret.Error(0)
}
return r0
}
// MockThresholdNotifier_UpdateThreshold_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateThreshold'
type MockThresholdNotifier_UpdateThreshold_Call struct {
*mock.Call
}
// UpdateThreshold is a helper method to define mock.On call
// - summary *v1alpha1.Summary
func (_e *MockThresholdNotifier_Expecter) UpdateThreshold(summary interface{}) *MockThresholdNotifier_UpdateThreshold_Call {
return &MockThresholdNotifier_UpdateThreshold_Call{Call: _e.mock.On("UpdateThreshold", summary)}
}
func (_c *MockThresholdNotifier_UpdateThreshold_Call) Run(run func(summary *v1alpha1.Summary)) *MockThresholdNotifier_UpdateThreshold_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(*v1alpha1.Summary))
})
return _c
}
func (_c *MockThresholdNotifier_UpdateThreshold_Call) Return(_a0 error) *MockThresholdNotifier_UpdateThreshold_Call {
_c.Call.Return(_a0)
return _c
}
func (_c *MockThresholdNotifier_UpdateThreshold_Call) RunAndReturn(run func(*v1alpha1.Summary) error) *MockThresholdNotifier_UpdateThreshold_Call {
_c.Call.Return(run)
return _c
}
// NewMockThresholdNotifier creates a new instance of MockThresholdNotifier. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewMockThresholdNotifier(t interface {
mock.TestingT
Cleanup(func())
}) *MockThresholdNotifier {
mock := &MockThresholdNotifier{}
mock.Mock.Test(t)
t.Cleanup(func() { mock.AssertExpectations(t) })
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockThresholdNotifier) EXPECT() *MockThresholdNotifierMockRecorder {
return m.recorder
}
// Description mocks base method.
func (m *MockThresholdNotifier) Description() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Description")
ret0, _ := ret[0].(string)
return ret0
}
// Description indicates an expected call of Description.
func (mr *MockThresholdNotifierMockRecorder) Description() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Description", reflect.TypeOf((*MockThresholdNotifier)(nil).Description))
}
// Start mocks base method.
func (m *MockThresholdNotifier) Start() {
m.ctrl.T.Helper()
m.ctrl.Call(m, "Start")
}
// Start indicates an expected call of Start.
func (mr *MockThresholdNotifierMockRecorder) Start() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockThresholdNotifier)(nil).Start))
}
// UpdateThreshold mocks base method.
func (m *MockThresholdNotifier) UpdateThreshold(summary *v1alpha1.Summary) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UpdateThreshold", summary)
ret0, _ := ret[0].(error)
return ret0
}
// UpdateThreshold indicates an expected call of UpdateThreshold.
func (mr *MockThresholdNotifierMockRecorder) UpdateThreshold(summary any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateThreshold", reflect.TypeOf((*MockThresholdNotifier)(nil).UpdateThreshold), summary)
}