From 13d94da25484e13a1d195b1927a0511f5daa7890 Mon Sep 17 00:00:00 2001 From: Guilherme Cassolato Date: Mon, 4 Dec 2023 11:00:42 +0100 Subject: [PATCH] test: create a different HTTPRoute at each integration test case of the AuthPolicy controller, so each route policy created at each test can target a freshly created route and not the same route targeted by another policy from a previous test that has not been cleaned up yet --- controllers/authpolicy_controller_test.go | 34 +++++++++++++---------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/controllers/authpolicy_controller_test.go b/controllers/authpolicy_controller_test.go index 495d0b866..e3c5a5a6e 100644 --- a/controllers/authpolicy_controller_test.go +++ b/controllers/authpolicy_controller_test.go @@ -10,6 +10,7 @@ import ( "strings" "time" + "github.com/google/uuid" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" secv1beta1resources "istio.io/client-go/pkg/apis/security/v1beta1" @@ -28,10 +29,7 @@ import ( api "github.com/kuadrant/kuadrant-operator/api/v1beta2" ) -const ( - testGatewayName = "toystore-gw" - testHTTPRouteName = "toystore-route" -) +const testGatewayName = "toystore-gw" var _ = Describe("AuthPolicy controller", func() { var testNamespace string @@ -51,10 +49,13 @@ var _ = Describe("AuthPolicy controller", func() { AfterEach(DeleteNamespaceCallback(&testNamespace)) Context("Basic HTTPRoute", func() { + var testHTTPRouteName string + BeforeEach(func() { err := ApplyResources(filepath.Join("..", "examples", "toystore", "toystore.yaml"), k8sClient, testNamespace) Expect(err).ToNot(HaveOccurred()) + testHTTPRouteName = fmt.Sprintf("toystore-route-%s", uuid.New().String()) route := testBuildBasicHttpRoute(testHTTPRouteName, testGatewayName, testNamespace, []string{"*.toystore.com"}) err = k8sClient.Create(context.Background(), route) Expect(err).ToNot(HaveOccurred()) @@ -189,7 +190,7 @@ var _ = Describe("AuthPolicy controller", func() { TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ Group: "gateway.networking.k8s.io", Kind: "HTTPRoute", - Name: testHTTPRouteName, + Name: gatewayapiv1.ObjectName(testHTTPRouteName), Namespace: ptr.To(gatewayapiv1.Namespace(testNamespace)), }, AuthScheme: testBasicAuthScheme(), @@ -251,7 +252,7 @@ var _ = Describe("AuthPolicy controller", func() { TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ Group: "gateway.networking.k8s.io", Kind: "HTTPRoute", - Name: testHTTPRouteName, + Name: gatewayapiv1.ObjectName(testHTTPRouteName), Namespace: ptr.To(gatewayapiv1.Namespace(testNamespace)), }, AuthScheme: testBasicAuthScheme(), @@ -353,7 +354,7 @@ var _ = Describe("AuthPolicy controller", func() { TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ Group: "gateway.networking.k8s.io", Kind: "HTTPRoute", - Name: testHTTPRouteName, + Name: gatewayapiv1.ObjectName(testHTTPRouteName), Namespace: ptr.To(gatewayapiv1.Namespace(testNamespace)), }, AuthScheme: testBasicAuthScheme(), @@ -427,7 +428,7 @@ var _ = Describe("AuthPolicy controller", func() { TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ Group: "gateway.networking.k8s.io", Kind: "HTTPRoute", - Name: testHTTPRouteName, + Name: gatewayapiv1.ObjectName(testHTTPRouteName), Namespace: ptr.To(gatewayapiv1.Namespace(testNamespace)), }, RouteSelectors: []api.RouteSelector{ @@ -486,7 +487,7 @@ var _ = Describe("AuthPolicy controller", func() { TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ Group: "gateway.networking.k8s.io", Kind: "HTTPRoute", - Name: testHTTPRouteName, + Name: gatewayapiv1.ObjectName(testHTTPRouteName), Namespace: ptr.To(gatewayapiv1.Namespace(testNamespace)), }, AuthScheme: testBasicAuthScheme(), @@ -553,7 +554,7 @@ var _ = Describe("AuthPolicy controller", func() { TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ Group: "gateway.networking.k8s.io", Kind: "HTTPRoute", - Name: testHTTPRouteName, + Name: gatewayapiv1.ObjectName(testHTTPRouteName), Namespace: ptr.To(gatewayapiv1.Namespace(testNamespace)), }, AuthScheme: testBasicAuthScheme(), @@ -597,7 +598,7 @@ var _ = Describe("AuthPolicy controller", func() { TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ Group: "gateway.networking.k8s.io", Kind: "HTTPRoute", - Name: testHTTPRouteName, + Name: gatewayapiv1.ObjectName(testHTTPRouteName), Namespace: ptr.To(gatewayapiv1.Namespace(testNamespace)), }, NamedPatterns: map[string]authorinoapi.PatternExpressions{ @@ -835,10 +836,13 @@ var _ = Describe("AuthPolicy controller", func() { }) Context("Complex HTTPRoute with multiple rules and hostnames", func() { + var testHTTPRouteName string + BeforeEach(func() { err := ApplyResources(filepath.Join("..", "examples", "toystore", "toystore.yaml"), k8sClient, testNamespace) Expect(err).ToNot(HaveOccurred()) + testHTTPRouteName = fmt.Sprintf("toystore-route-%s", uuid.New().String()) route := testBuildMultipleRulesHttpRoute(testHTTPRouteName, testGatewayName, testNamespace, []string{"*.toystore.com", "*.admin.toystore.com"}) err = k8sClient.Create(context.Background(), route) Expect(err).ToNot(HaveOccurred()) @@ -855,7 +859,7 @@ var _ = Describe("AuthPolicy controller", func() { TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ Group: "gateway.networking.k8s.io", Kind: "HTTPRoute", - Name: testHTTPRouteName, + Name: gatewayapiv1.ObjectName(testHTTPRouteName), Namespace: ptr.To(gatewayapiv1.Namespace(testNamespace)), }, AuthScheme: testBasicAuthScheme(), @@ -942,7 +946,7 @@ var _ = Describe("AuthPolicy controller", func() { TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ Group: "gateway.networking.k8s.io", Kind: "HTTPRoute", - Name: testHTTPRouteName, + Name: gatewayapiv1.ObjectName(testHTTPRouteName), Namespace: ptr.To(gatewayapiv1.Namespace(testNamespace)), }, RouteSelectors: []api.RouteSelector{ @@ -1061,7 +1065,7 @@ var _ = Describe("AuthPolicy controller", func() { TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ Group: "gateway.networking.k8s.io", Kind: "HTTPRoute", - Name: testHTTPRouteName, + Name: gatewayapiv1.ObjectName(testHTTPRouteName), Namespace: ptr.To(gatewayapiv1.Namespace(testNamespace)), }, AuthScheme: testBasicAuthScheme(), @@ -1190,7 +1194,7 @@ var _ = Describe("AuthPolicy controller", func() { TargetRef: gatewayapiv1alpha2.PolicyTargetReference{ Group: "gateway.networking.k8s.io", Kind: "HTTPRoute", - Name: testHTTPRouteName, + Name: gatewayapiv1.ObjectName(testHTTPRouteName), Namespace: ptr.To(gatewayapiv1.Namespace(testNamespace)), }, AuthScheme: testBasicAuthScheme(),