From 536554cbd3b6142ca64bfb8df5a56c1c911df37b Mon Sep 17 00:00:00 2001 From: Michael Nairn Date: Tue, 14 Nov 2023 14:45:21 +0000 Subject: [PATCH] Integration tests --- .../gateway_controller_test.go | 3 ++- ...dnspolicy_controller_health_checks_test.go | 15 +++++++----- ...dnspolicy_controller_multi_cluster_test.go | 23 ++++++++++++------- ...nspolicy_controller_single_cluster_test.go | 17 +++++++++----- .../dnspolicy_controller_test.go | 3 ++- .../managedzone_controller_test.go | 3 ++- test/policy_integration/suite_test.go | 2 +- test/util/test_dnspolicy_types.go | 18 ++++++++++++++- 8 files changed, 59 insertions(+), 25 deletions(-) diff --git a/test/gateway_integration/gateway_controller_test.go b/test/gateway_integration/gateway_controller_test.go index 9aadae1fe..81cf8de0f 100644 --- a/test/gateway_integration/gateway_controller_test.go +++ b/test/gateway_integration/gateway_controller_test.go @@ -191,9 +191,10 @@ var _ = Describe("GatewayController", func() { ID: "1234", DomainName: "example.com", Description: "example.com", - SecretRef: &v1alpha1.SecretRef{ + ProviderRef: &v1alpha1.ProviderRef{ Name: providerCredential, Namespace: defaultNS, + Kind: v1alpha1.ProviderKindSecret, }, }, } diff --git a/test/policy_integration/dnspolicy_controller_health_checks_test.go b/test/policy_integration/dnspolicy_controller_health_checks_test.go index d88b84fa7..f68cb6558 100644 --- a/test/policy_integration/dnspolicy_controller_health_checks_test.go +++ b/test/policy_integration/dnspolicy_controller_health_checks_test.go @@ -103,8 +103,9 @@ var _ = Describe("DNSPolicy Health Checks", func() { return k8sClient.Status().Update(ctx, gateway) }, TestTimeoutMedium, TestRetryIntervalMedium).ShouldNot(HaveOccurred()) - dnsPolicyBuilder = testutil.NewDNSPolicyBuilder("test-dns-policy", testNamespace) - dnsPolicyBuilder.WithTargetGateway(TestGatewayName) + dnsPolicyBuilder = testutil.NewDNSPolicyBuilder("test-dns-policy", testNamespace). + WithProviderManagedZone(managedZone.Name). + WithTargetGateway(TestGatewayName) lbHash = dns.ToBase36hash(fmt.Sprintf("%s-%s", gateway.Name, gateway.Namespace)) recordName = fmt.Sprintf("%s-%s", TestGatewayName, TestListenerNameOne) @@ -164,15 +165,17 @@ var _ = Describe("DNSPolicy Health Checks", func() { MatchFields(IgnoreExtras, Fields{ "ObjectMeta": HaveField("Name", recordName), "Spec": MatchFields(IgnoreExtras, Fields{ - "ManagedZoneRef": HaveField("Name", "mz-example-com"), - "Endpoints": HaveLen(6), + "ZoneID": PointTo(Equal(managedZone.Spec.ID)), + "ProviderRef": Equal(dnsPolicy.Spec.ProviderRef), + "Endpoints": HaveLen(6), }), }), MatchFields(IgnoreExtras, Fields{ "ObjectMeta": HaveField("Name", wildcardRecordName), "Spec": MatchFields(IgnoreExtras, Fields{ - "ManagedZoneRef": HaveField("Name", "mz-example-com"), - "Endpoints": HaveLen(6), + "ZoneID": PointTo(Equal(managedZone.Spec.ID)), + "ProviderRef": Equal(dnsPolicy.Spec.ProviderRef), + "Endpoints": HaveLen(6), }), }), )) diff --git a/test/policy_integration/dnspolicy_controller_multi_cluster_test.go b/test/policy_integration/dnspolicy_controller_multi_cluster_test.go index dde6661df..9a04904ed 100644 --- a/test/policy_integration/dnspolicy_controller_multi_cluster_test.go +++ b/test/policy_integration/dnspolicy_controller_multi_cluster_test.go @@ -102,8 +102,9 @@ var _ = Describe("DNSPolicy Multi Cluster", func() { return k8sClient.Status().Update(ctx, gateway) }, TestTimeoutMedium, TestRetryIntervalMedium).ShouldNot(HaveOccurred()) - dnsPolicyBuilder = testutil.NewDNSPolicyBuilder("test-dns-policy", testNamespace) - dnsPolicyBuilder.WithTargetGateway(TestGatewayName) + dnsPolicyBuilder = testutil.NewDNSPolicyBuilder("test-dns-policy", testNamespace). + WithProviderManagedZone(managedZone.Name). + WithTargetGateway(TestGatewayName) lbHash = dns.ToBase36hash(fmt.Sprintf("%s-%s", gateway.Name, gateway.Namespace)) recordName = fmt.Sprintf("%s-%s", TestGatewayName, TestListenerNameOne) @@ -149,7 +150,8 @@ var _ = Describe("DNSPolicy Multi Cluster", func() { MatchFields(IgnoreExtras, Fields{ "ObjectMeta": HaveField("Name", recordName), "Spec": MatchFields(IgnoreExtras, Fields{ - "ManagedZoneRef": HaveField("Name", "mz-example-com"), + "ZoneID": PointTo(Equal(managedZone.Spec.ID)), + "ProviderRef": Equal(dnsPolicy.Spec.ProviderRef), "Endpoints": ConsistOf( PointTo(MatchFields(IgnoreExtras, Fields{ "DNSName": Equal(TestHostOne), @@ -164,7 +166,8 @@ var _ = Describe("DNSPolicy Multi Cluster", func() { MatchFields(IgnoreExtras, Fields{ "ObjectMeta": HaveField("Name", wildcardRecordName), "Spec": MatchFields(IgnoreExtras, Fields{ - "ManagedZoneRef": HaveField("Name", "mz-example-com"), + "ZoneID": PointTo(Equal(managedZone.Spec.ID)), + "ProviderRef": Equal(dnsPolicy.Spec.ProviderRef), "Endpoints": ConsistOf( PointTo(MatchFields(IgnoreExtras, Fields{ "DNSName": Equal(TestHostWildcard), @@ -207,7 +210,8 @@ var _ = Describe("DNSPolicy Multi Cluster", func() { MatchFields(IgnoreExtras, Fields{ "ObjectMeta": HaveField("Name", recordName), "Spec": MatchFields(IgnoreExtras, Fields{ - "ManagedZoneRef": HaveField("Name", "mz-example-com"), + "ZoneID": PointTo(Equal(managedZone.Spec.ID)), + "ProviderRef": Equal(dnsPolicy.Spec.ProviderRef), "Endpoints": ConsistOf( PointTo(MatchFields(IgnoreExtras, Fields{ "DNSName": Equal("2w705o.lb-" + lbHash + ".test.example.com"), @@ -260,7 +264,8 @@ var _ = Describe("DNSPolicy Multi Cluster", func() { MatchFields(IgnoreExtras, Fields{ "ObjectMeta": HaveField("Name", wildcardRecordName), "Spec": MatchFields(IgnoreExtras, Fields{ - "ManagedZoneRef": HaveField("Name", "mz-example-com"), + "ZoneID": PointTo(Equal(managedZone.Spec.ID)), + "ProviderRef": Equal(dnsPolicy.Spec.ProviderRef), "Endpoints": ConsistOf( PointTo(MatchFields(IgnoreExtras, Fields{ "DNSName": Equal("2w705o.lb-" + lbHash + ".example.com"), @@ -337,7 +342,8 @@ var _ = Describe("DNSPolicy Multi Cluster", func() { MatchFields(IgnoreExtras, Fields{ "ObjectMeta": HaveField("Name", recordName), "Spec": MatchFields(IgnoreExtras, Fields{ - "ManagedZoneRef": HaveField("Name", "mz-example-com"), + "ZoneID": PointTo(Equal(managedZone.Spec.ID)), + "ProviderRef": Equal(dnsPolicy.Spec.ProviderRef), "Endpoints": ConsistOf( PointTo(MatchFields(IgnoreExtras, Fields{ "DNSName": Equal("2w705o.lb-" + lbHash + ".test.example.com"), @@ -398,7 +404,8 @@ var _ = Describe("DNSPolicy Multi Cluster", func() { MatchFields(IgnoreExtras, Fields{ "ObjectMeta": HaveField("Name", wildcardRecordName), "Spec": MatchFields(IgnoreExtras, Fields{ - "ManagedZoneRef": HaveField("Name", "mz-example-com"), + "ZoneID": PointTo(Equal(managedZone.Spec.ID)), + "ProviderRef": Equal(dnsPolicy.Spec.ProviderRef), "Endpoints": ConsistOf( PointTo(MatchFields(IgnoreExtras, Fields{ "DNSName": Equal("2w705o.lb-" + lbHash + ".example.com"), diff --git a/test/policy_integration/dnspolicy_controller_single_cluster_test.go b/test/policy_integration/dnspolicy_controller_single_cluster_test.go index d800f2754..0a9b2118e 100644 --- a/test/policy_integration/dnspolicy_controller_single_cluster_test.go +++ b/test/policy_integration/dnspolicy_controller_single_cluster_test.go @@ -73,8 +73,9 @@ var _ = Describe("DNSPolicy Single Cluster", func() { return k8sClient.Status().Update(ctx, gateway) }, TestTimeoutMedium, TestRetryIntervalMedium).Should(Succeed()) - dnsPolicyBuilder = testutil.NewDNSPolicyBuilder("test-dns-policy", testNamespace) - dnsPolicyBuilder.WithTargetGateway(TestGatewayName) + dnsPolicyBuilder = testutil.NewDNSPolicyBuilder("test-dns-policy", testNamespace). + WithProviderManagedZone(managedZone.Name). + WithTargetGateway(TestGatewayName) lbHash = dns.ToBase36hash(fmt.Sprintf("%s-%s", gateway.Name, gateway.Namespace)) recordName = fmt.Sprintf("%s-%s", TestGatewayName, TestListenerNameOne) @@ -120,7 +121,8 @@ var _ = Describe("DNSPolicy Single Cluster", func() { MatchFields(IgnoreExtras, Fields{ "ObjectMeta": HaveField("Name", recordName), "Spec": MatchFields(IgnoreExtras, Fields{ - "ManagedZoneRef": HaveField("Name", "mz-example-com"), + "ZoneID": PointTo(Equal(managedZone.Spec.ID)), + "ProviderRef": Equal(dnsPolicy.Spec.ProviderRef), "Endpoints": ConsistOf( PointTo(MatchFields(IgnoreExtras, Fields{ "DNSName": Equal(TestHostOne), @@ -135,7 +137,8 @@ var _ = Describe("DNSPolicy Single Cluster", func() { MatchFields(IgnoreExtras, Fields{ "ObjectMeta": HaveField("Name", wildcardRecordName), "Spec": MatchFields(IgnoreExtras, Fields{ - "ManagedZoneRef": HaveField("Name", "mz-example-com"), + "ZoneID": PointTo(Equal(managedZone.Spec.ID)), + "ProviderRef": Equal(dnsPolicy.Spec.ProviderRef), "Endpoints": ConsistOf( PointTo(MatchFields(IgnoreExtras, Fields{ "DNSName": Equal(TestHostWildcard), @@ -172,7 +175,8 @@ var _ = Describe("DNSPolicy Single Cluster", func() { MatchFields(IgnoreExtras, Fields{ "ObjectMeta": HaveField("Name", recordName), "Spec": MatchFields(IgnoreExtras, Fields{ - "ManagedZoneRef": HaveField("Name", "mz-example-com"), + "ZoneID": PointTo(Equal(managedZone.Spec.ID)), + "ProviderRef": Equal(dnsPolicy.Spec.ProviderRef), "Endpoints": ConsistOf( PointTo(MatchFields(IgnoreExtras, Fields{ "DNSName": Equal("19sc9b.lb-" + lbHash + ".test.example.com"), @@ -210,7 +214,8 @@ var _ = Describe("DNSPolicy Single Cluster", func() { MatchFields(IgnoreExtras, Fields{ "ObjectMeta": HaveField("Name", wildcardRecordName), "Spec": MatchFields(IgnoreExtras, Fields{ - "ManagedZoneRef": HaveField("Name", "mz-example-com"), + "ZoneID": PointTo(Equal(managedZone.Spec.ID)), + "ProviderRef": Equal(dnsPolicy.Spec.ProviderRef), "Endpoints": ContainElements( PointTo(MatchFields(IgnoreExtras, Fields{ "DNSName": Equal("19sc9b.lb-" + lbHash + ".example.com"), diff --git a/test/policy_integration/dnspolicy_controller_test.go b/test/policy_integration/dnspolicy_controller_test.go index b742fd9cb..5623d28a5 100644 --- a/test/policy_integration/dnspolicy_controller_test.go +++ b/test/policy_integration/dnspolicy_controller_test.go @@ -43,7 +43,8 @@ var _ = Describe("DNSPolicy", func() { managedZone = testutil.NewManagedZoneBuilder("mz-example-com", testNamespace, "example.com").ManagedZone Expect(k8sClient.Create(ctx, managedZone)).To(Succeed()) - dnsPolicyBuilder = testutil.NewDNSPolicyBuilder("test-dns-policy", testNamespace) + dnsPolicyBuilder = testutil.NewDNSPolicyBuilder("test-dns-policy", testNamespace). + WithProviderManagedZone(managedZone.Name) }) AfterEach(func() { diff --git a/test/policy_integration/managedzone_controller_test.go b/test/policy_integration/managedzone_controller_test.go index d3e55ffff..79c3ac1ba 100644 --- a/test/policy_integration/managedzone_controller_test.go +++ b/test/policy_integration/managedzone_controller_test.go @@ -41,9 +41,10 @@ var _ = Describe("ManagedZoneReconciler", func() { Spec: v1alpha1.ManagedZoneSpec{ ID: testutil.Domain, DomainName: testutil.Domain, - SecretRef: &v1alpha1.SecretRef{ + ProviderRef: &v1alpha1.ProviderRef{ Name: providerCredential, Namespace: defaultNS, + Kind: v1alpha1.ProviderKindSecret, }, }, } diff --git a/test/policy_integration/suite_test.go b/test/policy_integration/suite_test.go index 80c9effdb..c52fcf771 100644 --- a/test/policy_integration/suite_test.go +++ b/test/policy_integration/suite_test.go @@ -61,7 +61,7 @@ var ( ctx context.Context cancel context.CancelFunc logger logr.Logger - providerFactory = func(ctx context.Context, managedZone *v1alpha1.ManagedZone) (dns.Provider, error) { + providerFactory = func(ctx context.Context, providerRef *v1alpha1.ProviderRef) (dns.Provider, error) { return &dns.FakeProvider{}, nil } ) diff --git a/test/util/test_dnspolicy_types.go b/test/util/test_dnspolicy_types.go index 846a13d2b..0156dde78 100644 --- a/test/util/test_dnspolicy_types.go +++ b/test/util/test_dnspolicy_types.go @@ -32,6 +32,11 @@ func (t *DNSPolicyBuilder) WithTargetRef(targetRef gatewayapiv1alpha2.PolicyTarg return t } +func (t *DNSPolicyBuilder) WithProviderRef(providerRef v1alpha1.ProviderRef) *DNSPolicyBuilder { + t.Spec.ProviderRef = &providerRef + return t +} + func (t *DNSPolicyBuilder) WithHealthCheck(healthCheck v1alpha1.HealthCheckSpec) *DNSPolicyBuilder { t.Spec.HealthCheck = &healthCheck return t @@ -59,6 +64,16 @@ func (t *DNSPolicyBuilder) WithTargetGateway(gwName string) *DNSPolicyBuilder { }) } +//ProviderRef + +func (t *DNSPolicyBuilder) WithProviderManagedZone(mzName string) *DNSPolicyBuilder { + return t.WithProviderRef(v1alpha1.ProviderRef{ + Name: mzName, + Namespace: t.GetNamespace(), + Kind: v1alpha1.ProviderKindManagedZone, + }) +} + //HealthCheck func (t *DNSPolicyBuilder) WithHealthCheckFor(endpoint string, port *int, protocol v1alpha1.HealthProtocol, failureThreshold *int) *DNSPolicyBuilder { @@ -121,9 +136,10 @@ func NewManagedZoneBuilder(name, ns, domainName string) *ManagedZoneBuilder { ID: "1234", DomainName: domainName, Description: domainName, - SecretRef: &v1alpha1.SecretRef{ + ProviderRef: &v1alpha1.ProviderRef{ Name: "secretname", Namespace: ns, + Kind: "Secret", }, }, },