Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
006580ab
Commit
006580ab
authored
May 18, 2016
by
Madhusudan.C.S
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement tests for federation queries.
parent
13fef231
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
0 deletions
+100
-0
dns_test.go
pkg/dns/dns_test.go
+100
-0
No files found.
pkg/dns/dns_test.go
View file @
006580ab
...
...
@@ -23,11 +23,15 @@ import (
"sync"
"testing"
etcd
"github.com/coreos/etcd/client"
skymsg
"github.com/skynetservices/skydns/msg"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
kapi
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
v1
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/client/cache"
fake
"k8s.io/kubernetes/pkg/client/clientset_generated/release_1_3/fake"
)
const
(
...
...
@@ -44,6 +48,7 @@ func newKubeDNS() *KubeDNS {
cache
:
NewTreeCache
(),
cacheLock
:
sync
.
RWMutex
{},
domainPath
:
reverseArray
(
strings
.
Split
(
strings
.
TrimRight
(
testDomain
,
"."
),
"."
)),
nodesStore
:
cache
.
NewStore
(
cache
.
MetaNamespaceKeyFunc
),
}
return
kd
}
...
...
@@ -200,6 +205,101 @@ func TestHeadlessServiceWithDelayedEndpointsAddition(t *testing.T) {
assertNoDNSForHeadlessService
(
t
,
kd
,
service
)
}
func
TestFederationQueryWithoutCache
(
t
*
testing
.
T
)
{
kd
:=
newKubeDNS
()
kd
.
federations
=
map
[
string
]
string
{
"myfederation"
:
"example.com"
,
"secondfederation"
:
"second.example.com"
,
}
kd
.
kubeClient
=
fake
.
NewSimpleClientset
(
newNodes
())
testValidFederationQueries
(
t
,
kd
)
testInvalidFederationQueries
(
t
,
kd
)
}
func
TestFederationQueryWithCache
(
t
*
testing
.
T
)
{
kd
:=
newKubeDNS
()
kd
.
federations
=
map
[
string
]
string
{
"myfederation"
:
"example.com"
,
"secondfederation"
:
"second.example.com"
,
}
// Add a node to the cache.
nodeList
:=
newNodes
()
if
err
:=
kd
.
nodesStore
.
Add
(
&
nodeList
.
Items
[
1
]);
err
!=
nil
{
t
.
Errorf
(
"failed to add the node to the cache: %v"
,
err
)
}
testValidFederationQueries
(
t
,
kd
)
testInvalidFederationQueries
(
t
,
kd
)
}
func
testValidFederationQueries
(
t
*
testing
.
T
,
kd
*
KubeDNS
)
{
queries
:=
[]
struct
{
q
string
a
string
}{
// Federation suffix is just a domain.
{
q
:
"mysvc.myns.myfederation.svc.cluster.local."
,
a
:
"mysvc.myns.myfederation.svc.testcontinent-testreg-testzone.example.com."
,
},
// Federation suffix is a subdomain.
{
q
:
"secsvc.default.secondfederation.svc.cluster.local."
,
a
:
"secsvc.default.secondfederation.svc.testcontinent-testreg-testzone.second.example.com."
,
},
}
for
_
,
query
:=
range
queries
{
records
,
err
:=
kd
.
Records
(
query
.
q
,
false
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
1
,
len
(
records
))
assert
.
Equal
(
t
,
query
.
a
,
records
[
0
]
.
Host
)
}
}
func
testInvalidFederationQueries
(
t
*
testing
.
T
,
kd
*
KubeDNS
)
{
noAnswerQueries
:=
[]
string
{
"mysvc.myns.svc.cluster.local."
,
"mysvc.default.nofederation.svc.cluster.local."
,
}
for
_
,
q
:=
range
noAnswerQueries
{
records
,
err
:=
kd
.
Records
(
q
,
false
)
if
err
==
nil
{
t
.
Errorf
(
"expected not found error, got nil"
)
}
if
etcdErr
,
ok
:=
err
.
(
etcd
.
Error
);
!
ok
||
etcdErr
.
Code
!=
etcd
.
ErrorCodeKeyNotFound
{
t
.
Errorf
(
"expected not found error, got %v"
,
etcdErr
)
}
assert
.
Equal
(
t
,
0
,
len
(
records
))
}
}
func
newNodes
()
*
v1
.
NodeList
{
return
&
v1
.
NodeList
{
Items
:
[]
v1
.
Node
{
// Node without annotation.
{
ObjectMeta
:
v1
.
ObjectMeta
{
Name
:
"testnode-0"
,
},
},
{
ObjectMeta
:
v1
.
ObjectMeta
{
Name
:
"testnode-1"
,
Annotations
:
map
[
string
]
string
{
// Note: The zone name here is an arbitrary string and doesn't exactly follow the
// format used by the cloud providers to name their zones. But that shouldn't matter
// for these tests here.
unversioned
.
LabelZoneFailureDomain
:
"testcontinent-testreg-testzone"
,
},
},
},
},
}
}
func
newService
(
namespace
,
serviceName
,
clusterIP
,
portName
string
,
portNumber
int32
)
*
kapi
.
Service
{
service
:=
kapi
.
Service
{
ObjectMeta
:
kapi
.
ObjectMeta
{
...
...
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