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
8ad8c75a
Commit
8ad8c75a
authored
Aug 03, 2017
by
Sandeep Rajan
Committed by
Yong Tang
Aug 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Middleware/k8s: Add unit tests for Pods (#815)
* Added Pod testing * Cleanup * fixed formatting
parent
cd1f2f1b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
2 deletions
+77
-2
middleware/kubernetes/handler_test.go
middleware/kubernetes/handler_test.go
+76
-2
middleware/test/helpers.go
middleware/test/helpers.go
+1
-0
No files found.
middleware/kubernetes/handler_test.go
View file @
8ad8c75a
...
...
@@ -106,6 +106,68 @@ var dnsTestCases = map[string](*test.Case){
},
}
var
podModeDisabledCases
=
map
[
string
](
*
test
.
Case
){
"A Record Pod mode = Case 1"
:
{
Qname
:
"10-240-0-1.podns.pod.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeNameError
,
Error
:
errPodsDisabled
,
Answer
:
[]
dns
.
RR
{},
Ns
:
[]
dns
.
RR
{
test
.
SOA
(
"cluster.local. 300 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"
),
},
},
"A Record Pod mode = Case 2"
:
{
Qname
:
"172-0-0-2.podns.pod.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeNameError
,
Error
:
errPodsDisabled
,
Answer
:
[]
dns
.
RR
{},
Ns
:
[]
dns
.
RR
{
test
.
SOA
(
"cluster.local. 300 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"
),
},
},
}
var
podModeInsecureCases
=
map
[
string
](
*
test
.
Case
){
"A Record Pod mode = Case 1"
:
{
Qname
:
"10-240-0-1.podns.pod.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeSuccess
,
Answer
:
[]
dns
.
RR
{
test
.
A
(
"10-240-0-1.podns.pod.cluster.local. 0 IN A 10.240.0.1"
),
},
},
"A Record Pod mode = Case 2"
:
{
Qname
:
"172-0-0-2.podns.pod.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeSuccess
,
Answer
:
[]
dns
.
RR
{
test
.
A
(
"172-0-0-2.podns.pod.cluster.local. 0 IN A 172.0.0.2"
),
},
},
}
var
podModeVerifiedCases
=
map
[
string
](
*
test
.
Case
){
"A Record Pod mode = Case 1"
:
{
Qname
:
"10-240-0-1.podns.pod.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeSuccess
,
Answer
:
[]
dns
.
RR
{
test
.
A
(
"10-240-0-1.podns.pod.cluster.local. 0 IN A 10.240.0.1"
),
},
},
"A Record Pod mode = Case 2"
:
{
Qname
:
"172-0-0-2.podns.pod.cluster.local."
,
Qtype
:
dns
.
TypeA
,
Rcode
:
dns
.
RcodeNameError
,
Answer
:
[]
dns
.
RR
{},
Ns
:
[]
dns
.
RR
{
test
.
SOA
(
"cluster.local. 300 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"
),
},
},
}
var
autopathCases
=
map
[
string
](
*
test
.
Case
){
"A Autopath Service (Second Search)"
:
{
Qname
:
"svc1.testns.podns.svc.cluster.local."
,
Qtype
:
dns
.
TypeA
,
...
...
@@ -215,11 +277,20 @@ func TestServeDNS(t *testing.T) {
runServeDNSTests
(
t
,
autopathCases
,
k
,
ctx
)
runServeDNSTests
(
t
,
autopathBareSearch
,
k
,
ctx
)
//Set PodMode to Disabled
k
.
PodMode
=
PodModeDisabled
runServeDNSTests
(
t
,
podModeDisabledCases
,
k
,
ctx
)
//Set PodMode to Insecure
k
.
PodMode
=
PodModeInsecure
runServeDNSTests
(
t
,
podModeInsecureCases
,
k
,
ctx
)
//Set PodMode to Verified
k
.
PodMode
=
PodModeVerified
runServeDNSTests
(
t
,
podModeVerifiedCases
,
k
,
ctx
)
// Set ndots to 2 for the ndots test cases
k
.
AutoPath
.
NDots
=
2
runServeDNSTests
(
t
,
autopath2NDotsCases
,
k
,
ctx
)
k
.
AutoPath
.
NDots
=
defautNdots
// Disable the NXDOMAIN override (enabled by default)
k
.
OnNXDOMAIN
=
dns
.
RcodeNameError
runServeDNSTests
(
t
,
autopathCases
,
k
,
ctx
)
...
...
@@ -235,10 +306,13 @@ func runServeDNSTests(t *testing.T, dnsTestCases map[string](*test.Case), k Kube
w
:=
dnsrecorder
.
New
(
&
test
.
ResponseWriter
{})
_
,
err
:=
k
.
ServeDNS
(
ctx
,
w
,
r
)
if
err
!=
nil
{
if
err
!=
tc
.
Error
{
t
.
Errorf
(
"%v expected no error, got %v
\n
"
,
testname
,
err
)
return
}
if
tc
.
Error
!=
nil
{
continue
}
resp
:=
w
.
Msg
...
...
middleware/test/helpers.go
View file @
8ad8c75a
...
...
@@ -35,6 +35,7 @@ type Case struct {
Answer
[]
dns
.
RR
Ns
[]
dns
.
RR
Extra
[]
dns
.
RR
Error
error
}
// Msg returns a *dns.Msg embedded in c.
...
...
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