Use verify for NodeLookup CNAME, and TXT tests

This commit is contained in:
Patrick Sodré 2017-08-10 02:02:39 -04:00 committed by Frank Schroeder
parent d5e3b9d843
commit 12fb0bfd5b
No known key found for this signature in database
GPG Key ID: 4D65C6EAEC87DECD

View File

@ -343,21 +343,25 @@ func TestDNS_NodeLookup_CNAME(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
// Should have the service, CNAME, A, and TXT records wantAnswer := []dns.RR{
if len(in.Answer) != 4 { &dns.CNAME{
t.Fatalf("Bad: %#v", in) Hdr: dns.RR_Header{Name: "google.node.consul.", Rrtype: dns.TypeCNAME, Class: dns.ClassINET, Ttl: 0, Rdlength: 0x10},
} Target: "www.google.com.",
},
cnRec, ok := in.Answer[0].(*dns.CNAME) &dns.CNAME{
if !ok { Hdr: dns.RR_Header{Name: "www.google.com.", Rrtype: dns.TypeCNAME, Class: dns.ClassINET, Rdlength: 0x2},
t.Fatalf("Bad: %#v", in.Answer[0]) Target: "google.com.",
} },
if cnRec.Target != "www.google.com." { &dns.A{
t.Fatalf("Bad: %#v", in.Answer[0]) Hdr: dns.RR_Header{Name: "google.com.", Rrtype: dns.TypeA, Class: dns.ClassINET, Rdlength: 0x4},
} A: []byte{0x1, 0x2, 0x3, 0x4}, // 1.2.3.4
if cnRec.Hdr.Ttl != 0 { },
t.Fatalf("Bad: %#v", in.Answer[0]) &dns.TXT{
Hdr: dns.RR_Header{Name: "google.com.", Rrtype: dns.TypeTXT, Class: dns.ClassINET, Rdlength: 0xd},
Txt: []string{"my_txt_value"},
},
} }
verify.Values(t, "answer", in.Answer, wantAnswer)
} }
func TestDNS_NodeLookup_TXT(t *testing.T) { func TestDNS_NodeLookup_TXT(t *testing.T) {
@ -436,10 +440,18 @@ func TestDNS_NodeLookup_ANY(t *testing.T) {
t.Fatalf("err: %v", err) t.Fatalf("err: %v", err)
} }
// Should have 1 A and 1 TXT record wantAnswer := []dns.RR{
if len(in.Answer) != 2 { &dns.A{
t.Fatalf("Bad: %#v", in) Hdr: dns.RR_Header{Name: "bar.node.consul.", Rrtype: dns.TypeA, Class: dns.ClassINET, Rdlength: 0x4},
A: []byte{0x7f, 0x0, 0x0, 0x1}, // 127.0.0.1
},
&dns.TXT{
Hdr: dns.RR_Header{Name: "bar.node.consul.", Rrtype: dns.TypeTXT, Class: dns.ClassINET, Rdlength: 0xa},
Txt: []string{"key=value"},
},
} }
verify.Values(t, "answer", in.Answer, wantAnswer)
} }
func TestDNS_EDNS0(t *testing.T) { func TestDNS_EDNS0(t *testing.T) {