Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
23ed465b
Commit
23ed465b
authored
Mar 28, 2016
by
Miek Gieben
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #51 from miekg/factor-testing
Add testing package
parents
5a919198
6eae17b0
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
295 additions
and
304 deletions
+295
-304
middleware/etcd/cname_test.go
middleware/etcd/cname_test.go
+13
-12
middleware/etcd/group_test.go
middleware/etcd/group_test.go
+13
-12
middleware/etcd/handler.go
middleware/etcd/handler.go
+1
-1
middleware/etcd/lookup_test.go
middleware/etcd/lookup_test.go
+46
-44
middleware/etcd/multi_test.go
middleware/etcd/multi_test.go
+12
-23
middleware/etcd/other_test.go
middleware/etcd/other_test.go
+21
-20
middleware/etcd/setup_test.go
middleware/etcd/setup_test.go
+8
-141
middleware/file/lookup_test.go
middleware/file/lookup_test.go
+29
-51
middleware/testing/helpers.go
middleware/testing/helpers.go
+152
-0
No files found.
middleware/etcd/cname_test.go
View file @
23ed465b
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/etcd/msg"
"github.com/miekg/coredns/middleware/etcd/msg"
coretest
"github.com/miekg/coredns/middleware/testing"
"github.com/miekg/dns"
"github.com/miekg/dns"
)
)
...
@@ -53,14 +54,14 @@ func TestCnameLookup(t *testing.T) {
...
@@ -53,14 +54,14 @@ func TestCnameLookup(t *testing.T) {
continue
continue
}
}
if
!
c
heckSection
(
t
,
tc
,
Answer
,
resp
.
Answer
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Answer
,
resp
.
Answer
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
if
!
c
heckSection
(
t
,
tc
,
Ns
,
resp
.
Ns
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Ns
,
resp
.
Ns
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
if
!
c
heckSection
(
t
,
tc
,
Extra
,
resp
.
Extra
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Extra
,
resp
.
Extra
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
}
}
...
@@ -77,20 +78,20 @@ var servicesCname = []*msg.Service{
...
@@ -77,20 +78,20 @@ var servicesCname = []*msg.Service{
{
Host
:
"10.240.0.1"
,
Key
:
"endpoint.region2.skydns.test."
},
{
Host
:
"10.240.0.1"
,
Key
:
"endpoint.region2.skydns.test."
},
}
}
var
dnsTestCasesCname
=
[]
dnsTest
Case
{
var
dnsTestCasesCname
=
[]
coretest
.
Case
{
{
{
Qname
:
"a.server1.dev.region1.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Qname
:
"a.server1.dev.region1.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
SRV
(
"a.server1.dev.region1.skydns.test. 300 IN SRV 10 100 0 cname1.region2.skydns.test."
),
coretest
.
SRV
(
"a.server1.dev.region1.skydns.test. 300 IN SRV 10 100 0 cname1.region2.skydns.test."
),
},
},
Extra
:
[]
dns
.
RR
{
Extra
:
[]
dns
.
RR
{
new
CNAME
(
"cname1.region2.skydns.test. 300 IN CNAME cname2.region2.skydns.test."
),
coretest
.
CNAME
(
"cname1.region2.skydns.test. 300 IN CNAME cname2.region2.skydns.test."
),
new
CNAME
(
"cname2.region2.skydns.test. 300 IN CNAME cname3.region2.skydns.test."
),
coretest
.
CNAME
(
"cname2.region2.skydns.test. 300 IN CNAME cname3.region2.skydns.test."
),
new
CNAME
(
"cname3.region2.skydns.test. 300 IN CNAME cname4.region2.skydns.test."
),
coretest
.
CNAME
(
"cname3.region2.skydns.test. 300 IN CNAME cname4.region2.skydns.test."
),
new
CNAME
(
"cname4.region2.skydns.test. 300 IN CNAME cname5.region2.skydns.test."
),
coretest
.
CNAME
(
"cname4.region2.skydns.test. 300 IN CNAME cname5.region2.skydns.test."
),
new
CNAME
(
"cname5.region2.skydns.test. 300 IN CNAME cname6.region2.skydns.test."
),
coretest
.
CNAME
(
"cname5.region2.skydns.test. 300 IN CNAME cname6.region2.skydns.test."
),
new
CNAME
(
"cname6.region2.skydns.test. 300 IN CNAME endpoint.region2.skydns.test."
),
coretest
.
CNAME
(
"cname6.region2.skydns.test. 300 IN CNAME endpoint.region2.skydns.test."
),
new
A
(
"endpoint.region2.skydns.test. 300 IN A 10.240.0.1"
),
coretest
.
A
(
"endpoint.region2.skydns.test. 300 IN A 10.240.0.1"
),
},
},
},
},
}
}
middleware/etcd/group_test.go
View file @
23ed465b
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/etcd/msg"
"github.com/miekg/coredns/middleware/etcd/msg"
coretest
"github.com/miekg/coredns/middleware/testing"
"github.com/miekg/dns"
"github.com/miekg/dns"
)
)
...
@@ -33,9 +34,9 @@ func TestGroupLookup(t *testing.T) {
...
@@ -33,9 +34,9 @@ func TestGroupLookup(t *testing.T) {
}
}
resp
:=
rec
.
Msg
()
resp
:=
rec
.
Msg
()
sort
.
Sort
(
rr
Set
(
resp
.
Answer
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Answer
))
sort
.
Sort
(
rr
Set
(
resp
.
Ns
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Ns
))
sort
.
Sort
(
rr
Set
(
resp
.
Extra
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Extra
))
if
resp
.
Rcode
!=
tc
.
Rcode
{
if
resp
.
Rcode
!=
tc
.
Rcode
{
t
.
Errorf
(
"rcode is %q, expected %q"
,
dns
.
RcodeToString
[
resp
.
Rcode
],
dns
.
RcodeToString
[
tc
.
Rcode
])
t
.
Errorf
(
"rcode is %q, expected %q"
,
dns
.
RcodeToString
[
resp
.
Rcode
],
dns
.
RcodeToString
[
tc
.
Rcode
])
...
@@ -59,14 +60,14 @@ func TestGroupLookup(t *testing.T) {
...
@@ -59,14 +60,14 @@ func TestGroupLookup(t *testing.T) {
continue
continue
}
}
if
!
c
heckSection
(
t
,
tc
,
Answer
,
resp
.
Answer
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Answer
,
resp
.
Answer
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
if
!
c
heckSection
(
t
,
tc
,
Ns
,
resp
.
Ns
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Ns
,
resp
.
Ns
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
if
!
c
heckSection
(
t
,
tc
,
Extra
,
resp
.
Extra
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Extra
,
resp
.
Extra
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
}
}
...
@@ -84,29 +85,29 @@ var servicesGroup = []*msg.Service{
...
@@ -84,29 +85,29 @@ var servicesGroup = []*msg.Service{
{
Host
:
"127.0.0.2"
,
Key
:
"b.sub.dom1.skydns.test."
,
Group
:
"g2"
},
{
Host
:
"127.0.0.2"
,
Key
:
"b.sub.dom1.skydns.test."
,
Group
:
"g2"
},
}
}
var
dnsTestCasesGroup
=
[]
dnsTest
Case
{
var
dnsTestCasesGroup
=
[]
coretest
.
Case
{
// Groups
// Groups
{
{
// hits the group 'g1' and only includes those records
// hits the group 'g1' and only includes those records
Qname
:
"dom.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"dom.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
A
(
"dom.skydns.test. 300 IN A 127.0.0.1"
),
coretest
.
A
(
"dom.skydns.test. 300 IN A 127.0.0.1"
),
new
A
(
"dom.skydns.test. 300 IN A 127.0.0.2"
),
coretest
.
A
(
"dom.skydns.test. 300 IN A 127.0.0.2"
),
},
},
},
},
{
{
// One has group, the other has not... Include the non-group always.
// One has group, the other has not... Include the non-group always.
Qname
:
"dom2.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"dom2.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
A
(
"dom2.skydns.test. 300 IN A 127.0.0.1"
),
coretest
.
A
(
"dom2.skydns.test. 300 IN A 127.0.0.1"
),
new
A
(
"dom2.skydns.test. 300 IN A 127.0.0.2"
),
coretest
.
A
(
"dom2.skydns.test. 300 IN A 127.0.0.2"
),
},
},
},
},
{
{
// The groups differ.
// The groups differ.
Qname
:
"dom1.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"dom1.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
A
(
"dom1.skydns.test. 300 IN A 127.0.0.1"
),
coretest
.
A
(
"dom1.skydns.test. 300 IN A 127.0.0.1"
),
},
},
},
},
}
}
middleware/etcd/handler.go
View file @
23ed465b
...
@@ -16,7 +16,7 @@ func (e Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
...
@@ -16,7 +16,7 @@ func (e Etcd) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
// are not auth. for *but* do have a stubzone forward for. If we do the stubzone
// are not auth. for *but* do have a stubzone forward for. If we do the stubzone
// handler will handle the request.
// handler will handle the request.
name
:=
state
.
Name
()
name
:=
state
.
Name
()
if
len
(
*
e
.
Stubmap
)
>
0
{
if
e
.
Stubmap
!=
nil
&&
len
(
*
e
.
Stubmap
)
>
0
{
for
zone
,
_
:=
range
*
e
.
Stubmap
{
for
zone
,
_
:=
range
*
e
.
Stubmap
{
if
strings
.
HasSuffix
(
name
,
zone
)
{
if
strings
.
HasSuffix
(
name
,
zone
)
{
stub
:=
Stub
{
Etcd
:
e
,
Zone
:
zone
}
stub
:=
Stub
{
Etcd
:
e
,
Zone
:
zone
}
...
...
middleware/etcd/lookup_test.go
View file @
23ed465b
...
@@ -8,6 +8,8 @@ package etcd
...
@@ -8,6 +8,8 @@ package etcd
import
(
import
(
"github.com/miekg/coredns/middleware/etcd/msg"
"github.com/miekg/coredns/middleware/etcd/msg"
"github.com/miekg/coredns/middleware/testing"
"github.com/miekg/dns"
"github.com/miekg/dns"
)
)
...
@@ -30,87 +32,87 @@ var services = []*msg.Service{
...
@@ -30,87 +32,87 @@ var services = []*msg.Service{
{
Host
:
"b.cname.skydns.test"
,
Key
:
"a.cname.skydns.test."
},
{
Host
:
"b.cname.skydns.test"
,
Key
:
"a.cname.skydns.test."
},
}
}
var
dnsTestCases
=
[]
dnsTest
Case
{
var
dnsTestCases
=
[]
testing
.
Case
{
// SRV Test
// SRV Test
{
{
Qname
:
"a.server1.dev.region1.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Qname
:
"a.server1.dev.region1.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Answer
:
[]
dns
.
RR
{
new
SRV
(
"a.server1.dev.region1.skydns.test. 300 SRV 10 100 8080 dev.server1."
)},
Answer
:
[]
dns
.
RR
{
testing
.
SRV
(
"a.server1.dev.region1.skydns.test. 300 SRV 10 100 8080 dev.server1."
)},
},
},
// SRV Test (case test)
// SRV Test (case test)
{
{
Qname
:
"a.SERVer1.dEv.region1.skydns.tEst."
,
Qtype
:
dns
.
TypeSRV
,
Qname
:
"a.SERVer1.dEv.region1.skydns.tEst."
,
Qtype
:
dns
.
TypeSRV
,
Answer
:
[]
dns
.
RR
{
new
SRV
(
"a.SERVer1.dEv.region1.skydns.tEst. 300 SRV 10 100 8080 dev.server1."
)},
Answer
:
[]
dns
.
RR
{
testing
.
SRV
(
"a.SERVer1.dEv.region1.skydns.tEst. 300 SRV 10 100 8080 dev.server1."
)},
},
},
// NXDOMAIN Test
// NXDOMAIN Test
{
{
Qname
:
"doesnotexist.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"doesnotexist.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeNameError
,
Rcode
:
dns
.
RcodeNameError
,
Ns
:
[]
dns
.
RR
{
Ns
:
[]
dns
.
RR
{
new
SOA
(
"skydns.test. 300 SOA ns.dns.skydns.test. hostmaster.skydns.test. 0 0 0 0 0"
),
testing
.
SOA
(
"skydns.test. 300 SOA ns.dns.skydns.test. hostmaster.skydns.test. 0 0 0 0 0"
),
},
},
},
},
// A Test
// A Test
{
{
Qname
:
"a.server1.prod.region1.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"a.server1.prod.region1.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Answer
:
[]
dns
.
RR
{
new
A
(
"a.server1.prod.region1.skydns.test. 300 A 10.0.0.1"
)},
Answer
:
[]
dns
.
RR
{
testing
.
A
(
"a.server1.prod.region1.skydns.test. 300 A 10.0.0.1"
)},
},
},
// SRV Test where target is IP address
// SRV Test where target is IP address
{
{
Qname
:
"a.server1.prod.region1.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Qname
:
"a.server1.prod.region1.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Answer
:
[]
dns
.
RR
{
new
SRV
(
"a.server1.prod.region1.skydns.test. 300 SRV 10 100 8080 a.server1.prod.region1.skydns.test."
)},
Answer
:
[]
dns
.
RR
{
testing
.
SRV
(
"a.server1.prod.region1.skydns.test. 300 SRV 10 100 8080 a.server1.prod.region1.skydns.test."
)},
Extra
:
[]
dns
.
RR
{
new
A
(
"a.server1.prod.region1.skydns.test. 300 A 10.0.0.1"
)},
Extra
:
[]
dns
.
RR
{
testing
.
A
(
"a.server1.prod.region1.skydns.test. 300 A 10.0.0.1"
)},
},
},
// AAAA Test
// AAAA Test
{
{
Qname
:
"b.server6.prod.region1.skydns.test."
,
Qtype
:
dns
.
TypeAAAA
,
Qname
:
"b.server6.prod.region1.skydns.test."
,
Qtype
:
dns
.
TypeAAAA
,
Answer
:
[]
dns
.
RR
{
new
AAAA
(
"b.server6.prod.region1.skydns.test. 300 AAAA ::1"
)},
Answer
:
[]
dns
.
RR
{
testing
.
AAAA
(
"b.server6.prod.region1.skydns.test. 300 AAAA ::1"
)},
},
},
// Multiple A Record Test
// Multiple A Record Test
{
{
Qname
:
"server1.prod.region1.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"server1.prod.region1.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
A
(
"server1.prod.region1.skydns.test. 300 A 10.0.0.1"
),
testing
.
A
(
"server1.prod.region1.skydns.test. 300 A 10.0.0.1"
),
new
A
(
"server1.prod.region1.skydns.test. 300 A 10.0.0.2"
),
testing
.
A
(
"server1.prod.region1.skydns.test. 300 A 10.0.0.2"
),
},
},
},
},
// Priority Test
// Priority Test
{
{
Qname
:
"priority.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Qname
:
"priority.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Answer
:
[]
dns
.
RR
{
new
SRV
(
"priority.skydns.test. 300 SRV 333 100 8080 priority.server1."
)},
Answer
:
[]
dns
.
RR
{
testing
.
SRV
(
"priority.skydns.test. 300 SRV 333 100 8080 priority.server1."
)},
},
},
// Subdomain Test
// Subdomain Test
{
{
Qname
:
"sub.region1.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Qname
:
"sub.region1.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
SRV
(
"sub.region1.skydns.test. 300 IN SRV 10 33 0 sub.server1."
),
testing
.
SRV
(
"sub.region1.skydns.test. 300 IN SRV 10 33 0 sub.server1."
),
new
SRV
(
"sub.region1.skydns.test. 300 IN SRV 10 33 80 sub.server2."
),
testing
.
SRV
(
"sub.region1.skydns.test. 300 IN SRV 10 33 80 sub.server2."
),
new
SRV
(
"sub.region1.skydns.test. 300 IN SRV 10 33 8080 c.sub.region1.skydns.test."
),
testing
.
SRV
(
"sub.region1.skydns.test. 300 IN SRV 10 33 8080 c.sub.region1.skydns.test."
),
},
},
Extra
:
[]
dns
.
RR
{
new
A
(
"c.sub.region1.skydns.test. 300 IN A 10.0.0.1"
)},
Extra
:
[]
dns
.
RR
{
testing
.
A
(
"c.sub.region1.skydns.test. 300 IN A 10.0.0.1"
)},
},
},
// CNAME (unresolvable internal name)
// CNAME (unresolvable internal name)
{
{
Qname
:
"cname.prod.region1.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"cname.prod.region1.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Ns
:
[]
dns
.
RR
{
new
SOA
(
"skydns.test. 300 SOA ns.dns.skydns.test. hostmaster.skydns.test. 0 0 0 0 0"
)},
Ns
:
[]
dns
.
RR
{
testing
.
SOA
(
"skydns.test. 300 SOA ns.dns.skydns.test. hostmaster.skydns.test. 0 0 0 0 0"
)},
},
},
// Wildcard Test
// Wildcard Test
{
{
Qname
:
"*.region1.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Qname
:
"*.region1.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 0 sub.server1."
),
testing
.
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 0 sub.server1."
),
new
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 0 unresolvable.skydns.test."
),
testing
.
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 0 unresolvable.skydns.test."
),
new
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 80 sub.server2."
),
testing
.
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 80 sub.server2."
),
new
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 8080 a.server1.prod.region1.skydns.test."
),
testing
.
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 8080 a.server1.prod.region1.skydns.test."
),
new
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 8080 b.server1.prod.region1.skydns.test."
),
testing
.
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 8080 b.server1.prod.region1.skydns.test."
),
new
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 8080 b.server6.prod.region1.skydns.test."
),
testing
.
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 8080 b.server6.prod.region1.skydns.test."
),
new
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 8080 c.sub.region1.skydns.test."
),
testing
.
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 8080 c.sub.region1.skydns.test."
),
new
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 8080 dev.server1."
),
testing
.
SRV
(
"*.region1.skydns.test. 300 IN SRV 10 12 8080 dev.server1."
),
},
},
Extra
:
[]
dns
.
RR
{
Extra
:
[]
dns
.
RR
{
new
A
(
"a.server1.prod.region1.skydns.test. 300 IN A 10.0.0.1"
),
testing
.
A
(
"a.server1.prod.region1.skydns.test. 300 IN A 10.0.0.1"
),
new
A
(
"b.server1.prod.region1.skydns.test. 300 IN A 10.0.0.2"
),
testing
.
A
(
"b.server1.prod.region1.skydns.test. 300 IN A 10.0.0.2"
),
new
AAAA
(
"b.server6.prod.region1.skydns.test. 300 IN AAAA ::1"
),
testing
.
AAAA
(
"b.server6.prod.region1.skydns.test. 300 IN AAAA ::1"
),
new
A
(
"c.sub.region1.skydns.test. 300 IN A 10.0.0.1"
),
testing
.
A
(
"c.sub.region1.skydns.test. 300 IN A 10.0.0.1"
),
},
},
},
},
// Wildcard Test
// Wildcard Test
...
@@ -118,40 +120,40 @@ var dnsTestCases = []dnsTestCase{
...
@@ -118,40 +120,40 @@ var dnsTestCases = []dnsTestCase{
Qname
:
"prod.*.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Qname
:
"prod.*.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
SRV
(
"prod.*.skydns.test. 300 IN SRV 10 25 0 unresolvable.skydns.test."
),
testing
.
SRV
(
"prod.*.skydns.test. 300 IN SRV 10 25 0 unresolvable.skydns.test."
),
new
SRV
(
"prod.*.skydns.test. 300 IN SRV 10 25 8080 a.server1.prod.region1.skydns.test."
),
testing
.
SRV
(
"prod.*.skydns.test. 300 IN SRV 10 25 8080 a.server1.prod.region1.skydns.test."
),
new
SRV
(
"prod.*.skydns.test. 300 IN SRV 10 25 8080 b.server1.prod.region1.skydns.test."
),
testing
.
SRV
(
"prod.*.skydns.test. 300 IN SRV 10 25 8080 b.server1.prod.region1.skydns.test."
),
new
SRV
(
"prod.*.skydns.test. 300 IN SRV 10 25 8080 b.server6.prod.region1.skydns.test."
),
testing
.
SRV
(
"prod.*.skydns.test. 300 IN SRV 10 25 8080 b.server6.prod.region1.skydns.test."
),
},
},
Extra
:
[]
dns
.
RR
{
Extra
:
[]
dns
.
RR
{
new
A
(
"a.server1.prod.region1.skydns.test. 300 IN A 10.0.0.1"
),
testing
.
A
(
"a.server1.prod.region1.skydns.test. 300 IN A 10.0.0.1"
),
new
A
(
"b.server1.prod.region1.skydns.test. 300 IN A 10.0.0.2"
),
testing
.
A
(
"b.server1.prod.region1.skydns.test. 300 IN A 10.0.0.2"
),
new
AAAA
(
"b.server6.prod.region1.skydns.test. 300 IN AAAA ::1"
),
testing
.
AAAA
(
"b.server6.prod.region1.skydns.test. 300 IN AAAA ::1"
),
},
},
},
},
// Wildcard Test
// Wildcard Test
{
{
Qname
:
"prod.any.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Qname
:
"prod.any.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
SRV
(
"prod.any.skydns.test. 300 IN SRV 10 25 0 unresolvable.skydns.test."
),
testing
.
SRV
(
"prod.any.skydns.test. 300 IN SRV 10 25 0 unresolvable.skydns.test."
),
new
SRV
(
"prod.any.skydns.test. 300 IN SRV 10 25 8080 a.server1.prod.region1.skydns.test."
),
testing
.
SRV
(
"prod.any.skydns.test. 300 IN SRV 10 25 8080 a.server1.prod.region1.skydns.test."
),
new
SRV
(
"prod.any.skydns.test. 300 IN SRV 10 25 8080 b.server1.prod.region1.skydns.test."
),
testing
.
SRV
(
"prod.any.skydns.test. 300 IN SRV 10 25 8080 b.server1.prod.region1.skydns.test."
),
new
SRV
(
"prod.any.skydns.test. 300 IN SRV 10 25 8080 b.server6.prod.region1.skydns.test."
),
testing
.
SRV
(
"prod.any.skydns.test. 300 IN SRV 10 25 8080 b.server6.prod.region1.skydns.test."
),
},
},
Extra
:
[]
dns
.
RR
{
Extra
:
[]
dns
.
RR
{
new
A
(
"a.server1.prod.region1.skydns.test. 300 IN A 10.0.0.1"
),
testing
.
A
(
"a.server1.prod.region1.skydns.test. 300 IN A 10.0.0.1"
),
new
A
(
"b.server1.prod.region1.skydns.test. 300 IN A 10.0.0.2"
),
testing
.
A
(
"b.server1.prod.region1.skydns.test. 300 IN A 10.0.0.2"
),
new
AAAA
(
"b.server6.prod.region1.skydns.test. 300 IN AAAA ::1"
),
testing
.
AAAA
(
"b.server6.prod.region1.skydns.test. 300 IN AAAA ::1"
),
},
},
},
},
// CNAME loop detection
// CNAME loop detection
{
{
Qname
:
"a.cname.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"a.cname.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Ns
:
[]
dns
.
RR
{
new
SOA
(
"skydns.test. 300 SOA ns.dns.skydns.test. hostmaster.skydns.test. 1407441600 28800 7200 604800 60"
)},
Ns
:
[]
dns
.
RR
{
testing
.
SOA
(
"skydns.test. 300 SOA ns.dns.skydns.test. hostmaster.skydns.test. 1407441600 28800 7200 604800 60"
)},
},
},
// NODATA Test
// NODATA Test
{
{
Qname
:
"a.server1.dev.region1.skydns.test."
,
Qtype
:
dns
.
TypeTXT
,
Qname
:
"a.server1.dev.region1.skydns.test."
,
Qtype
:
dns
.
TypeTXT
,
Ns
:
[]
dns
.
RR
{
new
SOA
(
"skydns.test. 300 SOA ns.dns.skydns.test. hostmaster.skydns.test. 0 0 0 0 0"
)},
Ns
:
[]
dns
.
RR
{
testing
.
SOA
(
"skydns.test. 300 SOA ns.dns.skydns.test. hostmaster.skydns.test. 0 0 0 0 0"
)},
},
},
}
}
middleware/etcd/multi_test.go
View file @
23ed465b
...
@@ -3,17 +3,15 @@
...
@@ -3,17 +3,15 @@
package
etcd
package
etcd
// etcd needs to be running on http://127.0.0.1:2379
// etcd needs to be running on http://127.0.0.1:2379
// *and* needs connectivity to the internet for remotely resolving
// *and* needs connectivity to the internet for remotely resolving names.
// names.
import
(
import
(
"sort"
"sort"
"testing"
"testing"
"golang.org/x/net/context"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/etcd/msg"
"github.com/miekg/coredns/middleware/etcd/msg"
coretest
"github.com/miekg/coredns/middleware/testing"
"github.com/miekg/dns"
"github.com/miekg/dns"
)
)
...
@@ -21,7 +19,7 @@ import (
...
@@ -21,7 +19,7 @@ import (
func
TestMultiLookup
(
t
*
testing
.
T
)
{
func
TestMultiLookup
(
t
*
testing
.
T
)
{
etcMulti
:=
etc
etcMulti
:=
etc
etcMulti
.
Zones
=
[]
string
{
"skydns.test."
,
"miek.nl."
}
etcMulti
.
Zones
=
[]
string
{
"skydns.test."
,
"miek.nl."
}
etcMulti
.
Next
=
h
andler
()
etcMulti
.
Next
=
coretest
.
ErrorH
andler
()
for
_
,
serv
:=
range
servicesMulti
{
for
_
,
serv
:=
range
servicesMulti
{
set
(
t
,
etcMulti
,
serv
.
Key
,
0
,
serv
)
set
(
t
,
etcMulti
,
serv
.
Key
,
0
,
serv
)
...
@@ -39,9 +37,9 @@ func TestMultiLookup(t *testing.T) {
...
@@ -39,9 +37,9 @@ func TestMultiLookup(t *testing.T) {
}
}
resp
:=
rec
.
Msg
()
resp
:=
rec
.
Msg
()
sort
.
Sort
(
rr
Set
(
resp
.
Answer
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Answer
))
sort
.
Sort
(
rr
Set
(
resp
.
Ns
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Ns
))
sort
.
Sort
(
rr
Set
(
resp
.
Extra
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Extra
))
if
resp
.
Rcode
!=
tc
.
Rcode
{
if
resp
.
Rcode
!=
tc
.
Rcode
{
t
.
Errorf
(
"rcode is %q, expected %q"
,
dns
.
RcodeToString
[
resp
.
Rcode
],
dns
.
RcodeToString
[
tc
.
Rcode
])
t
.
Errorf
(
"rcode is %q, expected %q"
,
dns
.
RcodeToString
[
resp
.
Rcode
],
dns
.
RcodeToString
[
tc
.
Rcode
])
...
@@ -65,14 +63,14 @@ func TestMultiLookup(t *testing.T) {
...
@@ -65,14 +63,14 @@ func TestMultiLookup(t *testing.T) {
continue
continue
}
}
if
!
c
heckSection
(
t
,
tc
,
Answer
,
resp
.
Answer
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Answer
,
resp
.
Answer
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
if
!
c
heckSection
(
t
,
tc
,
Ns
,
resp
.
Ns
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Ns
,
resp
.
Ns
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
if
!
c
heckSection
(
t
,
tc
,
Extra
,
resp
.
Extra
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Extra
,
resp
.
Extra
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
}
}
...
@@ -85,25 +83,16 @@ var servicesMulti = []*msg.Service{
...
@@ -85,25 +83,16 @@ var servicesMulti = []*msg.Service{
{
Host
:
"dev.server1"
,
Port
:
8080
,
Key
:
"a.server1.dev.region1.example.org."
},
{
Host
:
"dev.server1"
,
Port
:
8080
,
Key
:
"a.server1.dev.region1.example.org."
},
}
}
var
dnsTestCasesMulti
=
[]
dnsTest
Case
{
var
dnsTestCasesMulti
=
[]
coretest
.
Case
{
{
{
Qname
:
"a.server1.dev.region1.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Qname
:
"a.server1.dev.region1.skydns.test."
,
Qtype
:
dns
.
TypeSRV
,
Answer
:
[]
dns
.
RR
{
new
SRV
(
"a.server1.dev.region1.skydns.test. 300 SRV 10 100 8080 dev.server1."
)},
Answer
:
[]
dns
.
RR
{
coretest
.
SRV
(
"a.server1.dev.region1.skydns.test. 300 SRV 10 100 8080 dev.server1."
)},
},
},
{
{
Qname
:
"a.server1.dev.region1.miek.nl."
,
Qtype
:
dns
.
TypeSRV
,
Qname
:
"a.server1.dev.region1.miek.nl."
,
Qtype
:
dns
.
TypeSRV
,
Answer
:
[]
dns
.
RR
{
new
SRV
(
"a.server1.dev.region1.miek.nl. 300 SRV 10 100 8080 dev.server1."
)},
Answer
:
[]
dns
.
RR
{
coretest
.
SRV
(
"a.server1.dev.region1.miek.nl. 300 SRV 10 100 8080 dev.server1."
)},
},
},
{
{
Qname
:
"a.server1.dev.region1.example.org."
,
Qtype
:
dns
.
TypeSRV
,
Rcode
:
dns
.
RcodeServerFailure
,
Qname
:
"a.server1.dev.region1.example.org."
,
Qtype
:
dns
.
TypeSRV
,
Rcode
:
dns
.
RcodeServerFailure
,
},
},
}
}
func
handler
()
middleware
.
Handler
{
return
middleware
.
HandlerFunc
(
func
(
ctx
context
.
Context
,
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
(
int
,
error
)
{
m
:=
new
(
dns
.
Msg
)
m
.
SetRcode
(
r
,
dns
.
RcodeServerFailure
)
w
.
WriteMsg
(
m
)
return
dns
.
RcodeServerFailure
,
nil
})
}
middleware/etcd/other_test.go
View file @
23ed465b
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware/etcd/msg"
"github.com/miekg/coredns/middleware/etcd/msg"
coretest
"github.com/miekg/coredns/middleware/testing"
"github.com/miekg/dns"
"github.com/miekg/dns"
)
)
...
@@ -35,9 +36,9 @@ func TestOtherLookup(t *testing.T) {
...
@@ -35,9 +36,9 @@ func TestOtherLookup(t *testing.T) {
}
}
resp
:=
rec
.
Msg
()
resp
:=
rec
.
Msg
()
sort
.
Sort
(
rr
Set
(
resp
.
Answer
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Answer
))
sort
.
Sort
(
rr
Set
(
resp
.
Ns
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Ns
))
sort
.
Sort
(
rr
Set
(
resp
.
Extra
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Extra
))
if
resp
.
Rcode
!=
tc
.
Rcode
{
if
resp
.
Rcode
!=
tc
.
Rcode
{
t
.
Errorf
(
"rcode is %q, expected %q"
,
dns
.
RcodeToString
[
resp
.
Rcode
],
dns
.
RcodeToString
[
tc
.
Rcode
])
t
.
Errorf
(
"rcode is %q, expected %q"
,
dns
.
RcodeToString
[
resp
.
Rcode
],
dns
.
RcodeToString
[
tc
.
Rcode
])
...
@@ -61,14 +62,14 @@ func TestOtherLookup(t *testing.T) {
...
@@ -61,14 +62,14 @@ func TestOtherLookup(t *testing.T) {
continue
continue
}
}
if
!
c
heckSection
(
t
,
tc
,
Answer
,
resp
.
Answer
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Answer
,
resp
.
Answer
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
if
!
c
heckSection
(
t
,
tc
,
Ns
,
resp
.
Ns
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Ns
,
resp
.
Ns
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
if
!
c
heckSection
(
t
,
tc
,
Extra
,
resp
.
Extra
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Extra
,
resp
.
Extra
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
}
}
...
@@ -98,57 +99,57 @@ var servicesOther = []*msg.Service{
...
@@ -98,57 +99,57 @@ var servicesOther = []*msg.Service{
{
Host
:
"10.11.11.10"
,
Key
:
"https.multiport.http.skydns.test."
,
Port
:
443
},
{
Host
:
"10.11.11.10"
,
Key
:
"https.multiport.http.skydns.test."
,
Port
:
443
},
}
}
var
dnsTestCasesOther
=
[]
dnsTest
Case
{
var
dnsTestCasesOther
=
[]
coretest
.
Case
{
// MX Tests
// MX Tests
{
{
// NODATA as this is not an Mail: true record.
// NODATA as this is not an Mail: true record.
Qname
:
"a.server1.dev.region1.skydns.test."
,
Qtype
:
dns
.
TypeMX
,
Qname
:
"a.server1.dev.region1.skydns.test."
,
Qtype
:
dns
.
TypeMX
,
Ns
:
[]
dns
.
RR
{
Ns
:
[]
dns
.
RR
{
new
SOA
(
"skydns.test. 300 SOA ns.dns.skydns.test. hostmaster.skydns.test. 0 0 0 0 0"
),
coretest
.
SOA
(
"skydns.test. 300 SOA ns.dns.skydns.test. hostmaster.skydns.test. 0 0 0 0 0"
),
},
},
},
},
{
{
Qname
:
"a.mail.skydns.test."
,
Qtype
:
dns
.
TypeMX
,
Qname
:
"a.mail.skydns.test."
,
Qtype
:
dns
.
TypeMX
,
Answer
:
[]
dns
.
RR
{
new
MX
(
"a.mail.skydns.test. 300 IN MX 50 mx.skydns.test."
)},
Answer
:
[]
dns
.
RR
{
coretest
.
MX
(
"a.mail.skydns.test. 300 IN MX 50 mx.skydns.test."
)},
Extra
:
[]
dns
.
RR
{
Extra
:
[]
dns
.
RR
{
new
A
(
"a.ipaddr.skydns.test. 300 IN A 172.16.1.1"
),
coretest
.
A
(
"a.ipaddr.skydns.test. 300 IN A 172.16.1.1"
),
new
CNAME
(
"mx.skydns.test. 300 IN CNAME a.ipaddr.skydns.test."
),
coretest
.
CNAME
(
"mx.skydns.test. 300 IN CNAME a.ipaddr.skydns.test."
),
},
},
},
},
{
{
Qname
:
"mx2.skydns.test."
,
Qtype
:
dns
.
TypeMX
,
Qname
:
"mx2.skydns.test."
,
Qtype
:
dns
.
TypeMX
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
MX
(
"mx2.skydns.test. 300 IN MX 10 a.ipaddr.skydns.test."
),
coretest
.
MX
(
"mx2.skydns.test. 300 IN MX 10 a.ipaddr.skydns.test."
),
new
MX
(
"mx2.skydns.test. 300 IN MX 10 b.ipaddr.skydns.test."
),
coretest
.
MX
(
"mx2.skydns.test. 300 IN MX 10 b.ipaddr.skydns.test."
),
},
},
Extra
:
[]
dns
.
RR
{
Extra
:
[]
dns
.
RR
{
new
A
(
"a.ipaddr.skydns.test. 300 A 172.16.1.1"
),
coretest
.
A
(
"a.ipaddr.skydns.test. 300 A 172.16.1.1"
),
new
A
(
"b.ipaddr.skydns.test. 300 A 172.16.1.2"
),
coretest
.
A
(
"b.ipaddr.skydns.test. 300 A 172.16.1.2"
),
},
},
},
},
// Txt
// Txt
{
{
Qname
:
"a1.txt.skydns.test."
,
Qtype
:
dns
.
TypeTXT
,
Qname
:
"a1.txt.skydns.test."
,
Qtype
:
dns
.
TypeTXT
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
TXT
(
"a1.txt.skydns.test. 300 IN TXT
\"
abc
\"
"
),
coretest
.
TXT
(
"a1.txt.skydns.test. 300 IN TXT
\"
abc
\"
"
),
},
},
},
},
{
{
Qname
:
"a2.txt.skydns.test."
,
Qtype
:
dns
.
TypeTXT
,
Qname
:
"a2.txt.skydns.test."
,
Qtype
:
dns
.
TypeTXT
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
TXT
(
"a2.txt.skydns.test. 300 IN TXT
\"
abc abc
\"
"
),
coretest
.
TXT
(
"a2.txt.skydns.test. 300 IN TXT
\"
abc abc
\"
"
),
},
},
},
},
{
{
Qname
:
"txt.skydns.test."
,
Qtype
:
dns
.
TypeTXT
,
Qname
:
"txt.skydns.test."
,
Qtype
:
dns
.
TypeTXT
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
TXT
(
"txt.skydns.test. 300 IN TXT
\"
abc abc
\"
"
),
coretest
.
TXT
(
"txt.skydns.test. 300 IN TXT
\"
abc abc
\"
"
),
new
TXT
(
"txt.skydns.test. 300 IN TXT
\"
abc
\"
"
),
coretest
.
TXT
(
"txt.skydns.test. 300 IN TXT
\"
abc
\"
"
),
},
},
},
},
// Duplicate IP address test
// Duplicate IP address test
{
{
Qname
:
"multiport.http.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"multiport.http.skydns.test."
,
Qtype
:
dns
.
TypeA
,
Answer
:
[]
dns
.
RR
{
new
A
(
"multiport.http.skydns.test. 300 IN A 10.11.11.10"
)},
Answer
:
[]
dns
.
RR
{
coretest
.
A
(
"multiport.http.skydns.test. 300 IN A 10.11.11.10"
)},
},
},
}
}
middleware/etcd/setup_test.go
View file @
23ed465b
...
@@ -3,8 +3,7 @@
...
@@ -3,8 +3,7 @@
package
etcd
package
etcd
// etcd needs to be running on http://127.0.0.1:2379
// etcd needs to be running on http://127.0.0.1:2379
// *and* needs connectivity to the internet for remotely resolving
// *and* needs connectivity to the internet for remotely resolving names.
// names.
import
(
import
(
"encoding/json"
"encoding/json"
...
@@ -16,6 +15,7 @@ import (
...
@@ -16,6 +15,7 @@ import (
"github.com/miekg/coredns/middleware/etcd/msg"
"github.com/miekg/coredns/middleware/etcd/msg"
"github.com/miekg/coredns/middleware/etcd/singleflight"
"github.com/miekg/coredns/middleware/etcd/singleflight"
"github.com/miekg/coredns/middleware/proxy"
"github.com/miekg/coredns/middleware/proxy"
coretest
"github.com/miekg/coredns/middleware/testing"
"github.com/miekg/dns"
"github.com/miekg/dns"
etcdc
"github.com/coreos/etcd/client"
etcdc
"github.com/coreos/etcd/client"
...
@@ -28,14 +28,6 @@ var (
...
@@ -28,14 +28,6 @@ var (
ctx
context
.
Context
ctx
context
.
Context
)
)
type
Section
int
const
(
Answer
Section
=
iota
Ns
Extra
)
func
init
()
{
func
init
()
{
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
etcdTimeout
)
ctx
,
_
=
context
.
WithTimeout
(
context
.
Background
(),
etcdTimeout
)
...
@@ -67,12 +59,6 @@ func delete(t *testing.T, e Etcd, k string) {
...
@@ -67,12 +59,6 @@ func delete(t *testing.T, e Etcd, k string) {
e
.
Client
.
Delete
(
ctx
,
path
,
&
etcdc
.
DeleteOptions
{
Recursive
:
false
})
e
.
Client
.
Delete
(
ctx
,
path
,
&
etcdc
.
DeleteOptions
{
Recursive
:
false
})
}
}
type
rrSet
[]
dns
.
RR
func
(
p
rrSet
)
Len
()
int
{
return
len
(
p
)
}
func
(
p
rrSet
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
]
}
func
(
p
rrSet
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
.
String
()
<
p
[
j
]
.
String
()
}
func
TestLookup
(
t
*
testing
.
T
)
{
func
TestLookup
(
t
*
testing
.
T
)
{
for
_
,
serv
:=
range
services
{
for
_
,
serv
:=
range
services
{
set
(
t
,
etc
,
serv
.
Key
,
0
,
serv
)
set
(
t
,
etc
,
serv
.
Key
,
0
,
serv
)
...
@@ -90,9 +76,9 @@ func TestLookup(t *testing.T) {
...
@@ -90,9 +76,9 @@ func TestLookup(t *testing.T) {
}
}
resp
:=
rec
.
Msg
()
resp
:=
rec
.
Msg
()
sort
.
Sort
(
rr
Set
(
resp
.
Answer
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Answer
))
sort
.
Sort
(
rr
Set
(
resp
.
Ns
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Ns
))
sort
.
Sort
(
rr
Set
(
resp
.
Extra
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Extra
))
if
resp
.
Rcode
!=
tc
.
Rcode
{
if
resp
.
Rcode
!=
tc
.
Rcode
{
t
.
Errorf
(
"rcode is %q, expected %q"
,
dns
.
RcodeToString
[
resp
.
Rcode
],
dns
.
RcodeToString
[
tc
.
Rcode
])
t
.
Errorf
(
"rcode is %q, expected %q"
,
dns
.
RcodeToString
[
resp
.
Rcode
],
dns
.
RcodeToString
[
tc
.
Rcode
])
...
@@ -116,134 +102,15 @@ func TestLookup(t *testing.T) {
...
@@ -116,134 +102,15 @@ func TestLookup(t *testing.T) {
continue
continue
}
}
if
!
c
heckSection
(
t
,
tc
,
Answer
,
resp
.
Answer
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Answer
,
resp
.
Answer
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
if
!
c
heckSection
(
t
,
tc
,
Ns
,
resp
.
Ns
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Ns
,
resp
.
Ns
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
if
!
c
heckSection
(
t
,
tc
,
Extra
,
resp
.
Extra
)
{
if
!
c
oretest
.
CheckSection
(
t
,
tc
,
coretest
.
Extra
,
resp
.
Extra
)
{
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
}
}
}
}
}
}
type
dnsTestCase
struct
{
Qname
string
Qtype
uint16
Rcode
int
Answer
[]
dns
.
RR
Ns
[]
dns
.
RR
Extra
[]
dns
.
RR
}
func
newA
(
rr
string
)
*
dns
.
A
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
A
)
}
func
newAAAA
(
rr
string
)
*
dns
.
AAAA
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
AAAA
)
}
func
newCNAME
(
rr
string
)
*
dns
.
CNAME
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
CNAME
)
}
func
newSRV
(
rr
string
)
*
dns
.
SRV
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
SRV
)
}
func
newSOA
(
rr
string
)
*
dns
.
SOA
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
SOA
)
}
func
newNS
(
rr
string
)
*
dns
.
NS
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
NS
)
}
func
newPTR
(
rr
string
)
*
dns
.
PTR
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
PTR
)
}
func
newTXT
(
rr
string
)
*
dns
.
TXT
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
TXT
)
}
func
newMX
(
rr
string
)
*
dns
.
MX
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
MX
)
}
func
checkSection
(
t
*
testing
.
T
,
tc
dnsTestCase
,
sect
Section
,
rr
[]
dns
.
RR
)
bool
{
section
:=
[]
dns
.
RR
{}
switch
sect
{
case
0
:
section
=
tc
.
Answer
case
1
:
section
=
tc
.
Ns
case
2
:
section
=
tc
.
Extra
}
for
i
,
a
:=
range
rr
{
if
a
.
Header
()
.
Name
!=
section
[
i
]
.
Header
()
.
Name
{
t
.
Errorf
(
"rr %d should have a Header Name of %q, but has %q"
,
i
,
section
[
i
]
.
Header
()
.
Name
,
a
.
Header
()
.
Name
)
return
false
}
// 303 signals: don't care what the ttl is.
if
section
[
i
]
.
Header
()
.
Ttl
!=
303
&&
a
.
Header
()
.
Ttl
!=
section
[
i
]
.
Header
()
.
Ttl
{
t
.
Errorf
(
"rr %d should have a Header TTL of %d, but has %d"
,
i
,
section
[
i
]
.
Header
()
.
Ttl
,
a
.
Header
()
.
Ttl
)
return
false
}
if
a
.
Header
()
.
Rrtype
!=
section
[
i
]
.
Header
()
.
Rrtype
{
t
.
Errorf
(
"rr %d should have a header rr type of %d, but has %d"
,
i
,
section
[
i
]
.
Header
()
.
Rrtype
,
a
.
Header
()
.
Rrtype
)
return
false
}
switch
x
:=
a
.
(
type
)
{
case
*
dns
.
SRV
:
if
x
.
Priority
!=
section
[
i
]
.
(
*
dns
.
SRV
)
.
Priority
{
t
.
Errorf
(
"rr %d should have a Priority of %d, but has %d"
,
i
,
section
[
i
]
.
(
*
dns
.
SRV
)
.
Priority
,
x
.
Priority
)
return
false
}
if
x
.
Weight
!=
section
[
i
]
.
(
*
dns
.
SRV
)
.
Weight
{
t
.
Errorf
(
"rr %d should have a Weight of %d, but has %d"
,
i
,
section
[
i
]
.
(
*
dns
.
SRV
)
.
Weight
,
x
.
Weight
)
return
false
}
if
x
.
Port
!=
section
[
i
]
.
(
*
dns
.
SRV
)
.
Port
{
t
.
Errorf
(
"rr %d should have a Port of %d, but has %d"
,
i
,
section
[
i
]
.
(
*
dns
.
SRV
)
.
Port
,
x
.
Port
)
return
false
}
if
x
.
Target
!=
section
[
i
]
.
(
*
dns
.
SRV
)
.
Target
{
t
.
Errorf
(
"rr %d should have a Target of %q, but has %q"
,
i
,
section
[
i
]
.
(
*
dns
.
SRV
)
.
Target
,
x
.
Target
)
return
false
}
case
*
dns
.
A
:
if
x
.
A
.
String
()
!=
section
[
i
]
.
(
*
dns
.
A
)
.
A
.
String
()
{
t
.
Errorf
(
"rr %d should have a Address of %q, but has %q"
,
i
,
section
[
i
]
.
(
*
dns
.
A
)
.
A
.
String
(),
x
.
A
.
String
())
return
false
}
case
*
dns
.
AAAA
:
if
x
.
AAAA
.
String
()
!=
section
[
i
]
.
(
*
dns
.
AAAA
)
.
AAAA
.
String
()
{
t
.
Errorf
(
"rr %d should have a Address of %q, but has %q"
,
i
,
section
[
i
]
.
(
*
dns
.
AAAA
)
.
AAAA
.
String
(),
x
.
AAAA
.
String
())
return
false
}
case
*
dns
.
TXT
:
for
j
,
txt
:=
range
x
.
Txt
{
if
txt
!=
section
[
i
]
.
(
*
dns
.
TXT
)
.
Txt
[
j
]
{
t
.
Errorf
(
"rr %d should have a Txt of %q, but has %q"
,
i
,
section
[
i
]
.
(
*
dns
.
TXT
)
.
Txt
[
j
],
txt
)
return
false
}
}
case
*
dns
.
SOA
:
tt
:=
section
[
i
]
.
(
*
dns
.
SOA
)
if
x
.
Ns
!=
tt
.
Ns
{
t
.
Errorf
(
"SOA nameserver should be %q, but is %q"
,
x
.
Ns
,
tt
.
Ns
)
return
false
}
case
*
dns
.
PTR
:
tt
:=
section
[
i
]
.
(
*
dns
.
PTR
)
if
x
.
Ptr
!=
tt
.
Ptr
{
t
.
Errorf
(
"PTR ptr should be %q, but is %q"
,
x
.
Ptr
,
tt
.
Ptr
)
return
false
}
case
*
dns
.
CNAME
:
tt
:=
section
[
i
]
.
(
*
dns
.
CNAME
)
if
x
.
Target
!=
tt
.
Target
{
t
.
Errorf
(
"CNAME target should be %q, but is %q"
,
x
.
Target
,
tt
.
Target
)
return
false
}
case
*
dns
.
MX
:
tt
:=
section
[
i
]
.
(
*
dns
.
MX
)
if
x
.
Mx
!=
tt
.
Mx
{
t
.
Errorf
(
"MX Mx should be %q, but is %q"
,
x
.
Mx
,
tt
.
Mx
)
return
false
}
if
x
.
Preference
!=
tt
.
Preference
{
t
.
Errorf
(
"MX Preference should be %q, but is %q"
,
x
.
Preference
,
tt
.
Preference
)
return
false
}
case
*
dns
.
NS
:
tt
:=
section
[
i
]
.
(
*
dns
.
NS
)
if
x
.
Ns
!=
tt
.
Ns
{
t
.
Errorf
(
"NS nameserver should be %q, but is %q"
,
x
.
Ns
,
tt
.
Ns
)
return
false
}
}
}
return
true
}
middleware/file/lookup_test.go
View file @
23ed465b
...
@@ -6,66 +6,61 @@ import (
...
@@ -6,66 +6,61 @@ import (
"testing"
"testing"
"github.com/miekg/coredns/middleware"
"github.com/miekg/coredns/middleware"
coretest
"github.com/miekg/coredns/middleware/testing"
"github.com/miekg/dns"
"github.com/miekg/dns"
"golang.org/x/net/context"
"golang.org/x/net/context"
)
)
var
dnsTestCases
=
[]
dnsTest
Case
{
var
dnsTestCases
=
[]
coretest
.
Case
{
{
{
Qname
:
"miek.nl."
,
Qtype
:
dns
.
TypeSOA
,
Qname
:
"miek.nl."
,
Qtype
:
dns
.
TypeSOA
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
SOA
(
"miek.nl. 1800 IN SOA linode.atoom.net. miek.miek.nl. 1282630057 14400 3600 604800 14400"
),
coretest
.
SOA
(
"miek.nl. 1800 IN SOA linode.atoom.net. miek.miek.nl. 1282630057 14400 3600 604800 14400"
),
},
},
},
},
{
{
Qname
:
"miek.nl."
,
Qtype
:
dns
.
TypeAAAA
,
Qname
:
"miek.nl."
,
Qtype
:
dns
.
TypeAAAA
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
AAAA
(
"miek.nl. 1800 IN AAAA 2a01:7e00::f03c:91ff:fef1:6735"
),
coretest
.
AAAA
(
"miek.nl. 1800 IN AAAA 2a01:7e00::f03c:91ff:fef1:6735"
),
},
},
},
},
{
{
Qname
:
"miek.nl."
,
Qtype
:
dns
.
TypeMX
,
Qname
:
"miek.nl."
,
Qtype
:
dns
.
TypeMX
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
MX
(
"miek.nl. 1800 IN MX 1 aspmx.l.google.com."
),
coretest
.
MX
(
"miek.nl. 1800 IN MX 1 aspmx.l.google.com."
),
new
MX
(
"miek.nl. 1800 IN MX 10 aspmx2.googlemail.com."
),
coretest
.
MX
(
"miek.nl. 1800 IN MX 10 aspmx2.googlemail.com."
),
new
MX
(
"miek.nl. 1800 IN MX 10 aspmx3.googlemail.com."
),
coretest
.
MX
(
"miek.nl. 1800 IN MX 10 aspmx3.googlemail.com."
),
new
MX
(
"miek.nl. 1800 IN MX 5 alt1.aspmx.l.google.com."
),
coretest
.
MX
(
"miek.nl. 1800 IN MX 5 alt1.aspmx.l.google.com."
),
new
MX
(
"miek.nl. 1800 IN MX 5 alt2.aspmx.l.google.com."
),
coretest
.
MX
(
"miek.nl. 1800 IN MX 5 alt2.aspmx.l.google.com."
),
},
},
},
},
{
{
Qname
:
"www.miek.nl."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"www.miek.nl."
,
Qtype
:
dns
.
TypeA
,
Answer
:
[]
dns
.
RR
{
Answer
:
[]
dns
.
RR
{
new
CNAME
(
"www.miek.nl. 1800 IN CNAME a.miek.nl."
),
coretest
.
CNAME
(
"www.miek.nl. 1800 IN CNAME a.miek.nl."
),
},
},
Extra
:
[]
dns
.
RR
{
Extra
:
[]
dns
.
RR
{
new
A
(
"a.miek.nl. 1800 IN A 139.162.196.78"
),
coretest
.
A
(
"a.miek.nl. 1800 IN A 139.162.196.78"
),
new
AAAA
(
"a.miek.nl. 1800 IN AAAA 2a01:7e00::f03c:91ff:fef1:6735"
),
coretest
.
AAAA
(
"a.miek.nl. 1800 IN AAAA 2a01:7e00::f03c:91ff:fef1:6735"
),
},
},
},
},
{
{
Qname
:
"a.miek.nl."
,
Qtype
:
dns
.
TypeSRV
,
Qname
:
"a.miek.nl."
,
Qtype
:
dns
.
TypeSRV
,
Ns
:
[]
dns
.
RR
{
Ns
:
[]
dns
.
RR
{
new
SOA
(
"miek.nl. 1800 IN SOA linode.atoom.net. miek.miek.nl. 1282630057 14400 3600 604800 14400"
),
coretest
.
SOA
(
"miek.nl. 1800 IN SOA linode.atoom.net. miek.miek.nl. 1282630057 14400 3600 604800 14400"
),
},
},
},
},
{
{
Qname
:
"b.miek.nl."
,
Qtype
:
dns
.
TypeA
,
Qname
:
"b.miek.nl."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeNameError
,
Rcode
:
dns
.
RcodeNameError
,
Ns
:
[]
dns
.
RR
{
Ns
:
[]
dns
.
RR
{
new
SOA
(
"miek.nl. 1800 IN SOA linode.atoom.net. miek.miek.nl. 1282630057 14400 3600 604800 14400"
),
coretest
.
SOA
(
"miek.nl. 1800 IN SOA linode.atoom.net. miek.miek.nl. 1282630057 14400 3600 604800 14400"
),
},
},
},
},
}
}
type
rrSet
[]
dns
.
RR
func
(
p
rrSet
)
Len
()
int
{
return
len
(
p
)
}
func
(
p
rrSet
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
]
}
func
(
p
rrSet
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
.
String
()
<
p
[
j
]
.
String
()
}
const
testzone
=
"miek.nl."
const
testzone
=
"miek.nl."
func
TestLookup
(
t
*
testing
.
T
)
{
func
TestLookup
(
t
*
testing
.
T
)
{
...
@@ -74,7 +69,7 @@ func TestLookup(t *testing.T) {
...
@@ -74,7 +69,7 @@ func TestLookup(t *testing.T) {
t
.
Fatalf
(
"expect no error when reading zone, got %q"
,
err
)
t
.
Fatalf
(
"expect no error when reading zone, got %q"
,
err
)
}
}
fm
:=
File
{
Next
:
h
andler
(),
Zones
:
Zones
{
Z
:
map
[
string
]
*
Zone
{
testzone
:
zone
},
Names
:
[]
string
{
testzone
}}}
fm
:=
File
{
Next
:
coretest
.
ErrorH
andler
(),
Zones
:
Zones
{
Z
:
map
[
string
]
*
Zone
{
testzone
:
zone
},
Names
:
[]
string
{
testzone
}}}
ctx
:=
context
.
TODO
()
ctx
:=
context
.
TODO
()
for
_
,
tc
:=
range
dnsTestCases
{
for
_
,
tc
:=
range
dnsTestCases
{
...
@@ -89,9 +84,9 @@ func TestLookup(t *testing.T) {
...
@@ -89,9 +84,9 @@ func TestLookup(t *testing.T) {
}
}
resp
:=
rec
.
Msg
()
resp
:=
rec
.
Msg
()
sort
.
Sort
(
rr
Set
(
resp
.
Answer
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Answer
))
sort
.
Sort
(
rr
Set
(
resp
.
Ns
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Ns
))
sort
.
Sort
(
rr
Set
(
resp
.
Extra
))
sort
.
Sort
(
coretest
.
RR
Set
(
resp
.
Extra
))
if
resp
.
Rcode
!=
tc
.
Rcode
{
if
resp
.
Rcode
!=
tc
.
Rcode
{
t
.
Errorf
(
"rcode is %q, expected %q"
,
dns
.
RcodeToString
[
resp
.
Rcode
],
dns
.
RcodeToString
[
tc
.
Rcode
])
t
.
Errorf
(
"rcode is %q, expected %q"
,
dns
.
RcodeToString
[
resp
.
Rcode
],
dns
.
RcodeToString
[
tc
.
Rcode
])
...
@@ -114,27 +109,19 @@ func TestLookup(t *testing.T) {
...
@@ -114,27 +109,19 @@ func TestLookup(t *testing.T) {
t
.
Logf
(
"%v
\n
"
,
resp
)
t
.
Logf
(
"%v
\n
"
,
resp
)
continue
continue
}
}
}
}
type
dnsTestCase
struct
{
if
!
coretest
.
CheckSection
(
t
,
tc
,
coretest
.
Answer
,
resp
.
Answer
)
{
Qname
string
t
.
Logf
(
"%v
\n
"
,
resp
)
Qtype
uint16
}
Rcode
int
if
!
coretest
.
CheckSection
(
t
,
tc
,
coretest
.
Ns
,
resp
.
Ns
)
{
Answer
[]
dns
.
RR
t
.
Logf
(
"%v
\n
"
,
resp
)
Ns
[]
dns
.
RR
Extra
[]
dns
.
RR
}
func
newA
(
rr
string
)
*
dns
.
A
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
A
)
}
}
func
newAAAA
(
rr
string
)
*
dns
.
AAAA
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
AAAA
)
}
if
!
coretest
.
CheckSection
(
t
,
tc
,
coretest
.
Extra
,
resp
.
Extra
)
{
func
newCNAME
(
rr
string
)
*
dns
.
CNAME
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
CNAME
)
}
t
.
Logf
(
"%v
\n
"
,
resp
)
func
newSRV
(
rr
string
)
*
dns
.
SRV
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
SRV
)
}
}
func
newSOA
(
rr
string
)
*
dns
.
SOA
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
SOA
)
}
}
func
newNS
(
rr
string
)
*
dns
.
NS
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
NS
)
}
}
func
newPTR
(
rr
string
)
*
dns
.
PTR
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
PTR
)
}
func
newTXT
(
rr
string
)
*
dns
.
TXT
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
TXT
)
}
func
newMX
(
rr
string
)
*
dns
.
MX
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
MX
)
}
const
dbMiekNL
=
`
const
dbMiekNL
=
`
$TTL 30M
$TTL 30M
...
@@ -163,12 +150,3 @@ a IN A 139.162.196.78
...
@@ -163,12 +150,3 @@ a IN A 139.162.196.78
IN AAAA 2a01:7e00::f03c:91ff:fef1:6735
IN AAAA 2a01:7e00::f03c:91ff:fef1:6735
www IN CNAME a
www IN CNAME a
archive IN CNAME a`
archive IN CNAME a`
func
handler
()
middleware
.
Handler
{
return
middleware
.
HandlerFunc
(
func
(
ctx
context
.
Context
,
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
(
int
,
error
)
{
m
:=
new
(
dns
.
Msg
)
m
.
SetRcode
(
r
,
dns
.
RcodeServerFailure
)
w
.
WriteMsg
(
m
)
return
dns
.
RcodeServerFailure
,
nil
})
}
middleware/testing/helpers.go
0 → 100644
View file @
23ed465b
package
testing
import
(
"testing"
"github.com/miekg/coredns/middleware"
"github.com/miekg/dns"
"golang.org/x/net/context"
)
type
Section
int
const
(
Answer
Section
=
iota
Ns
Extra
)
type
RRSet
[]
dns
.
RR
func
(
p
RRSet
)
Len
()
int
{
return
len
(
p
)
}
func
(
p
RRSet
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
]
}
func
(
p
RRSet
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
.
String
()
<
p
[
j
]
.
String
()
}
type
Case
struct
{
Qname
string
Qtype
uint16
Rcode
int
Answer
[]
dns
.
RR
Ns
[]
dns
.
RR
Extra
[]
dns
.
RR
}
func
A
(
rr
string
)
*
dns
.
A
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
A
)
}
func
AAAA
(
rr
string
)
*
dns
.
AAAA
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
AAAA
)
}
func
CNAME
(
rr
string
)
*
dns
.
CNAME
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
CNAME
)
}
func
SRV
(
rr
string
)
*
dns
.
SRV
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
SRV
)
}
func
SOA
(
rr
string
)
*
dns
.
SOA
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
SOA
)
}
func
NS
(
rr
string
)
*
dns
.
NS
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
NS
)
}
func
PTR
(
rr
string
)
*
dns
.
PTR
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
PTR
)
}
func
TXT
(
rr
string
)
*
dns
.
TXT
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
TXT
)
}
func
MX
(
rr
string
)
*
dns
.
MX
{
r
,
_
:=
dns
.
NewRR
(
rr
);
return
r
.
(
*
dns
.
MX
)
}
func
CheckSection
(
t
*
testing
.
T
,
tc
Case
,
sect
Section
,
rr
[]
dns
.
RR
)
bool
{
section
:=
[]
dns
.
RR
{}
switch
sect
{
case
0
:
section
=
tc
.
Answer
case
1
:
section
=
tc
.
Ns
case
2
:
section
=
tc
.
Extra
}
for
i
,
a
:=
range
rr
{
if
a
.
Header
()
.
Name
!=
section
[
i
]
.
Header
()
.
Name
{
t
.
Errorf
(
"rr %d should have a Header Name of %q, but has %q"
,
i
,
section
[
i
]
.
Header
()
.
Name
,
a
.
Header
()
.
Name
)
return
false
}
// 303 signals: don't care what the ttl is.
if
section
[
i
]
.
Header
()
.
Ttl
!=
303
&&
a
.
Header
()
.
Ttl
!=
section
[
i
]
.
Header
()
.
Ttl
{
t
.
Errorf
(
"rr %d should have a Header TTL of %d, but has %d"
,
i
,
section
[
i
]
.
Header
()
.
Ttl
,
a
.
Header
()
.
Ttl
)
return
false
}
if
a
.
Header
()
.
Rrtype
!=
section
[
i
]
.
Header
()
.
Rrtype
{
t
.
Errorf
(
"rr %d should have a header rr type of %d, but has %d"
,
i
,
section
[
i
]
.
Header
()
.
Rrtype
,
a
.
Header
()
.
Rrtype
)
return
false
}
switch
x
:=
a
.
(
type
)
{
case
*
dns
.
SRV
:
if
x
.
Priority
!=
section
[
i
]
.
(
*
dns
.
SRV
)
.
Priority
{
t
.
Errorf
(
"rr %d should have a Priority of %d, but has %d"
,
i
,
section
[
i
]
.
(
*
dns
.
SRV
)
.
Priority
,
x
.
Priority
)
return
false
}
if
x
.
Weight
!=
section
[
i
]
.
(
*
dns
.
SRV
)
.
Weight
{
t
.
Errorf
(
"rr %d should have a Weight of %d, but has %d"
,
i
,
section
[
i
]
.
(
*
dns
.
SRV
)
.
Weight
,
x
.
Weight
)
return
false
}
if
x
.
Port
!=
section
[
i
]
.
(
*
dns
.
SRV
)
.
Port
{
t
.
Errorf
(
"rr %d should have a Port of %d, but has %d"
,
i
,
section
[
i
]
.
(
*
dns
.
SRV
)
.
Port
,
x
.
Port
)
return
false
}
if
x
.
Target
!=
section
[
i
]
.
(
*
dns
.
SRV
)
.
Target
{
t
.
Errorf
(
"rr %d should have a Target of %q, but has %q"
,
i
,
section
[
i
]
.
(
*
dns
.
SRV
)
.
Target
,
x
.
Target
)
return
false
}
case
*
dns
.
A
:
if
x
.
A
.
String
()
!=
section
[
i
]
.
(
*
dns
.
A
)
.
A
.
String
()
{
t
.
Errorf
(
"rr %d should have a Address of %q, but has %q"
,
i
,
section
[
i
]
.
(
*
dns
.
A
)
.
A
.
String
(),
x
.
A
.
String
())
return
false
}
case
*
dns
.
AAAA
:
if
x
.
AAAA
.
String
()
!=
section
[
i
]
.
(
*
dns
.
AAAA
)
.
AAAA
.
String
()
{
t
.
Errorf
(
"rr %d should have a Address of %q, but has %q"
,
i
,
section
[
i
]
.
(
*
dns
.
AAAA
)
.
AAAA
.
String
(),
x
.
AAAA
.
String
())
return
false
}
case
*
dns
.
TXT
:
for
j
,
txt
:=
range
x
.
Txt
{
if
txt
!=
section
[
i
]
.
(
*
dns
.
TXT
)
.
Txt
[
j
]
{
t
.
Errorf
(
"rr %d should have a Txt of %q, but has %q"
,
i
,
section
[
i
]
.
(
*
dns
.
TXT
)
.
Txt
[
j
],
txt
)
return
false
}
}
case
*
dns
.
SOA
:
tt
:=
section
[
i
]
.
(
*
dns
.
SOA
)
if
x
.
Ns
!=
tt
.
Ns
{
t
.
Errorf
(
"SOA nameserver should be %q, but is %q"
,
x
.
Ns
,
tt
.
Ns
)
return
false
}
case
*
dns
.
PTR
:
tt
:=
section
[
i
]
.
(
*
dns
.
PTR
)
if
x
.
Ptr
!=
tt
.
Ptr
{
t
.
Errorf
(
"PTR ptr should be %q, but is %q"
,
x
.
Ptr
,
tt
.
Ptr
)
return
false
}
case
*
dns
.
CNAME
:
tt
:=
section
[
i
]
.
(
*
dns
.
CNAME
)
if
x
.
Target
!=
tt
.
Target
{
t
.
Errorf
(
"CNAME target should be %q, but is %q"
,
x
.
Target
,
tt
.
Target
)
return
false
}
case
*
dns
.
MX
:
tt
:=
section
[
i
]
.
(
*
dns
.
MX
)
if
x
.
Mx
!=
tt
.
Mx
{
t
.
Errorf
(
"MX Mx should be %q, but is %q"
,
x
.
Mx
,
tt
.
Mx
)
return
false
}
if
x
.
Preference
!=
tt
.
Preference
{
t
.
Errorf
(
"MX Preference should be %q, but is %q"
,
x
.
Preference
,
tt
.
Preference
)
return
false
}
case
*
dns
.
NS
:
tt
:=
section
[
i
]
.
(
*
dns
.
NS
)
if
x
.
Ns
!=
tt
.
Ns
{
t
.
Errorf
(
"NS nameserver should be %q, but is %q"
,
x
.
Ns
,
tt
.
Ns
)
return
false
}
}
}
return
true
}
func
ErrorHandler
()
middleware
.
Handler
{
return
middleware
.
HandlerFunc
(
func
(
ctx
context
.
Context
,
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
(
int
,
error
)
{
m
:=
new
(
dns
.
Msg
)
m
.
SetRcode
(
r
,
dns
.
RcodeServerFailure
)
w
.
WriteMsg
(
m
)
return
dns
.
RcodeServerFailure
,
nil
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment