Skip to content

Commit

Permalink
move mock SDK code to *_mock.go to allow them being imported by other…
Browse files Browse the repository at this point in the history
… packages
  • Loading branch information
randmonkey committed Sep 5, 2024
1 parent 34a6352 commit 954bb84
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,8 @@ issues:
linters:
- revive
text: "exported: exported"
# Generated mock SDKs does not need comments on generated methods.
- path: controller/konnect/ops/.*_mock\.go
linters:
- revive
text: "exported: exported"
2 changes: 1 addition & 1 deletion .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ inpackage: True
disable-version-string: True
with-expecter: True

filename: "{{ trimSuffix .InterfaceFile \".go\" | base | lower }}_mock_test.go"
filename: "{{ trimSuffix .InterfaceFile \".go\" | base | lower }}_mock.go"
dir: "{{ .InterfaceDir }}"
mockname: "Mock{{ .InterfaceName }}"
outpkg: "{{ .PackageName }}"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
62 changes: 62 additions & 0 deletions controller/konnect/ops/sdkfactory_mock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ops

type MockSDKWrapper struct {
ControlPlaneSDK *MockControlPlaneSDK
ServicesSDK *MockServicesSDK
RoutesSDK *MockRoutesSDK
ConsumersSDK *MockConsumersSDK
ConsumerGroupSDK *MockConsumerGroupSDK
PluginSDK *MockPluginSDK
MeSDK *MockMeSDK
}

var _ SDKWrapper = MockSDKWrapper{}

func (m MockSDKWrapper) GetControlPlaneSDK() ControlPlaneSDK {
return m.ControlPlaneSDK
}

func (m MockSDKWrapper) GetServicesSDK() ServicesSDK {
return m.ServicesSDK
}

func (m MockSDKWrapper) GetRoutesSDK() RoutesSDK {
return m.RoutesSDK
}

func (m MockSDKWrapper) GetConsumersSDK() ConsumersSDK {
return m.ConsumersSDK
}

func (m MockSDKWrapper) GetConsumerGroupsSDK() ConsumerGroupSDK {
return m.ConsumerGroupSDK
}

func (m MockSDKWrapper) GetPluginSDK() PluginSDK {
return m.PluginSDK
}

func (m MockSDKWrapper) GetMeSDK() MeSDK {
return m.MeSDK
}

type MockSDKFactory struct {
w *MockSDKWrapper
}

var _ SDKFactory = MockSDKFactory{}

func (m MockSDKFactory) NewKonnectSDK(_ string, _ SDKToken) SDKWrapper {
if m.w != nil {
return *m.w
}
return &MockSDKWrapper{
ControlPlaneSDK: &MockControlPlaneSDK{},
ServicesSDK: &MockServicesSDK{},
RoutesSDK: &MockRoutesSDK{},
ConsumersSDK: &MockConsumersSDK{},
ConsumerGroupSDK: &MockConsumerGroupSDK{},
PluginSDK: &MockPluginSDK{},
MeSDK: &MockMeSDK{},
}
}
4 changes: 2 additions & 2 deletions controller/konnect/reconciler_generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func testNewKonnectEntityReconciler[
t.Helper()

// TODO: use a mock Konnect SDK factory here and use envtest to trigger real reconciliations and Konnect requests
// https://github.com/Kong/gateway-operator/issues/540
sdkFactory := ops.NewSDKFactory()
//
sdkFactory := &ops.MockSDKFactory{}

t.Run(ent.GetTypeName(), func(t *testing.T) {
cl := fakectrlruntimeclient.NewFakeClient()
Expand Down

0 comments on commit 954bb84

Please sign in to comment.