Skip to content

Commit

Permalink
Added DNS test case that returns both CNAME and A records
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravi Sankar Penta committed May 22, 2018
1 parent 2a614a2 commit aac3da0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/network/common/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"net"
"os"
"strings"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -37,13 +38,21 @@ func TestAddDNS(t *testing.T) {
ip := net.ParseIP("10.11.12.13")
tests := []dnsTest{
{
testCase: "Test valid domain name",
testCase: "Test valid domain name with resolver returning only A record",
domainName: "example.com",
dnsResolverOutput: "example.com. 600 IN A 10.11.12.13",
ips: []net.IP{ip},
ttl: 600,
expectFailure: false,
},
{
testCase: "Test valid domain name with resolver returning both CNAME and A records",
domainName: "example.com",
dnsResolverOutput: "example.com. 200 IN CNAME foo.example.com.\nfoo.example.com. 600 IN A 10.11.12.13",
ips: []net.IP{ip},
ttl: 600,
expectFailure: false,
},
{
testCase: "Test invalid domain name",
domainName: "sads@#$.com",
Expand Down Expand Up @@ -211,9 +220,12 @@ func dummyServer(output string) func(dns.ResponseWriter, *dns.Msg) {
m := new(dns.Msg)
m.SetReply(req)

m.Answer = make([]dns.RR, 1)
mx, _ := dns.NewRR(output)
m.Answer[0] = mx
answers := strings.Split(output, "\n")
m.Answer = make([]dns.RR, len(answers))
for i, ans := range answers {
mx, _ := dns.NewRR(ans)
m.Answer[i] = mx
}
w.WriteMsg(m)
}
}
Expand Down

0 comments on commit aac3da0

Please sign in to comment.