From 87b3ae253542dcbd649ccb67fc6313cbe117c081 Mon Sep 17 00:00:00 2001 From: David Fattakhov Date: Wed, 17 May 2023 14:19:12 +0300 Subject: [PATCH] Added client reader mock --- cbcontainers/state/state_applier_test.go | 2 +- cbcontainers/test_utils/mocks/generated.go | 1 + .../mocks/mock_k8s_client_reader.go | 75 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 cbcontainers/test_utils/mocks/mock_k8s_client_reader.go diff --git a/cbcontainers/state/state_applier_test.go b/cbcontainers/state/state_applier_test.go index fee7ddd8..5ee90bb2 100644 --- a/cbcontainers/state/state_applier_test.go +++ b/cbcontainers/state/state_applier_test.go @@ -190,7 +190,7 @@ func testStateApplier(t *testing.T, setup StateApplierTestSetup, k8sVersion, nam setup(mockObjects) - stateApplier := state.NewStateApplier(mockObjects.componentApplier, k8sVersion, mockObjects.secretValuesCreator, logrTesting.NewTestLogger(t)) + stateApplier := state.NewStateApplier(testUtilsMocks.NewMockReader(ctrl), mockObjects.componentApplier, k8sVersion, mockObjects.secretValuesCreator, logrTesting.NewTestLogger(t)) return stateApplier.ApplyDesiredState(context.Background(), agentSpec, &models.RegistrySecretValues{}, nil) } diff --git a/cbcontainers/test_utils/mocks/generated.go b/cbcontainers/test_utils/mocks/generated.go index 630c33f3..a5ebce30 100644 --- a/cbcontainers/test_utils/mocks/generated.go +++ b/cbcontainers/test_utils/mocks/generated.go @@ -1,3 +1,4 @@ package mocks //go:generate mockgen -destination mock_k8s_client.go -package mocks sigs.k8s.io/controller-runtime/pkg/client Client +//go:generate mockgen -destination mock_k8s_client_reader.go -package mocks sigs.k8s.io/controller-runtime/pkg/client Reader diff --git a/cbcontainers/test_utils/mocks/mock_k8s_client_reader.go b/cbcontainers/test_utils/mocks/mock_k8s_client_reader.go new file mode 100644 index 00000000..82f7d496 --- /dev/null +++ b/cbcontainers/test_utils/mocks/mock_k8s_client_reader.go @@ -0,0 +1,75 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: sigs.k8s.io/controller-runtime/pkg/client (interfaces: Reader) + +// Package mocks is a generated GoMock package. +package mocks + +import ( + context "context" + reflect "reflect" + + gomock "github.com/golang/mock/gomock" + types "k8s.io/apimachinery/pkg/types" + client "sigs.k8s.io/controller-runtime/pkg/client" +) + +// MockReader is a mock of Reader interface. +type MockReader struct { + ctrl *gomock.Controller + recorder *MockReaderMockRecorder +} + +// MockReaderMockRecorder is the mock recorder for MockReader. +type MockReaderMockRecorder struct { + mock *MockReader +} + +// NewMockReader creates a new mock instance. +func NewMockReader(ctrl *gomock.Controller) *MockReader { + mock := &MockReader{ctrl: ctrl} + mock.recorder = &MockReaderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockReader) EXPECT() *MockReaderMockRecorder { + return m.recorder +} + +// Get mocks base method. +func (m *MockReader) Get(arg0 context.Context, arg1 types.NamespacedName, arg2 client.Object, arg3 ...client.GetOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1, arg2} + for _, a := range arg3 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Get", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// Get indicates an expected call of Get. +func (mr *MockReaderMockRecorder) Get(arg0, arg1, arg2 interface{}, arg3 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1, arg2}, arg3...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockReader)(nil).Get), varargs...) +} + +// List mocks base method. +func (m *MockReader) List(arg0 context.Context, arg1 client.ObjectList, arg2 ...client.ListOption) error { + m.ctrl.T.Helper() + varargs := []interface{}{arg0, arg1} + for _, a := range arg2 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "List", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// List indicates an expected call of List. +func (mr *MockReaderMockRecorder) List(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{arg0, arg1}, arg2...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "List", reflect.TypeOf((*MockReader)(nil).List), varargs...) +}