Skip to content

Commit

Permalink
test: create a different HTTPRoute at each integration test case of t…
Browse files Browse the repository at this point in the history
…he 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
  • Loading branch information
guicassolato committed Dec 4, 2023
1 parent 9f6f1f9 commit 13d94da
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions controllers/authpolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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())
Expand All @@ -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(),
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 13d94da

Please sign in to comment.