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
7946a9a3
Unverified
Commit
7946a9a3
authored
Dec 31, 2018
by
Kubernetes Prow Robot
Committed by
GitHub
Dec 31, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #72445 from bart0sh/PR0052-app-apis-kubeadm-use-T.Run
kubeadm: use T.Run API in app/apis/kubeadm
parents
922c7221
d57ec598
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
368 additions
and
293 deletions
+368
-293
bootstraptokenhelpers_test.go
cmd/kubeadm/app/apis/kubeadm/bootstraptokenhelpers_test.go
+114
-79
bootstraptokenstring_test.go
cmd/kubeadm/app/apis/kubeadm/bootstraptokenstring_test.go
+79
-67
bootstraptokenstring_test.go
...dm/app/apis/kubeadm/v1alpha3/bootstraptokenstring_test.go
+79
-67
conversion_test.go
cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion_test.go
+17
-13
bootstraptokenstring_test.go
...adm/app/apis/kubeadm/v1beta1/bootstraptokenstring_test.go
+79
-67
No files found.
cmd/kubeadm/app/apis/kubeadm/bootstraptokenhelpers_test.go
View file @
7946a9a3
This diff is collapsed.
Click to expand it.
cmd/kubeadm/app/apis/kubeadm/bootstraptokenstring_test.go
View file @
7946a9a3
...
@@ -34,17 +34,19 @@ func TestMarshalJSON(t *testing.T) {
...
@@ -34,17 +34,19 @@ func TestMarshalJSON(t *testing.T) {
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
`"h.b"`
},
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
`"h.b"`
},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
b
,
err
:=
json
.
Marshal
(
rt
.
bts
)
t
.
Run
(
rt
.
bts
.
ID
,
func
(
t
*
testing
.
T
)
{
if
err
!=
nil
{
b
,
err
:=
json
.
Marshal
(
rt
.
bts
)
t
.
Fatalf
(
"json.Marshal returned an unexpected error: %v"
,
err
)
if
err
!=
nil
{
}
t
.
Fatalf
(
"json.Marshal returned an unexpected error: %v"
,
err
)
if
string
(
b
)
!=
rt
.
expected
{
}
t
.
Errorf
(
if
string
(
b
)
!=
rt
.
expected
{
"failed BootstrapTokenString.MarshalJSON:
\n\t
expected: %s
\n\t
actual: %s"
,
t
.
Errorf
(
rt
.
expected
,
"failed BootstrapTokenString.MarshalJSON:
\n\t
expected: %s
\n\t
actual: %s"
,
string
(
b
),
rt
.
expected
,
)
string
(
b
),
}
)
}
})
}
}
}
}
...
@@ -64,17 +66,19 @@ func TestUnmarshalJSON(t *testing.T) {
...
@@ -64,17 +66,19 @@ func TestUnmarshalJSON(t *testing.T) {
{
`"123456.aabbccddeeffgghh"`
,
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"aabbccddeeffgghh"
},
false
},
{
`"123456.aabbccddeeffgghh"`
,
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"aabbccddeeffgghh"
},
false
},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
newbts
:=
&
BootstrapTokenString
{}
t
.
Run
(
rt
.
input
,
func
(
t
*
testing
.
T
)
{
err
:=
json
.
Unmarshal
([]
byte
(
rt
.
input
),
newbts
)
newbts
:=
&
BootstrapTokenString
{}
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
err
:=
json
.
Unmarshal
([]
byte
(
rt
.
input
),
newbts
)
t
.
Errorf
(
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
expectedError
,
err
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
}
else
if
!
reflect
.
DeepEqual
(
rt
.
bts
,
newbts
)
{
t
.
Errorf
(
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
expectedError
,
err
)
t
.
Errorf
(
}
else
if
!
reflect
.
DeepEqual
(
rt
.
bts
,
newbts
)
{
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected: %v
\n\t
actual: %v"
,
t
.
Errorf
(
rt
.
bts
,
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected: %v
\n\t
actual: %v"
,
newbts
,
rt
.
bts
,
)
newbts
,
}
)
}
})
}
}
}
}
...
@@ -87,9 +91,11 @@ func TestJSONRoundtrip(t *testing.T) {
...
@@ -87,9 +91,11 @@ func TestJSONRoundtrip(t *testing.T) {
{
""
,
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
}},
{
""
,
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
}},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
if
err
:=
roundtrip
(
rt
.
input
,
rt
.
bts
);
err
!=
nil
{
t
.
Run
(
rt
.
input
,
func
(
t
*
testing
.
T
)
{
t
.
Errorf
(
"failed BootstrapTokenString JSON roundtrip with error: %v"
,
err
)
if
err
:=
roundtrip
(
rt
.
input
,
rt
.
bts
);
err
!=
nil
{
}
t
.
Errorf
(
"failed BootstrapTokenString JSON roundtrip with error: %v"
,
err
)
}
})
}
}
}
}
...
@@ -140,14 +146,16 @@ func TestTokenFromIDAndSecret(t *testing.T) {
...
@@ -140,14 +146,16 @@ func TestTokenFromIDAndSecret(t *testing.T) {
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
"h.b"
},
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
"h.b"
},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
actual
:=
rt
.
bts
.
String
()
t
.
Run
(
rt
.
bts
.
ID
,
func
(
t
*
testing
.
T
)
{
if
actual
!=
rt
.
expected
{
actual
:=
rt
.
bts
.
String
()
t
.
Errorf
(
if
actual
!=
rt
.
expected
{
"failed BootstrapTokenString.String():
\n\t
expected: %s
\n\t
actual: %s"
,
t
.
Errorf
(
rt
.
expected
,
"failed BootstrapTokenString.String():
\n\t
expected: %s
\n\t
actual: %s"
,
actual
,
rt
.
expected
,
)
actual
,
}
)
}
})
}
}
}
}
...
@@ -175,22 +183,24 @@ func TestNewBootstrapTokenString(t *testing.T) {
...
@@ -175,22 +183,24 @@ func TestNewBootstrapTokenString(t *testing.T) {
{
token
:
"123456.1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
{
token
:
"123456.1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
actual
,
err
:=
NewBootstrapTokenString
(
rt
.
token
)
t
.
Run
(
rt
.
token
,
func
(
t
*
testing
.
T
)
{
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
actual
,
err
:=
NewBootstrapTokenString
(
rt
.
token
)
t
.
Errorf
(
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
"failed NewBootstrapTokenString for the token %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
t
.
Errorf
(
rt
.
token
,
"failed NewBootstrapTokenString for the token %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
expectedError
,
rt
.
token
,
err
,
rt
.
expectedError
,
)
err
,
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
)
t
.
Errorf
(
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
"failed NewBootstrapTokenString for the token %q
\n\t
expected: %v
\n\t
actual: %v"
,
t
.
Errorf
(
rt
.
token
,
"failed NewBootstrapTokenString for the token %q
\n\t
expected: %v
\n\t
actual: %v"
,
rt
.
bts
,
rt
.
token
,
actual
,
rt
.
bts
,
)
actual
,
}
)
}
})
}
}
}
}
...
@@ -215,23 +225,25 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
...
@@ -215,23 +225,25 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
{
id
:
"123456"
,
secret
:
"1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
{
id
:
"123456"
,
secret
:
"1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
actual
,
err
:=
NewBootstrapTokenStringFromIDAndSecret
(
rt
.
id
,
rt
.
secret
)
t
.
Run
(
rt
.
id
,
func
(
t
*
testing
.
T
)
{
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
actual
,
err
:=
NewBootstrapTokenStringFromIDAndSecret
(
rt
.
id
,
rt
.
secret
)
t
.
Errorf
(
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
t
.
Errorf
(
rt
.
id
,
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
secret
,
rt
.
id
,
rt
.
expectedError
,
rt
.
secret
,
err
,
rt
.
expectedError
,
)
err
,
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
)
t
.
Errorf
(
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected: %v
\n\t
actual: %v"
,
t
.
Errorf
(
rt
.
id
,
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected: %v
\n\t
actual: %v"
,
rt
.
secret
,
rt
.
id
,
rt
.
bts
,
rt
.
secret
,
actual
,
rt
.
bts
,
)
actual
,
}
)
}
})
}
}
}
}
cmd/kubeadm/app/apis/kubeadm/v1alpha3/bootstraptokenstring_test.go
View file @
7946a9a3
...
@@ -34,17 +34,19 @@ func TestMarshalJSON(t *testing.T) {
...
@@ -34,17 +34,19 @@ func TestMarshalJSON(t *testing.T) {
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
`"h.b"`
},
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
`"h.b"`
},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
b
,
err
:=
json
.
Marshal
(
rt
.
bts
)
t
.
Run
(
rt
.
bts
.
ID
,
func
(
t
*
testing
.
T
)
{
if
err
!=
nil
{
b
,
err
:=
json
.
Marshal
(
rt
.
bts
)
t
.
Fatalf
(
"json.Marshal returned an unexpected error: %v"
,
err
)
if
err
!=
nil
{
}
t
.
Fatalf
(
"json.Marshal returned an unexpected error: %v"
,
err
)
if
string
(
b
)
!=
rt
.
expected
{
}
t
.
Errorf
(
if
string
(
b
)
!=
rt
.
expected
{
"failed BootstrapTokenString.MarshalJSON:
\n\t
expected: %s
\n\t
actual: %s"
,
t
.
Errorf
(
rt
.
expected
,
"failed BootstrapTokenString.MarshalJSON:
\n\t
expected: %s
\n\t
actual: %s"
,
string
(
b
),
rt
.
expected
,
)
string
(
b
),
}
)
}
})
}
}
}
}
...
@@ -64,17 +66,19 @@ func TestUnmarshalJSON(t *testing.T) {
...
@@ -64,17 +66,19 @@ func TestUnmarshalJSON(t *testing.T) {
{
`"123456.aabbccddeeffgghh"`
,
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"aabbccddeeffgghh"
},
false
},
{
`"123456.aabbccddeeffgghh"`
,
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"aabbccddeeffgghh"
},
false
},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
newbts
:=
&
BootstrapTokenString
{}
t
.
Run
(
rt
.
input
,
func
(
t
*
testing
.
T
)
{
err
:=
json
.
Unmarshal
([]
byte
(
rt
.
input
),
newbts
)
newbts
:=
&
BootstrapTokenString
{}
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
err
:=
json
.
Unmarshal
([]
byte
(
rt
.
input
),
newbts
)
t
.
Errorf
(
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
expectedError
,
err
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
}
else
if
!
reflect
.
DeepEqual
(
rt
.
bts
,
newbts
)
{
t
.
Errorf
(
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
expectedError
,
err
)
t
.
Errorf
(
}
else
if
!
reflect
.
DeepEqual
(
rt
.
bts
,
newbts
)
{
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected: %v
\n\t
actual: %v"
,
t
.
Errorf
(
rt
.
bts
,
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected: %v
\n\t
actual: %v"
,
newbts
,
rt
.
bts
,
)
newbts
,
}
)
}
})
}
}
}
}
...
@@ -87,9 +91,11 @@ func TestJSONRoundtrip(t *testing.T) {
...
@@ -87,9 +91,11 @@ func TestJSONRoundtrip(t *testing.T) {
{
""
,
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
}},
{
""
,
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
}},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
if
err
:=
roundtrip
(
rt
.
input
,
rt
.
bts
);
err
!=
nil
{
t
.
Run
(
rt
.
input
,
func
(
t
*
testing
.
T
)
{
t
.
Errorf
(
"failed BootstrapTokenString JSON roundtrip with error: %v"
,
err
)
if
err
:=
roundtrip
(
rt
.
input
,
rt
.
bts
);
err
!=
nil
{
}
t
.
Errorf
(
"failed BootstrapTokenString JSON roundtrip with error: %v"
,
err
)
}
})
}
}
}
}
...
@@ -140,14 +146,16 @@ func TestTokenFromIDAndSecret(t *testing.T) {
...
@@ -140,14 +146,16 @@ func TestTokenFromIDAndSecret(t *testing.T) {
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
"h.b"
},
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
"h.b"
},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
actual
:=
rt
.
bts
.
String
()
t
.
Run
(
rt
.
bts
.
ID
,
func
(
t
*
testing
.
T
)
{
if
actual
!=
rt
.
expected
{
actual
:=
rt
.
bts
.
String
()
t
.
Errorf
(
if
actual
!=
rt
.
expected
{
"failed BootstrapTokenString.String():
\n\t
expected: %s
\n\t
actual: %s"
,
t
.
Errorf
(
rt
.
expected
,
"failed BootstrapTokenString.String():
\n\t
expected: %s
\n\t
actual: %s"
,
actual
,
rt
.
expected
,
)
actual
,
}
)
}
})
}
}
}
}
...
@@ -175,22 +183,24 @@ func TestNewBootstrapTokenString(t *testing.T) {
...
@@ -175,22 +183,24 @@ func TestNewBootstrapTokenString(t *testing.T) {
{
token
:
"123456.1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
{
token
:
"123456.1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
actual
,
err
:=
NewBootstrapTokenString
(
rt
.
token
)
t
.
Run
(
rt
.
token
,
func
(
t
*
testing
.
T
)
{
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
actual
,
err
:=
NewBootstrapTokenString
(
rt
.
token
)
t
.
Errorf
(
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
"failed NewBootstrapTokenString for the token %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
t
.
Errorf
(
rt
.
token
,
"failed NewBootstrapTokenString for the token %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
expectedError
,
rt
.
token
,
err
,
rt
.
expectedError
,
)
err
,
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
)
t
.
Errorf
(
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
"failed NewBootstrapTokenString for the token %q
\n\t
expected: %v
\n\t
actual: %v"
,
t
.
Errorf
(
rt
.
token
,
"failed NewBootstrapTokenString for the token %q
\n\t
expected: %v
\n\t
actual: %v"
,
rt
.
bts
,
rt
.
token
,
actual
,
rt
.
bts
,
)
actual
,
}
)
}
})
}
}
}
}
...
@@ -215,23 +225,25 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
...
@@ -215,23 +225,25 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
{
id
:
"123456"
,
secret
:
"1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
{
id
:
"123456"
,
secret
:
"1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
actual
,
err
:=
NewBootstrapTokenStringFromIDAndSecret
(
rt
.
id
,
rt
.
secret
)
t
.
Run
(
rt
.
id
,
func
(
t
*
testing
.
T
)
{
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
actual
,
err
:=
NewBootstrapTokenStringFromIDAndSecret
(
rt
.
id
,
rt
.
secret
)
t
.
Errorf
(
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
t
.
Errorf
(
rt
.
id
,
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
secret
,
rt
.
id
,
rt
.
expectedError
,
rt
.
secret
,
err
,
rt
.
expectedError
,
)
err
,
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
)
t
.
Errorf
(
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected: %v
\n\t
actual: %v"
,
t
.
Errorf
(
rt
.
id
,
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected: %v
\n\t
actual: %v"
,
rt
.
secret
,
rt
.
id
,
rt
.
bts
,
rt
.
secret
,
actual
,
rt
.
bts
,
)
actual
,
}
)
}
})
}
}
}
}
cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion_test.go
View file @
7946a9a3
...
@@ -46,13 +46,15 @@ func TestJoinConfigurationConversion(t *testing.T) {
...
@@ -46,13 +46,15 @@ func TestJoinConfigurationConversion(t *testing.T) {
expectedError
:
true
,
expectedError
:
true
,
},
},
}
}
for
_
,
tc
:=
range
testcases
{
for
name
,
tc
:=
range
testcases
{
internal
:=
&
kubeadm
.
JoinConfiguration
{}
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
err
:=
Convert_v1alpha3_JoinConfiguration_To_kubeadm_JoinConfiguration
(
tc
.
old
,
internal
,
nil
)
internal
:=
&
kubeadm
.
JoinConfiguration
{}
if
(
err
!=
nil
)
!=
tc
.
expectedError
{
err
:=
Convert_v1alpha3_JoinConfiguration_To_kubeadm_JoinConfiguration
(
tc
.
old
,
internal
,
nil
)
t
.
Errorf
(
"ImageToImageMeta returned unexpected error: %v, saw: %v"
,
tc
.
expectedError
,
(
err
!=
nil
))
if
(
err
!=
nil
)
!=
tc
.
expectedError
{
return
t
.
Errorf
(
"ImageToImageMeta returned unexpected error: %v, saw: %v"
,
tc
.
expectedError
,
(
err
!=
nil
))
}
return
}
})
}
}
}
}
...
@@ -76,12 +78,14 @@ func TestInitConfigurationConversion(t *testing.T) {
...
@@ -76,12 +78,14 @@ func TestInitConfigurationConversion(t *testing.T) {
expectedErr
:
true
,
expectedErr
:
true
,
},
},
}
}
for
_
,
tc
:=
range
testcases
{
for
name
,
tc
:=
range
testcases
{
internal
:=
&
kubeadm
.
InitConfiguration
{}
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
err
:=
Convert_v1alpha3_InitConfiguration_To_kubeadm_InitConfiguration
(
tc
.
old
,
internal
,
nil
)
internal
:=
&
kubeadm
.
InitConfiguration
{}
if
(
err
!=
nil
)
!=
tc
.
expectedErr
{
err
:=
Convert_v1alpha3_InitConfiguration_To_kubeadm_InitConfiguration
(
tc
.
old
,
internal
,
nil
)
t
.
Errorf
(
"no error was expected but '%s' was found"
,
err
)
if
(
err
!=
nil
)
!=
tc
.
expectedErr
{
}
t
.
Errorf
(
"no error was expected but '%s' was found"
,
err
)
}
})
}
}
}
}
...
...
cmd/kubeadm/app/apis/kubeadm/v1beta1/bootstraptokenstring_test.go
View file @
7946a9a3
...
@@ -34,17 +34,19 @@ func TestMarshalJSON(t *testing.T) {
...
@@ -34,17 +34,19 @@ func TestMarshalJSON(t *testing.T) {
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
`"h.b"`
},
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
`"h.b"`
},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
b
,
err
:=
json
.
Marshal
(
rt
.
bts
)
t
.
Run
(
rt
.
bts
.
ID
,
func
(
t
*
testing
.
T
)
{
if
err
!=
nil
{
b
,
err
:=
json
.
Marshal
(
rt
.
bts
)
t
.
Fatalf
(
"json.Marshal returned an unexpected error: %v"
,
err
)
if
err
!=
nil
{
}
t
.
Fatalf
(
"json.Marshal returned an unexpected error: %v"
,
err
)
if
string
(
b
)
!=
rt
.
expected
{
}
t
.
Errorf
(
if
string
(
b
)
!=
rt
.
expected
{
"failed BootstrapTokenString.MarshalJSON:
\n\t
expected: %s
\n\t
actual: %s"
,
t
.
Errorf
(
rt
.
expected
,
"failed BootstrapTokenString.MarshalJSON:
\n\t
expected: %s
\n\t
actual: %s"
,
string
(
b
),
rt
.
expected
,
)
string
(
b
),
}
)
}
})
}
}
}
}
...
@@ -64,17 +66,19 @@ func TestUnmarshalJSON(t *testing.T) {
...
@@ -64,17 +66,19 @@ func TestUnmarshalJSON(t *testing.T) {
{
`"123456.aabbccddeeffgghh"`
,
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"aabbccddeeffgghh"
},
false
},
{
`"123456.aabbccddeeffgghh"`
,
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"aabbccddeeffgghh"
},
false
},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
newbts
:=
&
BootstrapTokenString
{}
t
.
Run
(
rt
.
input
,
func
(
t
*
testing
.
T
)
{
err
:=
json
.
Unmarshal
([]
byte
(
rt
.
input
),
newbts
)
newbts
:=
&
BootstrapTokenString
{}
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
err
:=
json
.
Unmarshal
([]
byte
(
rt
.
input
),
newbts
)
t
.
Errorf
(
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
expectedError
,
err
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
}
else
if
!
reflect
.
DeepEqual
(
rt
.
bts
,
newbts
)
{
t
.
Errorf
(
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
expectedError
,
err
)
t
.
Errorf
(
}
else
if
!
reflect
.
DeepEqual
(
rt
.
bts
,
newbts
)
{
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected: %v
\n\t
actual: %v"
,
t
.
Errorf
(
rt
.
bts
,
"failed BootstrapTokenString.UnmarshalJSON:
\n\t
expected: %v
\n\t
actual: %v"
,
newbts
,
rt
.
bts
,
)
newbts
,
}
)
}
})
}
}
}
}
...
@@ -87,9 +91,11 @@ func TestJSONRoundtrip(t *testing.T) {
...
@@ -87,9 +91,11 @@ func TestJSONRoundtrip(t *testing.T) {
{
""
,
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
}},
{
""
,
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
}},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
if
err
:=
roundtrip
(
rt
.
input
,
rt
.
bts
);
err
!=
nil
{
t
.
Run
(
rt
.
input
,
func
(
t
*
testing
.
T
)
{
t
.
Errorf
(
"failed BootstrapTokenString JSON roundtrip with error: %v"
,
err
)
if
err
:=
roundtrip
(
rt
.
input
,
rt
.
bts
);
err
!=
nil
{
}
t
.
Errorf
(
"failed BootstrapTokenString JSON roundtrip with error: %v"
,
err
)
}
})
}
}
}
}
...
@@ -140,14 +146,16 @@ func TestTokenFromIDAndSecret(t *testing.T) {
...
@@ -140,14 +146,16 @@ func TestTokenFromIDAndSecret(t *testing.T) {
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
"h.b"
},
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
"h.b"
},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
actual
:=
rt
.
bts
.
String
()
t
.
Run
(
rt
.
bts
.
ID
,
func
(
t
*
testing
.
T
)
{
if
actual
!=
rt
.
expected
{
actual
:=
rt
.
bts
.
String
()
t
.
Errorf
(
if
actual
!=
rt
.
expected
{
"failed BootstrapTokenString.String():
\n\t
expected: %s
\n\t
actual: %s"
,
t
.
Errorf
(
rt
.
expected
,
"failed BootstrapTokenString.String():
\n\t
expected: %s
\n\t
actual: %s"
,
actual
,
rt
.
expected
,
)
actual
,
}
)
}
})
}
}
}
}
...
@@ -175,22 +183,24 @@ func TestNewBootstrapTokenString(t *testing.T) {
...
@@ -175,22 +183,24 @@ func TestNewBootstrapTokenString(t *testing.T) {
{
token
:
"123456.1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
{
token
:
"123456.1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
actual
,
err
:=
NewBootstrapTokenString
(
rt
.
token
)
t
.
Run
(
rt
.
token
,
func
(
t
*
testing
.
T
)
{
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
actual
,
err
:=
NewBootstrapTokenString
(
rt
.
token
)
t
.
Errorf
(
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
"failed NewBootstrapTokenString for the token %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
t
.
Errorf
(
rt
.
token
,
"failed NewBootstrapTokenString for the token %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
expectedError
,
rt
.
token
,
err
,
rt
.
expectedError
,
)
err
,
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
)
t
.
Errorf
(
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
"failed NewBootstrapTokenString for the token %q
\n\t
expected: %v
\n\t
actual: %v"
,
t
.
Errorf
(
rt
.
token
,
"failed NewBootstrapTokenString for the token %q
\n\t
expected: %v
\n\t
actual: %v"
,
rt
.
bts
,
rt
.
token
,
actual
,
rt
.
bts
,
)
actual
,
}
)
}
})
}
}
}
}
...
@@ -215,23 +225,25 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
...
@@ -215,23 +225,25 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
{
id
:
"123456"
,
secret
:
"1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
{
id
:
"123456"
,
secret
:
"1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
}
for
_
,
rt
:=
range
tests
{
for
_
,
rt
:=
range
tests
{
actual
,
err
:=
NewBootstrapTokenStringFromIDAndSecret
(
rt
.
id
,
rt
.
secret
)
t
.
Run
(
rt
.
id
,
func
(
t
*
testing
.
T
)
{
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
actual
,
err
:=
NewBootstrapTokenStringFromIDAndSecret
(
rt
.
id
,
rt
.
secret
)
t
.
Errorf
(
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
t
.
Errorf
(
rt
.
id
,
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected error: %t
\n\t
actual error: %v"
,
rt
.
secret
,
rt
.
id
,
rt
.
expectedError
,
rt
.
secret
,
err
,
rt
.
expectedError
,
)
err
,
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
)
t
.
Errorf
(
}
else
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
bts
)
{
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected: %v
\n\t
actual: %v"
,
t
.
Errorf
(
rt
.
id
,
"failed NewBootstrapTokenStringFromIDAndSecret for the token with id %q and secret %q
\n\t
expected: %v
\n\t
actual: %v"
,
rt
.
secret
,
rt
.
id
,
rt
.
bts
,
rt
.
secret
,
actual
,
rt
.
bts
,
)
actual
,
}
)
}
})
}
}
}
}
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