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
1fb849ef
Commit
1fb849ef
authored
Aug 28, 2017
by
zhangxiaoyu-zidif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor federation dns test case with sets.String
parent
b65d665b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
49 deletions
+45
-49
BUILD
federation/pkg/federation-controller/service/dns/BUILD
+1
-0
dns_test.go
federation/pkg/federation-controller/service/dns/dns_test.go
+44
-49
No files found.
federation/pkg/federation-controller/service/dns/BUILD
View file @
1fb849ef
...
...
@@ -18,6 +18,7 @@ go_test(
"//federation/pkg/federation-controller/util/test:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
],
)
...
...
federation/pkg/federation-controller/service/dns/dns_test.go
View file @
1fb849ef
...
...
@@ -18,13 +18,13 @@ package dns
import
(
"fmt"
"reflect"
"sort"
"testing"
"time"
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/federation/apis/federation/v1beta1"
fakefedclientset
"k8s.io/kubernetes/federation/client/clientset_generated/federation_clientset/fake"
"k8s.io/kubernetes/federation/pkg/dnsprovider/providers/google/clouddns"
// Only for unit testing purposes.
...
...
@@ -54,7 +54,7 @@ func TestServiceController_ensureDnsRecords(t *testing.T) {
tests
:=
[]
struct
{
name
string
service
v1
.
Service
expected
[]
s
tring
expected
sets
.
S
tring
}{
{
name
:
"ServiceWithSingleLBIngress"
,
...
...
@@ -66,13 +66,13 @@ func TestServiceController_ensureDnsRecords(t *testing.T) {
String
()},
},
},
expected
:
[]
string
{
"example.com:"
+
globalDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
fooRegionDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
fooZoneDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
barRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
barZoneDNSName
+
":CNAME:180:["
+
barRegionDNSName
+
"]"
,
}
,
expected
:
sets
.
NewString
(
"example.com:"
+
globalDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
fooRegionDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
fooZoneDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
barRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
barZoneDNSName
+
":CNAME:180:["
+
barRegionDNSName
+
"]"
,
)
,
},
/*
TODO: getResolvedEndpoints preforms DNS lookup.
...
...
@@ -99,12 +99,12 @@ func TestServiceController_ensureDnsRecords(t *testing.T) {
String
()},
},
},
expected
:
[]
string
{
"example.com:"
+
fooRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
fooZoneDNSName
+
":CNAME:180:["
+
fooRegionDNSName
+
"]"
,
"example.com:"
+
barRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
barZoneDNSName
+
":CNAME:180:["
+
barRegionDNSName
+
"]"
,
}
,
expected
:
sets
.
NewString
(
"example.com:"
+
fooRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
fooZoneDNSName
+
":CNAME:180:["
+
fooRegionDNSName
+
"]"
,
"example.com:"
+
barRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
barZoneDNSName
+
":CNAME:180:["
+
barRegionDNSName
+
"]"
,
)
,
},
{
name
:
"ServiceWithMultipleLBIngress"
,
...
...
@@ -116,13 +116,13 @@ func TestServiceController_ensureDnsRecords(t *testing.T) {
String
()},
},
},
expected
:
[]
string
{
"example.com:"
+
globalDNSName
+
":A:180:[198.51.100.1 198.51.200.1]"
,
"example.com:"
+
fooRegionDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
fooZoneDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
barRegionDNSName
+
":A:180:[198.51.200.1]"
,
"example.com:"
+
barZoneDNSName
+
":A:180:[198.51.200.1]"
,
}
,
expected
:
sets
.
NewString
(
"example.com:"
+
globalDNSName
+
":A:180:[198.51.100.1 198.51.200.1]"
,
"example.com:"
+
fooRegionDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
fooZoneDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
barRegionDNSName
+
":A:180:[198.51.200.1]"
,
"example.com:"
+
barZoneDNSName
+
":A:180:[198.51.200.1]"
,
)
,
},
{
name
:
"ServiceWithLBIngressAndServiceDeleted"
,
...
...
@@ -135,13 +135,13 @@ func TestServiceController_ensureDnsRecords(t *testing.T) {
DeletionTimestamp
:
&
metav1
.
Time
{
Time
:
time
.
Now
()},
},
},
expected
:
[]
string
{
expected
:
sets
.
NewString
(
// TODO: Ideally we should expect that there are no DNS records when federated service is deleted. Need to remove these leaks in future
"example.com:"
+
fooRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
fooZoneDNSName
+
":CNAME:180:["
+
fooRegionDNSName
+
"]"
,
"example.com:"
+
barRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
barZoneDNSName
+
":CNAME:180:["
+
barRegionDNSName
+
"]"
,
}
,
"example.com:"
+
fooRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
fooZoneDNSName
+
":CNAME:180:["
+
fooRegionDNSName
+
"]"
,
"example.com:"
+
barRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
barZoneDNSName
+
":CNAME:180:["
+
barRegionDNSName
+
"]"
,
)
,
},
{
name
:
"ServiceWithMultipleLBIngressAndOneLBIngressGettingRemoved"
,
...
...
@@ -154,13 +154,13 @@ func TestServiceController_ensureDnsRecords(t *testing.T) {
String
()},
},
},
expected
:
[]
string
{
"example.com:"
+
globalDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
fooRegionDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
fooZoneDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
barRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
barZoneDNSName
+
":CNAME:180:["
+
barRegionDNSName
+
"]"
,
}
,
expected
:
sets
.
NewString
(
"example.com:"
+
globalDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
fooRegionDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
fooZoneDNSName
+
":A:180:[198.51.100.1]"
,
"example.com:"
+
barRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
barZoneDNSName
+
":CNAME:180:["
+
barRegionDNSName
+
"]"
,
)
,
},
{
name
:
"ServiceWithMultipleLBIngressAndAllLBIngressGettingRemoved"
,
...
...
@@ -174,12 +174,12 @@ func TestServiceController_ensureDnsRecords(t *testing.T) {
String
()},
},
},
expected
:
[]
string
{
"example.com:"
+
fooRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
fooZoneDNSName
+
":CNAME:180:["
+
fooRegionDNSName
+
"]"
,
"example.com:"
+
barRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
barZoneDNSName
+
":CNAME:180:["
+
barRegionDNSName
+
"]"
,
}
,
expected
:
sets
.
NewString
(
"example.com:"
+
fooRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
fooZoneDNSName
+
":CNAME:180:["
+
fooRegionDNSName
+
"]"
,
"example.com:"
+
barRegionDNSName
+
":CNAME:180:["
+
globalDNSName
+
"]"
,
"example.com:"
+
barZoneDNSName
+
":CNAME:180:["
+
barRegionDNSName
+
"]"
,
)
,
},
}
for
_
,
test
:=
range
tests
{
...
...
@@ -222,7 +222,7 @@ func TestServiceController_ensureDnsRecords(t *testing.T) {
}
// Dump every record to a testable-by-string-comparison form
records
:=
[]
string
{}
records
:=
sets
.
NewString
()
for
_
,
z
:=
range
zones
{
zoneName
:=
z
.
Name
()
...
...
@@ -240,17 +240,12 @@ func TestServiceController_ensureDnsRecords(t *testing.T) {
// Put in consistent (testable-by-string-comparison) order
sort
.
Strings
(
rrdatas
)
records
=
append
(
records
,
fmt
.
Sprintf
(
"%s:%s:%s:%d:%s"
,
zoneName
,
rr
.
Name
(),
rr
.
Type
(),
rr
.
Ttl
(),
rrdatas
))
records
.
Insert
(
fmt
.
Sprintf
(
"%s:%s:%s:%d:%s"
,
zoneName
,
rr
.
Name
(),
rr
.
Type
(),
rr
.
Ttl
(),
rrdatas
))
}
}
// Ignore order of records
sort
.
Strings
(
records
)
sort
.
Strings
(
test
.
expected
)
if
!
reflect
.
DeepEqual
(
records
,
test
.
expected
)
{
if
!
records
.
Equal
(
test
.
expected
)
{
t
.
Errorf
(
"Test %q failed. Actual=%v, Expected=%v"
,
test
.
name
,
records
,
test
.
expected
)
}
}
}
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