Skip to content

Commit

Permalink
tests: add mocks for KongService SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Aug 23, 2024
1 parent 39da364 commit e97b1b4
Show file tree
Hide file tree
Showing 7 changed files with 809 additions and 38 deletions.
9 changes: 5 additions & 4 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ inpackage: True
disable-version-string: True
with-expecter: True

filename: "{{.InterfaceName | lower}}_mock_test.go"
dir: "{{.InterfaceDir}}"
mockname: "Mock{{.InterfaceName}}"
outpkg: "{{.PackageName}}"
filename: "{{ trimSuffix .InterfaceFile \".go\" | base | lower }}_mock_test.go"
dir: "{{ .InterfaceDir }}"
mockname: "Mock{{ .InterfaceName }}"
outpkg: "{{ .PackageName }}"

packages:
github.com/kong/gateway-operator/controller/konnect/ops:
interfaces:
ControlPlaneSDK:
ServicesSDK:
264 changes: 264 additions & 0 deletions controller/konnect/ops/kongservice_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion controller/konnect/ops/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func Update[
case *konnectv1alpha1.KonnectControlPlane:
return ctrl.Result{}, updateControlPlane(ctx, sdk.ControlPlanes, ent)
case *configurationv1alpha1.KongService:
return ctrl.Result{}, updateService(ctx, sdk.Services, cl, ent)
return ctrl.Result{}, updateService(ctx, sdk.Services, ent)
case *configurationv1alpha1.KongRoute:
return ctrl.Result{}, updateRoute(ctx, sdk.Routes, cl, ent)
case *configurationv1.KongConsumer:
Expand Down
8 changes: 4 additions & 4 deletions controller/konnect/ops/ops_controlplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestCreateControlPlane(t *testing.T) {
return sdk, cp
},
assertions: func(t *testing.T, cp *konnectv1alpha1.KonnectControlPlane) {
assert.Equal(t, "12345", cp.Status.GetKonnectID())
assert.Equal(t, "12345", cp.GetKonnectStatus().GetKonnectID())
cond, ok := k8sutils.GetCondition(conditions.KonnectEntityProgrammedConditionType, cp)
require.True(t, ok, "Programmed condition not set on KonnectControlPlane")
assert.Equal(t, metav1.ConditionTrue, cond.Status)
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestCreateControlPlane(t *testing.T) {
assert.Equal(t, metav1.ConditionFalse, cond.Status)
assert.Equal(t, "FailedToCreate", cond.Reason)
assert.Equal(t, cp.GetGeneration(), cond.ObservedGeneration)
assert.Equal(t, "failed to create KonnectControlPlane default/cp-1: {\"status\":400,\"title\":\"\",\"instance\":\"\",\"detail\":\"bad request\",\"invalid_parameters\":null}", cond.Message)
assert.Equal(t, `failed to create KonnectControlPlane default/cp-1: {"status":400,"title":"","instance":"","detail":"bad request","invalid_parameters":null}`, cond.Message)
},
expectedErr: true,
},
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestDeleteControlPlane(t *testing.T) {
expectedErr: true,
},
{
name: "not found error is ignore and considered a success when trying to delete",
name: "not found error is ignored and considered a success when trying to delete",
mockCPPair: func() (*MockControlPlaneSDK, *konnectv1alpha1.KonnectControlPlane) {
sdk := &MockControlPlaneSDK{}
cp := &konnectv1alpha1.KonnectControlPlane{
Expand Down Expand Up @@ -358,7 +358,7 @@ func TestUpdateControlPlane(t *testing.T) {
assert.Equal(t, metav1.ConditionFalse, cond.Status)
assert.Equal(t, "FailedToUpdate", cond.Reason)
assert.Equal(t, cp.GetGeneration(), cond.ObservedGeneration)
assert.Equal(t, "failed to update KonnectControlPlane default/cp-1: {\"status\":400,\"title\":\"\",\"instance\":\"\",\"detail\":\"bad request\",\"invalid_parameters\":null}", cond.Message)
assert.Equal(t, `failed to update KonnectControlPlane default/cp-1: {"status":400,"title":"","instance":"","detail":"bad request","invalid_parameters":null}`, cond.Message)
},
expectedErr: true,
},
Expand Down
Loading

0 comments on commit e97b1b4

Please sign in to comment.