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
f15a0fc0
Commit
f15a0fc0
authored
May 14, 2018
by
Guoliang Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use subtest for table units (pkg/master)
parent
e24fd8ef
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
107 deletions
+140
-107
client_ca_hook_test.go
pkg/master/client_ca_hook_test.go
+11
-11
crdregistration_controller_test.go
...roller/crdregistration/crdregistration_controller_test.go
+21
-19
lease_test.go
pkg/master/reconcilers/lease_test.go
+49
-45
ssh_test.go
pkg/master/tunneler/ssh_test.go
+59
-32
No files found.
pkg/master/client_ca_hook_test.go
View file @
f15a0fc0
...
@@ -189,18 +189,18 @@ func TestWriteClientCAs(t *testing.T) {
...
@@ -189,18 +189,18 @@ func TestWriteClientCAs(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
client
:=
fake
.
NewSimpleClientset
(
test
.
preexistingObjs
...
)
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
test
.
hook
.
tryToWriteClientCAs
(
client
.
Core
())
client
:=
fake
.
NewSimpleClientset
(
test
.
preexistingObjs
...
)
test
.
hook
.
tryToWriteClientCAs
(
client
.
Core
())
actualConfigMaps
,
updated
:=
getFinalConfiMaps
(
client
)
actualConfigMaps
,
updated
:=
getFinalConfiMaps
(
client
)
if
!
reflect
.
DeepEqual
(
test
.
expectedConfigMaps
,
actualConfigMaps
)
{
if
!
reflect
.
DeepEqual
(
test
.
expectedConfigMaps
,
actualConfigMaps
)
{
t
.
Errorf
(
"%s: %v"
,
test
.
name
,
diff
.
ObjectReflectDiff
(
test
.
expectedConfigMaps
,
actualConfigMaps
))
t
.
Fatalf
(
"%s: %v"
,
test
.
name
,
diff
.
ObjectReflectDiff
(
test
.
expectedConfigMaps
,
actualConfigMaps
))
continue
}
}
if
test
.
expectUpdate
!=
updated
{
if
test
.
expectUpdate
!=
updated
{
t
.
Fatalf
(
"%s: expected %v, got %v"
,
test
.
name
,
test
.
expectUpdate
,
updated
)
t
.
Errorf
(
"%s: expected %v, got %v"
,
test
.
name
,
test
.
expectUpdate
,
updated
)
}
continue
})
}
}
}
}
}
...
...
pkg/master/controller/crdregistration/crdregistration_controller_test.go
View file @
f15a0fc0
...
@@ -78,25 +78,27 @@ func TestHandleVersionUpdate(t *testing.T) {
...
@@ -78,25 +78,27 @@ func TestHandleVersionUpdate(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
registration
:=
&
fakeAPIServiceRegistration
{}
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
crdCache
:=
cache
.
NewIndexer
(
cache
.
DeletionHandlingMetaNamespaceKeyFunc
,
cache
.
Indexers
{
cache
.
NamespaceIndex
:
cache
.
MetaNamespaceIndexFunc
})
registration
:=
&
fakeAPIServiceRegistration
{}
crdLister
:=
crdlisters
.
NewCustomResourceDefinitionLister
(
crdCache
)
crdCache
:=
cache
.
NewIndexer
(
cache
.
DeletionHandlingMetaNamespaceKeyFunc
,
cache
.
Indexers
{
cache
.
NamespaceIndex
:
cache
.
MetaNamespaceIndexFunc
})
c
:=
crdRegistrationController
{
crdLister
:=
crdlisters
.
NewCustomResourceDefinitionLister
(
crdCache
)
crdLister
:
crdLister
,
c
:=
crdRegistrationController
{
apiServiceRegistration
:
registration
,
crdLister
:
crdLister
,
}
apiServiceRegistration
:
registration
,
for
i
:=
range
test
.
startingCRDs
{
}
crdCache
.
Add
(
test
.
startingCRDs
[
i
])
for
i
:=
range
test
.
startingCRDs
{
}
crdCache
.
Add
(
test
.
startingCRDs
[
i
])
}
c
.
handleVersionUpdate
(
test
.
version
)
c
.
handleVersionUpdate
(
test
.
version
)
if
!
reflect
.
DeepEqual
(
test
.
expectedAdded
,
registration
.
added
)
{
t
.
Errorf
(
"%s expected %v, got %v"
,
test
.
name
,
test
.
expectedAdded
,
registration
.
added
)
if
!
reflect
.
DeepEqual
(
test
.
expectedAdded
,
registration
.
added
)
{
}
t
.
Errorf
(
"%s expected %v, got %v"
,
test
.
name
,
test
.
expectedAdded
,
registration
.
added
)
if
!
reflect
.
DeepEqual
(
test
.
expectedRemoved
,
registration
.
removed
)
{
}
t
.
Errorf
(
"%s expected %v, got %v"
,
test
.
name
,
test
.
expectedRemoved
,
registration
.
removed
)
if
!
reflect
.
DeepEqual
(
test
.
expectedRemoved
,
registration
.
removed
)
{
}
t
.
Errorf
(
"%s expected %v, got %v"
,
test
.
name
,
test
.
expectedRemoved
,
registration
.
removed
)
}
})
}
}
}
}
...
...
pkg/master/reconcilers/lease_test.go
View file @
f15a0fc0
...
@@ -509,29 +509,31 @@ func TestLeaseEndpointReconciler(t *testing.T) {
...
@@ -509,29 +509,31 @@ func TestLeaseEndpointReconciler(t *testing.T) {
},
},
}
}
for
_
,
test
:=
range
nonReconcileTests
{
for
_
,
test
:=
range
nonReconcileTests
{
fakeLeases
:=
newFakeLeases
()
t
.
Run
(
test
.
testName
,
func
(
t
*
testing
.
T
)
{
fakeLeases
.
SetKeys
(
test
.
endpointKeys
)
fakeLeases
:=
newFakeLeases
()
registry
:=
&
registrytest
.
EndpointRegistry
{
fakeLeases
.
SetKeys
(
test
.
endpointKeys
)
Endpoints
:
test
.
endpoints
,
registry
:=
&
registrytest
.
EndpointRegistry
{
}
Endpoints
:
test
.
endpoints
,
r
:=
NewLeaseEndpointReconciler
(
registry
,
fakeLeases
)
err
:=
r
.
ReconcileEndpoints
(
test
.
serviceName
,
net
.
ParseIP
(
test
.
ip
),
test
.
endpointPorts
,
false
)
if
err
!=
nil
{
t
.
Errorf
(
"case %q: unexpected error: %v"
,
test
.
testName
,
err
)
}
if
test
.
expectUpdate
!=
nil
{
if
len
(
registry
.
Updates
)
!=
1
{
t
.
Errorf
(
"case %q: unexpected updates: %v"
,
test
.
testName
,
registry
.
Updates
)
}
else
if
e
,
a
:=
test
.
expectUpdate
,
&
registry
.
Updates
[
0
];
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"case %q: expected update:
\n
%#v
\n
got:
\n
%#v
\n
"
,
test
.
testName
,
e
,
a
)
}
}
}
r
:=
NewLeaseEndpointReconciler
(
registry
,
fakeLeases
)
if
test
.
expectUpdate
==
nil
&&
len
(
registry
.
Updates
)
>
0
{
err
:=
r
.
ReconcileEndpoints
(
test
.
serviceName
,
net
.
ParseIP
(
test
.
ip
),
test
.
endpointPorts
,
false
)
t
.
Errorf
(
"case %q: no update expected, yet saw: %v"
,
test
.
testName
,
registry
.
Updates
)
if
err
!=
nil
{
}
t
.
Errorf
(
"case %q: unexpected error: %v"
,
test
.
testName
,
err
)
if
updatedKeys
:=
fakeLeases
.
GetUpdatedKeys
();
len
(
updatedKeys
)
!=
1
||
updatedKeys
[
0
]
!=
test
.
ip
{
}
t
.
Errorf
(
"case %q: expected the master's IP to be refreshed, but the following IPs were refreshed instead: %v"
,
test
.
testName
,
updatedKeys
)
if
test
.
expectUpdate
!=
nil
{
}
if
len
(
registry
.
Updates
)
!=
1
{
t
.
Errorf
(
"case %q: unexpected updates: %v"
,
test
.
testName
,
registry
.
Updates
)
}
else
if
e
,
a
:=
test
.
expectUpdate
,
&
registry
.
Updates
[
0
];
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"case %q: expected update:
\n
%#v
\n
got:
\n
%#v
\n
"
,
test
.
testName
,
e
,
a
)
}
}
if
test
.
expectUpdate
==
nil
&&
len
(
registry
.
Updates
)
>
0
{
t
.
Errorf
(
"case %q: no update expected, yet saw: %v"
,
test
.
testName
,
registry
.
Updates
)
}
if
updatedKeys
:=
fakeLeases
.
GetUpdatedKeys
();
len
(
updatedKeys
)
!=
1
||
updatedKeys
[
0
]
!=
test
.
ip
{
t
.
Errorf
(
"case %q: expected the master's IP to be refreshed, but the following IPs were refreshed instead: %v"
,
test
.
testName
,
updatedKeys
)
}
})
}
}
}
}
...
@@ -604,30 +606,32 @@ func TestLeaseStopReconciling(t *testing.T) {
...
@@ -604,30 +606,32 @@ func TestLeaseStopReconciling(t *testing.T) {
},
},
}
}
for
_
,
test
:=
range
stopTests
{
for
_
,
test
:=
range
stopTests
{
fakeLeases
:=
newFakeLeases
()
t
.
Run
(
test
.
testName
,
func
(
t
*
testing
.
T
)
{
fakeLeases
.
SetKeys
(
test
.
endpointKeys
)
fakeLeases
:=
newFakeLeases
()
registry
:=
&
registrytest
.
EndpointRegistry
{
fakeLeases
.
SetKeys
(
test
.
endpointKeys
)
Endpoints
:
test
.
endpoints
,
registry
:=
&
registrytest
.
EndpointRegistry
{
}
Endpoints
:
test
.
endpoints
,
r
:=
NewLeaseEndpointReconciler
(
registry
,
fakeLeases
)
err
:=
r
.
StopReconciling
(
test
.
serviceName
,
net
.
ParseIP
(
test
.
ip
),
test
.
endpointPorts
)
if
err
!=
nil
{
t
.
Errorf
(
"case %q: unexpected error: %v"
,
test
.
testName
,
err
)
}
if
test
.
expectUpdate
!=
nil
{
if
len
(
registry
.
Updates
)
!=
1
{
t
.
Errorf
(
"case %q: unexpected updates: %v"
,
test
.
testName
,
registry
.
Updates
)
}
else
if
e
,
a
:=
test
.
expectUpdate
,
&
registry
.
Updates
[
0
];
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"case %q: expected update:
\n
%#v
\n
got:
\n
%#v
\n
"
,
test
.
testName
,
e
,
a
)
}
}
}
r
:=
NewLeaseEndpointReconciler
(
registry
,
fakeLeases
)
if
test
.
expectUpdate
==
nil
&&
len
(
registry
.
Updates
)
>
0
{
err
:=
r
.
StopReconciling
(
test
.
serviceName
,
net
.
ParseIP
(
test
.
ip
),
test
.
endpointPorts
)
t
.
Errorf
(
"case %q: no update expected, yet saw: %v"
,
test
.
testName
,
registry
.
Updates
)
if
err
!=
nil
{
}
t
.
Errorf
(
"case %q: unexpected error: %v"
,
test
.
testName
,
err
)
for
_
,
key
:=
range
fakeLeases
.
GetUpdatedKeys
()
{
if
key
==
test
.
ip
{
t
.
Errorf
(
"case %q: Found ip %s in leases but shouldn't be there"
,
test
.
testName
,
key
)
}
}
}
if
test
.
expectUpdate
!=
nil
{
if
len
(
registry
.
Updates
)
!=
1
{
t
.
Errorf
(
"case %q: unexpected updates: %v"
,
test
.
testName
,
registry
.
Updates
)
}
else
if
e
,
a
:=
test
.
expectUpdate
,
&
registry
.
Updates
[
0
];
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"case %q: expected update:
\n
%#v
\n
got:
\n
%#v
\n
"
,
test
.
testName
,
e
,
a
)
}
}
if
test
.
expectUpdate
==
nil
&&
len
(
registry
.
Updates
)
>
0
{
t
.
Errorf
(
"case %q: no update expected, yet saw: %v"
,
test
.
testName
,
registry
.
Updates
)
}
for
_
,
key
:=
range
fakeLeases
.
GetUpdatedKeys
()
{
if
key
==
test
.
ip
{
t
.
Errorf
(
"case %q: Found ip %s in leases but shouldn't be there"
,
test
.
testName
,
key
)
}
}
})
}
}
}
}
pkg/master/tunneler/ssh_test.go
View file @
f15a0fc0
...
@@ -32,39 +32,66 @@ import (
...
@@ -32,39 +32,66 @@ import (
// TestSecondsSinceSync verifies that proper results are returned
// TestSecondsSinceSync verifies that proper results are returned
// when checking the time between syncs
// when checking the time between syncs
func
TestSecondsSinceSync
(
t
*
testing
.
T
)
{
func
TestSecondsSinceSync
(
t
*
testing
.
T
)
{
tunneler
:=
&
SSHTunneler
{}
tests
:=
[]
struct
{
assert
:=
assert
.
New
(
t
)
name
string
lastSync
int64
tunneler
.
lastSync
=
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
1
,
1
,
time
.
UTC
)
.
Unix
()
clock
*
clock
.
FakeClock
want
int64
// Nano Second. No difference.
}{
tunneler
.
clock
=
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
1
,
2
,
time
.
UTC
))
{
assert
.
Equal
(
int64
(
0
),
tunneler
.
SecondsSinceSync
())
name
:
"Nano Second. No difference"
,
lastSync
:
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
1
,
1
,
time
.
UTC
)
.
Unix
(),
// Second
clock
:
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
1
,
2
,
time
.
UTC
)),
tunneler
.
clock
=
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
2
,
1
,
time
.
UTC
))
want
:
int64
(
0
),
assert
.
Equal
(
int64
(
1
),
tunneler
.
SecondsSinceSync
())
},
{
// Minute
name
:
"Second"
,
tunneler
.
clock
=
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
2
,
1
,
1
,
time
.
UTC
))
lastSync
:
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
1
,
1
,
time
.
UTC
)
.
Unix
(),
assert
.
Equal
(
int64
(
60
),
tunneler
.
SecondsSinceSync
())
clock
:
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
2
,
1
,
time
.
UTC
)),
want
:
int64
(
1
),
// Hour
},
tunneler
.
clock
=
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
January
,
1
,
2
,
1
,
1
,
1
,
time
.
UTC
))
{
assert
.
Equal
(
int64
(
3600
),
tunneler
.
SecondsSinceSync
())
name
:
"Minute"
,
lastSync
:
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
1
,
1
,
time
.
UTC
)
.
Unix
(),
// Day
clock
:
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
2
,
1
,
1
,
time
.
UTC
)),
tunneler
.
clock
=
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
January
,
2
,
1
,
1
,
1
,
1
,
time
.
UTC
))
want
:
int64
(
60
),
assert
.
Equal
(
int64
(
86400
),
tunneler
.
SecondsSinceSync
())
},
{
// Month
name
:
"Hour"
,
tunneler
.
clock
=
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
February
,
1
,
1
,
1
,
1
,
1
,
time
.
UTC
))
lastSync
:
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
1
,
1
,
time
.
UTC
)
.
Unix
(),
assert
.
Equal
(
int64
(
2678400
),
tunneler
.
SecondsSinceSync
())
clock
:
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
January
,
1
,
2
,
1
,
1
,
1
,
time
.
UTC
)),
want
:
int64
(
3600
),
},
{
name
:
"Day"
,
lastSync
:
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
1
,
1
,
time
.
UTC
)
.
Unix
(),
clock
:
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
January
,
2
,
1
,
1
,
1
,
1
,
time
.
UTC
)),
want
:
int64
(
86400
),
},
{
name
:
"Month"
,
lastSync
:
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
1
,
1
,
time
.
UTC
)
.
Unix
(),
clock
:
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
February
,
1
,
1
,
1
,
1
,
1
,
time
.
UTC
)),
want
:
int64
(
2678400
),
},
{
name
:
"Future Month. Should be -Month"
,
lastSync
:
time
.
Date
(
2015
,
time
.
February
,
1
,
1
,
1
,
1
,
1
,
time
.
UTC
)
.
Unix
(),
clock
:
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
1
,
2
,
time
.
UTC
)),
want
:
int64
(
-
2678400
),
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
tunneler
:=
&
SSHTunneler
{}
assert
:=
assert
.
New
(
t
)
tunneler
.
lastSync
=
tt
.
lastSync
tunneler
.
clock
=
tt
.
clock
assert
.
Equal
(
int64
(
tt
.
want
),
tunneler
.
SecondsSinceSync
())
})
}
// Future Month. Should be -Month.
tunneler
.
lastSync
=
time
.
Date
(
2015
,
time
.
February
,
1
,
1
,
1
,
1
,
1
,
time
.
UTC
)
.
Unix
()
tunneler
.
clock
=
clock
.
NewFakeClock
(
time
.
Date
(
2015
,
time
.
January
,
1
,
1
,
1
,
1
,
1
,
time
.
UTC
))
assert
.
Equal
(
int64
(
-
2678400
),
tunneler
.
SecondsSinceSync
())
}
}
// generateTempFile creates a temporary file path
// generateTempFile creates a temporary file path
...
...
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