Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikenairn committed Nov 14, 2023
1 parent 7a1d761 commit 536554c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 25 deletions.
3 changes: 2 additions & 1 deletion test/gateway_integration/gateway_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
}),
}),
))
Expand Down
23 changes: 15 additions & 8 deletions test/policy_integration/dnspolicy_controller_multi_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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"),
Expand Down
3 changes: 2 additions & 1 deletion test/policy_integration/dnspolicy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion test/policy_integration/managedzone_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion test/policy_integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)
Expand Down
18 changes: 17 additions & 1 deletion test/util/test_dnspolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
},
},
},
Expand Down

0 comments on commit 536554c

Please sign in to comment.