Remove createTestServer (#981)
* Remove createTestServer * more cleanups * comment tweak * sort * sigh
This commit is contained in:
parent
e06863d2be
commit
932639ac99
1 changed files with 11 additions and 26 deletions
|
@ -660,52 +660,34 @@ var dnsTestCasesFallthrough = []test.Case{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestServer(t *testing.T, corefile string) (*caddy.Instance, string) {
|
func doIntegrationTests(t *testing.T, corefile string, testCases []test.Case) {
|
||||||
server, err := CoreDNSServer(corefile)
|
server, udp, _, err := CoreDNSServerAndPorts(corefile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
|
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
udp, _ := CoreDNSServerPorts(server, 0)
|
|
||||||
if udp == "" {
|
|
||||||
t.Fatalf("Could not get UDP listening port")
|
|
||||||
}
|
|
||||||
|
|
||||||
return server, udp
|
|
||||||
}
|
|
||||||
|
|
||||||
func doIntegrationTests(t *testing.T, corefile string, testCases []test.Case) {
|
|
||||||
server, udp := createTestServer(t, corefile)
|
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
// Work-around for timing condition that results in no-data being returned in
|
// Work-around for timing condition that results in no-data being returned in test environment.
|
||||||
// test environment.
|
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
||||||
dnsClient := new(dns.Client)
|
c := new(dns.Client)
|
||||||
dnsMessage := new(dns.Msg)
|
m := tc.Msg()
|
||||||
|
|
||||||
dnsMessage.SetQuestion(tc.Qname, tc.Qtype)
|
res, _, err := c.Exchange(m, udp)
|
||||||
|
|
||||||
res, _, err := dnsClient.Exchange(dnsMessage, udp)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Could not send query: %s", err)
|
t.Fatalf("Could not send query: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before sorting, make sure that CNAMES do not appear after their target records
|
// Before sorting, make sure that CNAMES do not appear after their target records and then sort the tc.
|
||||||
test.CNAMEOrder(t, res)
|
test.CNAMEOrder(t, res)
|
||||||
|
|
||||||
// Sorting the test cases to check with the response
|
|
||||||
sort.Sort(test.RRSet(tc.Answer))
|
sort.Sort(test.RRSet(tc.Answer))
|
||||||
sort.Sort(test.RRSet(tc.Ns))
|
sort.Sort(test.RRSet(tc.Ns))
|
||||||
sort.Sort(test.RRSet(tc.Extra))
|
sort.Sort(test.RRSet(tc.Extra))
|
||||||
|
|
||||||
test.SortAndCheck(t, res, tc)
|
test.SortAndCheck(t, res, tc)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createUpstreamServer(t *testing.T) (func(), *caddy.Instance, string) {
|
func createUpstreamServer(t *testing.T) (func(), *caddy.Instance, string) {
|
||||||
|
@ -719,7 +701,10 @@ func createUpstreamServer(t *testing.T) (func(), *caddy.Instance, string) {
|
||||||
drop 0
|
drop 0
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
server, udp := createTestServer(t, upstreamServerCorefile)
|
server, udp, _, err := CoreDNSServerAndPorts(upstreamServerCorefile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
|
||||||
|
}
|
||||||
return rmfile, server, udp
|
return rmfile, server, udp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue