From a8760229a799c00c2f4565dad0c63ea2424c55a6 Mon Sep 17 00:00:00 2001 From: jm96441n Date: Thu, 1 Feb 2024 13:12:32 -0500 Subject: [PATCH 1/2] Fix meshgw tests --- .../resources/mesh_gateway_controller_test.go | 146 +++++++++++++++++- 1 file changed, 144 insertions(+), 2 deletions(-) diff --git a/control-plane/controllers/resources/mesh_gateway_controller_test.go b/control-plane/controllers/resources/mesh_gateway_controller_test.go index 6aef2ec6e2..cb72ed4dde 100644 --- a/control-plane/controllers/resources/mesh_gateway_controller_test.go +++ b/control-plane/controllers/resources/mesh_gateway_controller_test.go @@ -8,7 +8,6 @@ import ( "testing" logrtest "github.com/go-logr/logr/testr" - "github.com/hashicorp/consul/sdk/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" @@ -21,6 +20,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/fake" + pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v2beta1" + "github.com/hashicorp/consul/sdk/testutil" + "github.com/hashicorp/consul-k8s/control-plane/api/mesh/v2beta1" "github.com/hashicorp/consul-k8s/control-plane/helper/test" ) @@ -50,6 +52,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Namespace: "consul", Name: "mesh-gateway", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, }, request: ctrl.Request{ @@ -73,6 +85,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Namespace: "default", Name: "mesh-gateway", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, &corev1.ServiceAccount{ ObjectMeta: metav1.ObjectMeta{ @@ -99,6 +121,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Namespace: "consul", Name: "mesh-gateway", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, }, request: ctrl.Request{ @@ -122,6 +154,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Namespace: "default", Name: "mesh-gateway", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, &rbacv1.Role{ ObjectMeta: metav1.ObjectMeta{ @@ -148,6 +190,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Name: "mesh-gateway", UID: "abc123", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, &rbacv1.Role{ ObjectMeta: metav1.ObjectMeta{ @@ -180,6 +232,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Namespace: "consul", Name: "mesh-gateway", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, }, request: ctrl.Request{ @@ -203,6 +265,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Namespace: "default", Name: "mesh-gateway", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, &rbacv1.RoleBinding{ ObjectMeta: metav1.ObjectMeta{ @@ -229,6 +301,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Name: "mesh-gateway", UID: "abc123", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, &rbacv1.RoleBinding{ ObjectMeta: metav1.ObjectMeta{ @@ -261,6 +343,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Namespace: "consul", Name: "mesh-gateway", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, }, request: ctrl.Request{ @@ -284,6 +376,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Namespace: "default", Name: "mesh-gateway", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -310,6 +412,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Name: "mesh-gateway", UID: "abc123", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, &appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -342,6 +454,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Namespace: "consul", Name: "mesh-gateway", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, }, request: ctrl.Request{ @@ -365,6 +487,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Namespace: "default", Name: "mesh-gateway", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -391,6 +523,16 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { Name: "mesh-gateway", UID: "abc123", }, + Spec: pbmesh.MeshGateway{ + GatewayClassName: "consul", + Listeners: []*pbmesh.MeshGatewayListener{ + { + Name: "wan", + Port: 8443, + Protocol: "mesh", + }, + }, + }, }, &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -444,7 +586,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { res, err := controller.Reconcile(context.Background(), testCase.request) if testCase.expectedErr != nil { - //require.EqualError(t, err, testCase.expectedErr.Error()) + // require.EqualError(t, err, testCase.expectedErr.Error()) require.ErrorIs(t, err, testCase.expectedErr) } else { require.NoError(t, err) From 170968664a12730c87c96d6d7c60d2ef4620ad79 Mon Sep 17 00:00:00 2001 From: jm96441n Date: Thu, 1 Feb 2024 13:21:51 -0500 Subject: [PATCH 2/2] change protocol on mesh gw tests to tcp from mesh --- .../resources/mesh_gateway_controller_test.go | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/control-plane/controllers/resources/mesh_gateway_controller_test.go b/control-plane/controllers/resources/mesh_gateway_controller_test.go index cb72ed4dde..63f38624f0 100644 --- a/control-plane/controllers/resources/mesh_gateway_controller_test.go +++ b/control-plane/controllers/resources/mesh_gateway_controller_test.go @@ -58,7 +58,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -91,7 +91,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -127,7 +127,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -160,7 +160,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -196,7 +196,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -238,7 +238,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -271,7 +271,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -307,7 +307,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -349,7 +349,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -382,7 +382,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -418,7 +418,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -460,7 +460,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -493,7 +493,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, }, @@ -529,7 +529,7 @@ func TestMeshGatewayController_Reconcile(t *testing.T) { { Name: "wan", Port: 8443, - Protocol: "mesh", + Protocol: "tcp", }, }, },