Skip to content

Commit

Permalink
chore: move mock under sdk
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Lavacca <[email protected]>
  • Loading branch information
mlavacca committed Oct 21, 2024
1 parent 19ea145 commit 63f1a70
Show file tree
Hide file tree
Showing 49 changed files with 159 additions and 159 deletions.
86 changes: 43 additions & 43 deletions controller/konnect/ops/ops_controlplane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

mockops "github.com/kong/gateway-operator/controller/konnect/ops/mock"
sdkmock "github.com/kong/gateway-operator/controller/konnect/ops/sdk/mock"
"github.com/kong/gateway-operator/modules/manager/scheme"

konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
Expand All @@ -34,17 +34,17 @@ func TestCreateControlPlane(t *testing.T) {
ctx := context.Background()
testCases := []struct {
name string
mockCPTuple func(*testing.T) (*mockops.MockControlPlaneSDK, *mockops.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane)
mockCPTuple func(*testing.T) (*sdkmock.MockControlPlaneSDK, *sdkmock.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane)
objects []client.Object
expectedErrContains string
expectedErrType error
expectedID string
}{
{
name: "success",
mockCPTuple: func(t *testing.T) (*mockops.MockControlPlaneSDK, *mockops.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := mockops.NewMockControlPlaneSDK(t)
sdkGroups := mockops.NewMockControlPlaneGroupSDK(t)
mockCPTuple: func(t *testing.T) (*sdkmock.MockControlPlaneSDK, *sdkmock.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := sdkmock.NewMockControlPlaneSDK(t)
sdkGroups := sdkmock.NewMockControlPlaneGroupSDK(t)
cp := &konnectv1alpha1.KonnectGatewayControlPlane{
Spec: konnectv1alpha1.KonnectGatewayControlPlaneSpec{
CreateControlPlaneRequest: sdkkonnectcomp.CreateControlPlaneRequest{
Expand Down Expand Up @@ -73,9 +73,9 @@ func TestCreateControlPlane(t *testing.T) {
},
{
name: "fail",
mockCPTuple: func(t *testing.T) (*mockops.MockControlPlaneSDK, *mockops.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := mockops.NewMockControlPlaneSDK(t)
sdkGroups := mockops.NewMockControlPlaneGroupSDK(t)
mockCPTuple: func(t *testing.T) (*sdkmock.MockControlPlaneSDK, *sdkmock.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := sdkmock.NewMockControlPlaneSDK(t)
sdkGroups := sdkmock.NewMockControlPlaneGroupSDK(t)
cp := &konnectv1alpha1.KonnectGatewayControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "cp-1",
Expand Down Expand Up @@ -126,9 +126,9 @@ func TestCreateControlPlane(t *testing.T) {
},
},
},
mockCPTuple: func(t *testing.T) (*mockops.MockControlPlaneSDK, *mockops.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := mockops.NewMockControlPlaneSDK(t)
sdkGroups := mockops.NewMockControlPlaneGroupSDK(t)
mockCPTuple: func(t *testing.T) (*sdkmock.MockControlPlaneSDK, *sdkmock.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := sdkmock.NewMockControlPlaneSDK(t)
sdkGroups := sdkmock.NewMockControlPlaneGroupSDK(t)
cp := &konnectv1alpha1.KonnectGatewayControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "cpg-1",
Expand Down Expand Up @@ -195,9 +195,9 @@ func TestCreateControlPlane(t *testing.T) {
},
},
},
mockCPTuple: func(t *testing.T) (*mockops.MockControlPlaneSDK, *mockops.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := mockops.NewMockControlPlaneSDK(t)
sdkGroups := mockops.NewMockControlPlaneGroupSDK(t)
mockCPTuple: func(t *testing.T) (*sdkmock.MockControlPlaneSDK, *sdkmock.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := sdkmock.NewMockControlPlaneSDK(t)
sdkGroups := sdkmock.NewMockControlPlaneGroupSDK(t)
cp := &konnectv1alpha1.KonnectGatewayControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "cpg-1",
Expand Down Expand Up @@ -276,14 +276,14 @@ func TestDeleteControlPlane(t *testing.T) {
ctx := context.Background()
testCases := []struct {
name string
mockCPPair func(*testing.T) (*mockops.MockControlPlaneSDK, *konnectv1alpha1.KonnectGatewayControlPlane)
mockCPPair func(*testing.T) (*sdkmock.MockControlPlaneSDK, *konnectv1alpha1.KonnectGatewayControlPlane)
expectedErr bool
assertions func(*testing.T, *konnectv1alpha1.KonnectGatewayControlPlane)
}{
{
name: "success",
mockCPPair: func(t *testing.T) (*mockops.MockControlPlaneSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := mockops.NewMockControlPlaneSDK(t)
mockCPPair: func(t *testing.T) (*sdkmock.MockControlPlaneSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := sdkmock.NewMockControlPlaneSDK(t)
cp := &konnectv1alpha1.KonnectGatewayControlPlane{
Spec: konnectv1alpha1.KonnectGatewayControlPlaneSpec{
CreateControlPlaneRequest: sdkkonnectcomp.CreateControlPlaneRequest{
Expand Down Expand Up @@ -311,8 +311,8 @@ func TestDeleteControlPlane(t *testing.T) {
},
{
name: "fail",
mockCPPair: func(t *testing.T) (*mockops.MockControlPlaneSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := mockops.NewMockControlPlaneSDK(t)
mockCPPair: func(t *testing.T) (*sdkmock.MockControlPlaneSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := sdkmock.NewMockControlPlaneSDK(t)
cp := &konnectv1alpha1.KonnectGatewayControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "cp-1",
Expand Down Expand Up @@ -346,8 +346,8 @@ func TestDeleteControlPlane(t *testing.T) {
},
{
name: "not found error is ignored and considered a success when trying to delete",
mockCPPair: func(t *testing.T) (*mockops.MockControlPlaneSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := mockops.NewMockControlPlaneSDK(t)
mockCPPair: func(t *testing.T) (*sdkmock.MockControlPlaneSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := sdkmock.NewMockControlPlaneSDK(t)
cp := &konnectv1alpha1.KonnectGatewayControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "cp-1",
Expand Down Expand Up @@ -404,15 +404,15 @@ func TestUpdateControlPlane(t *testing.T) {
ctx := context.Background()
testCases := []struct {
name string
mockCPTuple func(*testing.T) (*mockops.MockControlPlaneSDK, *mockops.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane)
mockCPTuple func(*testing.T) (*sdkmock.MockControlPlaneSDK, *sdkmock.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane)
expectedErr bool
expectedID string
}{
{
name: "success",
mockCPTuple: func(t *testing.T) (*mockops.MockControlPlaneSDK, *mockops.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := mockops.NewMockControlPlaneSDK(t)
sdkGroups := mockops.NewMockControlPlaneGroupSDK(t)
mockCPTuple: func(t *testing.T) (*sdkmock.MockControlPlaneSDK, *sdkmock.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := sdkmock.NewMockControlPlaneSDK(t)
sdkGroups := sdkmock.NewMockControlPlaneGroupSDK(t)
cp := &konnectv1alpha1.KonnectGatewayControlPlane{
Spec: konnectv1alpha1.KonnectGatewayControlPlaneSpec{
CreateControlPlaneRequest: sdkkonnectcomp.CreateControlPlaneRequest{
Expand Down Expand Up @@ -451,9 +451,9 @@ func TestUpdateControlPlane(t *testing.T) {
},
{
name: "fail",
mockCPTuple: func(t *testing.T) (*mockops.MockControlPlaneSDK, *mockops.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := mockops.NewMockControlPlaneSDK(t)
sdkGroups := mockops.NewMockControlPlaneGroupSDK(t)
mockCPTuple: func(t *testing.T) (*sdkmock.MockControlPlaneSDK, *sdkmock.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := sdkmock.NewMockControlPlaneSDK(t)
sdkGroups := sdkmock.NewMockControlPlaneGroupSDK(t)
cp := &konnectv1alpha1.KonnectGatewayControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "cp-1",
Expand Down Expand Up @@ -496,9 +496,9 @@ func TestUpdateControlPlane(t *testing.T) {
},
{
name: "when not found then try to create",
mockCPTuple: func(t *testing.T) (*mockops.MockControlPlaneSDK, *mockops.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := mockops.NewMockControlPlaneSDK(t)
sdkGroups := mockops.NewMockControlPlaneGroupSDK(t)
mockCPTuple: func(t *testing.T) (*sdkmock.MockControlPlaneSDK, *sdkmock.MockControlPlaneGroupSDK, *konnectv1alpha1.KonnectGatewayControlPlane) {
sdk := sdkmock.NewMockControlPlaneSDK(t)
sdkGroups := sdkmock.NewMockControlPlaneGroupSDK(t)
cp := &konnectv1alpha1.KonnectGatewayControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: "cp-1",
Expand Down Expand Up @@ -593,7 +593,7 @@ func TestCreateAndUpdateControlPlane_KubernetesMetadataConsistency(t *testing.T)
},
},
}
sdk = mockops.NewMockSDKFactory(t)
sdk = sdkmock.NewMockSDKFactory(t)
sdkControlPlanes = sdk.SDK.ControlPlaneSDK
fakeClient = fake.NewClientBuilder().Build()
)
Expand Down Expand Up @@ -641,7 +641,7 @@ func TestSetGroupMembers(t *testing.T) {
name string
group *konnectv1alpha1.KonnectGatewayControlPlane
cps []client.Object
sdk func(t *testing.T) *mockops.MockControlPlaneGroupSDK
sdk func(t *testing.T) *sdkmock.MockControlPlaneGroupSDK
expectedErr bool
}{
{
Expand All @@ -658,8 +658,8 @@ func TestSetGroupMembers(t *testing.T) {
},
},
},
sdk: func(t *testing.T) *mockops.MockControlPlaneGroupSDK {
sdk := mockops.NewMockControlPlaneGroupSDK(t)
sdk: func(t *testing.T) *sdkmock.MockControlPlaneGroupSDK {
sdk := sdkmock.NewMockControlPlaneGroupSDK(t)
return sdk
},
},
Expand Down Expand Up @@ -695,8 +695,8 @@ func TestSetGroupMembers(t *testing.T) {
},
},
},
sdk: func(t *testing.T) *mockops.MockControlPlaneGroupSDK {
sdk := mockops.NewMockControlPlaneGroupSDK(t)
sdk: func(t *testing.T) *sdkmock.MockControlPlaneGroupSDK {
sdk := sdkmock.NewMockControlPlaneGroupSDK(t)
sdk.EXPECT().
PutControlPlanesIDGroupMemberships(
mock.Anything,
Expand Down Expand Up @@ -744,8 +744,8 @@ func TestSetGroupMembers(t *testing.T) {
Status: konnectv1alpha1.KonnectGatewayControlPlaneStatus{},
},
},
sdk: func(t *testing.T) *mockops.MockControlPlaneGroupSDK {
sdk := mockops.NewMockControlPlaneGroupSDK(t)
sdk: func(t *testing.T) *sdkmock.MockControlPlaneGroupSDK {
sdk := sdkmock.NewMockControlPlaneGroupSDK(t)
return sdk
},
expectedErr: true,
Expand Down Expand Up @@ -796,8 +796,8 @@ func TestSetGroupMembers(t *testing.T) {
},
},
},
sdk: func(t *testing.T) *mockops.MockControlPlaneGroupSDK {
sdk := mockops.NewMockControlPlaneGroupSDK(t)
sdk: func(t *testing.T) *sdkmock.MockControlPlaneGroupSDK {
sdk := sdkmock.NewMockControlPlaneGroupSDK(t)
sdk.EXPECT().
PutControlPlanesIDGroupMemberships(
mock.Anything,
Expand Down Expand Up @@ -861,8 +861,8 @@ func TestSetGroupMembers(t *testing.T) {
},
},
},
sdk: func(t *testing.T) *mockops.MockControlPlaneGroupSDK {
sdk := mockops.NewMockControlPlaneGroupSDK(t)
sdk: func(t *testing.T) *sdkmock.MockControlPlaneGroupSDK {
sdk := sdkmock.NewMockControlPlaneGroupSDK(t)
return sdk
},
expectedErr: true,
Expand Down
48 changes: 24 additions & 24 deletions controller/konnect/ops/ops_kongservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
k8stypes "k8s.io/apimachinery/pkg/types"

konnectconsts "github.com/kong/gateway-operator/controller/konnect/consts"
mockops "github.com/kong/gateway-operator/controller/konnect/ops/mock"
sdkmock "github.com/kong/gateway-operator/controller/konnect/ops/sdk/mock"

configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
Expand All @@ -25,15 +25,15 @@ func TestCreateKongService(t *testing.T) {
ctx := context.Background()
testCases := []struct {
name string
mockServicePair func(*testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService)
mockServicePair func(*testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService)
assertions func(*testing.T, *configurationv1alpha1.KongService)
expectedErrContains string
expectedErrType error
}{
{
name: "success",
mockServicePair: func(t *testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := mockops.NewMockServicesSDK(t)
mockServicePair: func(t *testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := sdkmock.NewMockServicesSDK(t)
svc := &configurationv1alpha1.KongService{
ObjectMeta: metav1.ObjectMeta{
Name: "svc-1",
Expand Down Expand Up @@ -74,8 +74,8 @@ func TestCreateKongService(t *testing.T) {
},
{
name: "fail - no control plane ID in status returns an error and does not create the Service in Konnect",
mockServicePair: func(t *testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := mockops.NewMockServicesSDK(t)
mockServicePair: func(t *testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := sdkmock.NewMockServicesSDK(t)
svc := &configurationv1alpha1.KongService{
ObjectMeta: metav1.ObjectMeta{
Name: "svc-1",
Expand All @@ -98,8 +98,8 @@ func TestCreateKongService(t *testing.T) {
},
{
name: "fail",
mockServicePair: func(t *testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := mockops.NewMockServicesSDK(t)
mockServicePair: func(t *testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := sdkmock.NewMockServicesSDK(t)
svc := &configurationv1alpha1.KongService{
ObjectMeta: metav1.ObjectMeta{
Name: "svc-1",
Expand Down Expand Up @@ -138,8 +138,8 @@ func TestCreateKongService(t *testing.T) {
},
{
name: "409 Conflict causes a list to find a matching (by UID) service and update it instead of creating a new one",
mockServicePair: func(t *testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := mockops.NewMockServicesSDK(t)
mockServicePair: func(t *testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := sdkmock.NewMockServicesSDK(t)
svc := &configurationv1alpha1.KongService{
ObjectMeta: metav1.ObjectMeta{
Name: "svc-1",
Expand Down Expand Up @@ -203,14 +203,14 @@ func TestDeleteKongService(t *testing.T) {
ctx := context.Background()
testCases := []struct {
name string
mockServicePair func(*testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService)
mockServicePair func(*testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService)
expectedErr bool
assertions func(*testing.T, *configurationv1alpha1.KongService)
}{
{
name: "success",
mockServicePair: func(t *testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := mockops.NewMockServicesSDK(t)
mockServicePair: func(t *testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := sdkmock.NewMockServicesSDK(t)
svc := &configurationv1alpha1.KongService{
Spec: configurationv1alpha1.KongServiceSpec{
KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
Expand Down Expand Up @@ -241,8 +241,8 @@ func TestDeleteKongService(t *testing.T) {
},
{
name: "fail",
mockServicePair: func(t *testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := mockops.NewMockServicesSDK(t)
mockServicePair: func(t *testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := sdkmock.NewMockServicesSDK(t)
svc := &configurationv1alpha1.KongService{
Spec: configurationv1alpha1.KongServiceSpec{
KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
Expand Down Expand Up @@ -275,8 +275,8 @@ func TestDeleteKongService(t *testing.T) {
},
{
name: "not found error is ignored and considered a success when trying to delete",
mockServicePair: func(t *testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := mockops.NewMockServicesSDK(t)
mockServicePair: func(t *testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := sdkmock.NewMockServicesSDK(t)
svc := &configurationv1alpha1.KongService{
Spec: configurationv1alpha1.KongServiceSpec{
KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
Expand Down Expand Up @@ -332,14 +332,14 @@ func TestUpdateKongService(t *testing.T) {
ctx := context.Background()
testCases := []struct {
name string
mockServicePair func(*testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService)
mockServicePair func(*testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService)
expectedErr bool
assertions func(*testing.T, *configurationv1alpha1.KongService)
}{
{
name: "success",
mockServicePair: func(t *testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := mockops.NewMockServicesSDK(t)
mockServicePair: func(t *testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := sdkmock.NewMockServicesSDK(t)
svc := &configurationv1alpha1.KongService{
Spec: configurationv1alpha1.KongServiceSpec{
KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
Expand Down Expand Up @@ -383,8 +383,8 @@ func TestUpdateKongService(t *testing.T) {
},
{
name: "fail",
mockServicePair: func(t *testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := mockops.NewMockServicesSDK(t)
mockServicePair: func(t *testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := sdkmock.NewMockServicesSDK(t)
svc := &configurationv1alpha1.KongService{
ObjectMeta: metav1.ObjectMeta{
Name: "svc-1",
Expand Down Expand Up @@ -430,8 +430,8 @@ func TestUpdateKongService(t *testing.T) {
},
{
name: "when not found then try to create",
mockServicePair: func(t *testing.T) (*mockops.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := mockops.NewMockServicesSDK(t)
mockServicePair: func(t *testing.T) (*sdkmock.MockServicesSDK, *configurationv1alpha1.KongService) {
sdk := sdkmock.NewMockServicesSDK(t)
svc := &configurationv1alpha1.KongService{
ObjectMeta: metav1.ObjectMeta{
Name: "svc-1",
Expand Down
Loading

0 comments on commit 63f1a70

Please sign in to comment.