Skip to content

Commit

Permalink
test(rrset): Add 'wrong record format' test
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony TREUILLIER <[email protected]>
  • Loading branch information
antrema committed Oct 29, 2024
1 parent 18876f1 commit 1cc92e6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
59 changes: 59 additions & 0 deletions internal/controller/rrset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1119,4 +1119,63 @@ var _ = Describe("RRset Controller", func() {
Expect(createdResource.GetFinalizers()).To(ContainElement(FINALIZER_NAME), "RRset should contain the finalizer")
})
})

Context("When creating a wrong RRset", func() {
It("should reconcile the resource with Failed status", Label("wrong-rrset", "wrong-format"), func() {
ctx := context.Background()
// Specific test variables
badFormatResourceName := "wrong-format"
badFormatResourceDNSName := "_wrong._record.format"
badFormatResourceType := "SRV"
badFormatResourceRecords := []string{"1 50 25565 test2.helloworld.com"}
badFormatResourceComment := "This is a wrong-format Record"

By("Creating the RRset resource")
badFormatResource := &dnsv1alpha1.RRset{
ObjectMeta: metav1.ObjectMeta{
Name: badFormatResourceName,
Namespace: resourceNamespace,
},
}
badFormatResource.SetResourceVersion("")
_, err := controllerutil.CreateOrUpdate(ctx, k8sClient, badFormatResource, func() error {
badFormatResource.Spec = dnsv1alpha1.RRsetSpec{
ZoneRef: dnsv1alpha1.ZoneRef{
Name: zoneName,
},
Type: badFormatResourceType,
Name: badFormatResourceDNSName,
TTL: resourceTTL,
Records: badFormatResourceRecords,
Comment: &badFormatResourceComment,
}
return nil
})
badFormatRRsetLookupKey := types.NamespacedName{
Name: badFormatResourceName,
Namespace: resourceNamespace,
}

Expect(err).NotTo(HaveOccurred())
Eventually(func() bool {
err := k8sClient.Get(ctx, badFormatRRsetLookupKey, badFormatResource)
return err == nil && badFormatResource.Status.SyncStatus != nil
}, timeout, interval).Should(BeTrue())

DnsFqdn := getRRsetName(badFormatResource)

By("Getting the created resource")
createdResource := &dnsv1alpha1.RRset{}
Eventually(func() bool {
err := k8sClient.Get(ctx, badFormatRRsetLookupKey, createdResource)
return err == nil
}, timeout, interval).Should(BeTrue())

Expect(getMockedRecordsForType(DnsFqdn, badFormatResourceType)).To(Equal([]string{}), "RRset should not have been created in backend")
Expect(*createdResource.Status.SyncStatus).To(Equal(FAILED_STATUS), "RRset status should be 'Failed'")
Expect(createdResource.GetOwnerReferences()).NotTo(BeEmpty(), "RRset should have setOwnerReference")
Expect(createdResource.GetOwnerReferences()[0].Name).To(Equal(zoneRef), "RRset should have setOwnerReference to Zone")
Expect(createdResource.GetFinalizers()).To(ContainElement(FINALIZER_NAME), "RRset should contain the finalizer")
})
})
})
9 changes: 9 additions & 0 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ func (m mockRecordsClient) Change(ctx context.Context, domain string, name strin
}
}

// Preliminary test - Linked to 'wrong-rrset && wrong-format' test
if string(recordType) == "SRV" && content[0] == strings.TrimSuffix(content[0], ".") {
return &powerdns.Error{
StatusCode: 422,
Status: "422 Unprocessable Entity",
Message: "Record " + name + "/SRV '" + strings.Join(content, ",") + "': Not in expected format (parsed as '" + strings.Join(content, ",") + ".')",
}
}

var isRRsetIdentical, isNewRRset, ok bool
var rrset *powerdns.RRset
var comment, specifiedComment string
Expand Down

0 comments on commit 1cc92e6

Please sign in to comment.