aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Yong Tang <yongtang@users.noreply.github.com> 2016-10-11 12:25:50 -0700
committerGravatar Miek Gieben <miek@miek.nl> 2016-10-11 20:25:50 +0100
commitbaea5eef2fd33f99a0612d413311dc0a15889a77 (patch)
treef2f5fafc0aed17368bd2d846c9d7adea0de827eb
parentf3066b94637b4278492dea13e9dea05e6abc0f0f (diff)
downloadcoredns-baea5eef2fd33f99a0612d413311dc0a15889a77.tar.gz
coredns-baea5eef2fd33f99a0612d413311dc0a15889a77.tar.zst
coredns-baea5eef2fd33f99a0612d413311dc0a15889a77.zip
Add a unit test for DuplicateCNAME (#329)
This fix adds a unit test for DuplicateCNAME to have a basic coverage for dnsutil. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
-rw-r--r--middleware/pkg/dnsutil/cname_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/middleware/pkg/dnsutil/cname_test.go b/middleware/pkg/dnsutil/cname_test.go
new file mode 100644
index 000000000..d122fdf52
--- /dev/null
+++ b/middleware/pkg/dnsutil/cname_test.go
@@ -0,0 +1,55 @@
+package dnsutil
+
+import (
+ "testing"
+
+ "github.com/miekg/dns"
+)
+
+func TestDuplicateCNAME(t *testing.T) {
+ tests := []struct {
+ cname string
+ records []string
+ expected bool
+ }{
+ {
+ "1.0.0.192.IN-ADDR.ARPA. 3600 IN CNAME 1.0.0.0.192.IN-ADDR.ARPA.",
+ []string{
+ "US. 86400 IN NSEC 0-.us. NS SOA RRSIG NSEC DNSKEY TYPE65534",
+ "1.0.0.192.IN-ADDR.ARPA. 3600 IN CNAME 1.0.0.0.192.IN-ADDR.ARPA.",
+ },
+ true,
+ },
+ {
+ "1.0.0.192.IN-ADDR.ARPA. 3600 IN CNAME 1.0.0.0.192.IN-ADDR.ARPA.",
+ []string{
+ "US. 86400 IN NSEC 0-.us. NS SOA RRSIG NSEC DNSKEY TYPE65534",
+ },
+ false,
+ },
+ {
+ "1.0.0.192.IN-ADDR.ARPA. 3600 IN CNAME 1.0.0.0.192.IN-ADDR.ARPA.",
+ []string{},
+ false,
+ },
+ }
+ for i, test := range tests {
+ cnameRR, err := dns.NewRR(test.cname)
+ if err != nil {
+ t.Fatal("Test %d, cname ('%s') error (%s)!", i, test.cname, err)
+ }
+ cname := cnameRR.(*dns.CNAME)
+ records := []dns.RR{}
+ for j, r := range test.records {
+ rr, err := dns.NewRR(r)
+ if err != nil {
+ t.Fatal("Test %d, record %d ('%s') error (%s)!", i, j, r, err)
+ }
+ records = append(records, rr)
+ }
+ got := DuplicateCNAME(cname, records)
+ if got != test.expected {
+ t.Errorf("Test %d, expected '%v', got '%v' for CNAME ('%s') and RECORDS (%v)", i, test.expected, got, test.cname, test.records)
+ }
+ }
+}