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
d57ec598
Commit
d57ec598
authored
Dec 31, 2018
by
Ed Bartosh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kubeadm: use T.Run API in app/apis/kubeadm
Used T.Run API for kubeadm tests in app/apis/kubeadm This should improve testing output and make it more visible which test is doing what.
parent
13e59ab9
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
22 deletions
+97
-22
bootstraptokenhelpers_test.go
cmd/kubeadm/app/apis/kubeadm/bootstraptokenhelpers_test.go
+55
-20
bootstraptokenstring_test.go
cmd/kubeadm/app/apis/kubeadm/bootstraptokenstring_test.go
+12
-0
bootstraptokenstring_test.go
...dm/app/apis/kubeadm/v1alpha3/bootstraptokenstring_test.go
+12
-0
conversion_test.go
cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion_test.go
+6
-2
bootstraptokenstring_test.go
...adm/app/apis/kubeadm/v1beta1/bootstraptokenstring_test.go
+12
-0
No files found.
cmd/kubeadm/app/apis/kubeadm/bootstraptokenhelpers_test.go
View file @
d57ec598
...
...
@@ -64,6 +64,7 @@ func TestToSecret(t *testing.T) {
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
bt
.
Token
.
ID
,
func
(
t
*
testing
.
T
)
{
actual
:=
rt
.
bt
.
ToSecret
()
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
secret
)
{
t
.
Errorf
(
...
...
@@ -72,6 +73,7 @@ func TestToSecret(t *testing.T) {
actual
,
)
}
})
}
}
...
...
@@ -92,6 +94,7 @@ func TestBootstrapTokenToSecretRoundtrip(t *testing.T) {
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
bt
.
Token
.
ID
,
func
(
t
*
testing
.
T
)
{
actual
,
err
:=
BootstrapTokenFromSecret
(
rt
.
bt
.
ToSecret
())
if
err
!=
nil
{
t
.
Errorf
(
"failed BootstrapToken to Secret roundtrip with error: %v"
,
err
)
...
...
@@ -103,16 +106,19 @@ func TestBootstrapTokenToSecretRoundtrip(t *testing.T) {
actual
,
)
}
})
}
}
func
TestEncodeTokenSecretData
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
name
string
bt
*
BootstrapToken
data
map
[
string
][]
byte
}{
{
&
BootstrapToken
{
// the minimum amount of information needed to be specified
"the minimum amount of information needed to be specified"
,
&
BootstrapToken
{
Token
:
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
},
},
map
[
string
][]
byte
{
...
...
@@ -121,7 +127,8 @@ func TestEncodeTokenSecretData(t *testing.T) {
},
},
{
&
BootstrapToken
{
// adds description
"adds description"
,
&
BootstrapToken
{
Token
:
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
},
Description
:
"foo"
,
},
...
...
@@ -132,7 +139,8 @@ func TestEncodeTokenSecretData(t *testing.T) {
},
},
{
&
BootstrapToken
{
// adds ttl
"adds ttl"
,
&
BootstrapToken
{
Token
:
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
},
TTL
:
&
metav1
.
Duration
{
Duration
:
mustParseDuration
(
"2h"
,
t
),
...
...
@@ -145,7 +153,8 @@ func TestEncodeTokenSecretData(t *testing.T) {
},
},
{
&
BootstrapToken
{
// adds expiration
"adds expiration"
,
&
BootstrapToken
{
Token
:
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
},
Expires
:
&
metav1
.
Time
{
Time
:
refTime
,
...
...
@@ -158,7 +167,8 @@ func TestEncodeTokenSecretData(t *testing.T) {
},
},
{
&
BootstrapToken
{
// adds ttl and expiration, should favor expiration
"adds ttl and expiration, should favor expiration"
,
&
BootstrapToken
{
Token
:
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
},
TTL
:
&
metav1
.
Duration
{
Duration
:
mustParseDuration
(
"2h"
,
t
),
...
...
@@ -174,7 +184,8 @@ func TestEncodeTokenSecretData(t *testing.T) {
},
},
{
&
BootstrapToken
{
// adds usages
"adds usages"
,
&
BootstrapToken
{
Token
:
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
},
Usages
:
[]
string
{
"authentication"
,
"signing"
},
},
...
...
@@ -186,7 +197,8 @@ func TestEncodeTokenSecretData(t *testing.T) {
},
},
{
&
BootstrapToken
{
// adds groups
"adds groups"
,
&
BootstrapToken
{
Token
:
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
},
Groups
:
[]
string
{
"system:bootstrappers"
,
"system:bootstrappers:foo"
},
},
...
...
@@ -197,7 +209,8 @@ func TestEncodeTokenSecretData(t *testing.T) {
},
},
{
&
BootstrapToken
{
// all together
"all together"
,
&
BootstrapToken
{
Token
:
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
},
Description
:
"foo"
,
TTL
:
&
metav1
.
Duration
{
...
...
@@ -221,6 +234,7 @@ func TestEncodeTokenSecretData(t *testing.T) {
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
name
,
func
(
t
*
testing
.
T
)
{
actual
:=
encodeTokenSecretData
(
rt
.
bt
,
refTime
)
if
!
reflect
.
DeepEqual
(
actual
,
rt
.
data
)
{
t
.
Errorf
(
...
...
@@ -229,6 +243,7 @@ func TestEncodeTokenSecretData(t *testing.T) {
actual
,
)
}
})
}
}
...
...
@@ -242,12 +257,14 @@ func mustParseDuration(durationStr string, t *testing.T) time.Duration {
func
TestBootstrapTokenFromSecret
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
desc
string
name
string
data
map
[
string
][]
byte
bt
*
BootstrapToken
expectedError
bool
}{
{
// minimum information
{
"minimum information"
,
"bootstrap-token-abcdef"
,
map
[
string
][]
byte
{
"token-id"
:
[]
byte
(
"abcdef"
),
...
...
@@ -258,7 +275,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
},
false
,
},
{
// invalid token id
{
"invalid token id"
,
"bootstrap-token-abcdef"
,
map
[
string
][]
byte
{
"token-id"
:
[]
byte
(
"abcdeF"
),
...
...
@@ -267,7 +285,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
nil
,
true
,
},
{
// invalid secret naming
{
"invalid secret naming"
,
"foo"
,
map
[
string
][]
byte
{
"token-id"
:
[]
byte
(
"abcdef"
),
...
...
@@ -276,7 +295,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
nil
,
true
,
},
{
// invalid token secret
{
"invalid token secret"
,
"bootstrap-token-abcdef"
,
map
[
string
][]
byte
{
"token-id"
:
[]
byte
(
"abcdef"
),
...
...
@@ -285,7 +305,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
nil
,
true
,
},
{
// adds description
{
"adds description"
,
"bootstrap-token-abcdef"
,
map
[
string
][]
byte
{
"token-id"
:
[]
byte
(
"abcdef"
),
...
...
@@ -298,7 +319,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
},
false
,
},
{
// adds expiration
{
"adds expiration"
,
"bootstrap-token-abcdef"
,
map
[
string
][]
byte
{
"token-id"
:
[]
byte
(
"abcdef"
),
...
...
@@ -313,7 +335,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
},
false
,
},
{
// invalid expiration
{
"invalid expiration"
,
"bootstrap-token-abcdef"
,
map
[
string
][]
byte
{
"token-id"
:
[]
byte
(
"abcdef"
),
...
...
@@ -323,7 +346,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
nil
,
true
,
},
{
// adds usages
{
"adds usages"
,
"bootstrap-token-abcdef"
,
map
[
string
][]
byte
{
"token-id"
:
[]
byte
(
"abcdef"
),
...
...
@@ -337,7 +361,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
},
false
,
},
{
// should ignore usages that aren't set to true
{
"should ignore usages that aren't set to true"
,
"bootstrap-token-abcdef"
,
map
[
string
][]
byte
{
"token-id"
:
[]
byte
(
"abcdef"
),
...
...
@@ -353,7 +378,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
},
false
,
},
{
// adds groups
{
"adds groups"
,
"bootstrap-token-abcdef"
,
map
[
string
][]
byte
{
"token-id"
:
[]
byte
(
"abcdef"
),
...
...
@@ -366,7 +392,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
},
false
,
},
{
// all fields set
{
"all fields set"
,
"bootstrap-token-abcdef"
,
map
[
string
][]
byte
{
"token-id"
:
[]
byte
(
"abcdef"
),
...
...
@@ -390,6 +417,7 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
desc
,
func
(
t
*
testing
.
T
)
{
actual
,
err
:=
BootstrapTokenFromSecret
(
&
v1
.
Secret
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
rt
.
name
,
...
...
@@ -407,7 +435,7 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
}
else
{
if
actual
==
nil
&&
rt
.
bt
==
nil
{
// if both pointers are nil, it's okay, just continue
continue
return
}
// If one of the pointers is defined but the other isn't, throw error. If both pointers are defined but unequal, throw error
if
(
actual
==
nil
&&
rt
.
bt
!=
nil
)
||
(
actual
!=
nil
&&
rt
.
bt
==
nil
)
||
!
reflect
.
DeepEqual
(
*
actual
,
*
rt
.
bt
)
{
...
...
@@ -418,6 +446,7 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
)
}
}
})
}
}
...
...
@@ -428,11 +457,13 @@ func jsonMarshal(bt *BootstrapToken) string {
func
TestGetSecretString
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
name
string
secret
*
v1
.
Secret
key
string
expectedVal
string
}{
{
name
:
"existing key"
,
secret
:
&
v1
.
Secret
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
},
Data
:
map
[
string
][]
byte
{
...
...
@@ -443,6 +474,7 @@ func TestGetSecretString(t *testing.T) {
expectedVal
:
"bar"
,
},
{
name
:
"non-existing key"
,
secret
:
&
v1
.
Secret
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
},
Data
:
map
[
string
][]
byte
{
...
...
@@ -453,6 +485,7 @@ func TestGetSecretString(t *testing.T) {
expectedVal
:
""
,
},
{
name
:
"no data"
,
secret
:
&
v1
.
Secret
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
},
},
...
...
@@ -461,6 +494,7 @@ func TestGetSecretString(t *testing.T) {
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
name
,
func
(
t
*
testing
.
T
)
{
actual
:=
getSecretString
(
rt
.
secret
,
rt
.
key
)
if
actual
!=
rt
.
expectedVal
{
t
.
Errorf
(
...
...
@@ -469,5 +503,6 @@ func TestGetSecretString(t *testing.T) {
actual
,
)
}
})
}
}
cmd/kubeadm/app/apis/kubeadm/bootstraptokenstring_test.go
View file @
d57ec598
...
...
@@ -34,6 +34,7 @@ func TestMarshalJSON(t *testing.T) {
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
`"h.b"`
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
bts
.
ID
,
func
(
t
*
testing
.
T
)
{
b
,
err
:=
json
.
Marshal
(
rt
.
bts
)
if
err
!=
nil
{
t
.
Fatalf
(
"json.Marshal returned an unexpected error: %v"
,
err
)
...
...
@@ -45,6 +46,7 @@ func TestMarshalJSON(t *testing.T) {
string
(
b
),
)
}
})
}
}
...
...
@@ -64,6 +66,7 @@ func TestUnmarshalJSON(t *testing.T) {
{
`"123456.aabbccddeeffgghh"`
,
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"aabbccddeeffgghh"
},
false
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
input
,
func
(
t
*
testing
.
T
)
{
newbts
:=
&
BootstrapTokenString
{}
err
:=
json
.
Unmarshal
([]
byte
(
rt
.
input
),
newbts
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
...
...
@@ -75,6 +78,7 @@ func TestUnmarshalJSON(t *testing.T) {
newbts
,
)
}
})
}
}
...
...
@@ -87,9 +91,11 @@ func TestJSONRoundtrip(t *testing.T) {
{
""
,
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
}},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
input
,
func
(
t
*
testing
.
T
)
{
if
err
:=
roundtrip
(
rt
.
input
,
rt
.
bts
);
err
!=
nil
{
t
.
Errorf
(
"failed BootstrapTokenString JSON roundtrip with error: %v"
,
err
)
}
})
}
}
...
...
@@ -140,6 +146,7 @@ func TestTokenFromIDAndSecret(t *testing.T) {
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
"h.b"
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
bts
.
ID
,
func
(
t
*
testing
.
T
)
{
actual
:=
rt
.
bts
.
String
()
if
actual
!=
rt
.
expected
{
t
.
Errorf
(
...
...
@@ -148,6 +155,7 @@ func TestTokenFromIDAndSecret(t *testing.T) {
actual
,
)
}
})
}
}
...
...
@@ -175,6 +183,7 @@ func TestNewBootstrapTokenString(t *testing.T) {
{
token
:
"123456.1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
token
,
func
(
t
*
testing
.
T
)
{
actual
,
err
:=
NewBootstrapTokenString
(
rt
.
token
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
t
.
Errorf
(
...
...
@@ -191,6 +200,7 @@ func TestNewBootstrapTokenString(t *testing.T) {
actual
,
)
}
})
}
}
...
...
@@ -215,6 +225,7 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
{
id
:
"123456"
,
secret
:
"1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
id
,
func
(
t
*
testing
.
T
)
{
actual
,
err
:=
NewBootstrapTokenStringFromIDAndSecret
(
rt
.
id
,
rt
.
secret
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
t
.
Errorf
(
...
...
@@ -233,5 +244,6 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
actual
,
)
}
})
}
}
cmd/kubeadm/app/apis/kubeadm/v1alpha3/bootstraptokenstring_test.go
View file @
d57ec598
...
...
@@ -34,6 +34,7 @@ func TestMarshalJSON(t *testing.T) {
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
`"h.b"`
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
bts
.
ID
,
func
(
t
*
testing
.
T
)
{
b
,
err
:=
json
.
Marshal
(
rt
.
bts
)
if
err
!=
nil
{
t
.
Fatalf
(
"json.Marshal returned an unexpected error: %v"
,
err
)
...
...
@@ -45,6 +46,7 @@ func TestMarshalJSON(t *testing.T) {
string
(
b
),
)
}
})
}
}
...
...
@@ -64,6 +66,7 @@ func TestUnmarshalJSON(t *testing.T) {
{
`"123456.aabbccddeeffgghh"`
,
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"aabbccddeeffgghh"
},
false
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
input
,
func
(
t
*
testing
.
T
)
{
newbts
:=
&
BootstrapTokenString
{}
err
:=
json
.
Unmarshal
([]
byte
(
rt
.
input
),
newbts
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
...
...
@@ -75,6 +78,7 @@ func TestUnmarshalJSON(t *testing.T) {
newbts
,
)
}
})
}
}
...
...
@@ -87,9 +91,11 @@ func TestJSONRoundtrip(t *testing.T) {
{
""
,
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
}},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
input
,
func
(
t
*
testing
.
T
)
{
if
err
:=
roundtrip
(
rt
.
input
,
rt
.
bts
);
err
!=
nil
{
t
.
Errorf
(
"failed BootstrapTokenString JSON roundtrip with error: %v"
,
err
)
}
})
}
}
...
...
@@ -140,6 +146,7 @@ func TestTokenFromIDAndSecret(t *testing.T) {
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
"h.b"
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
bts
.
ID
,
func
(
t
*
testing
.
T
)
{
actual
:=
rt
.
bts
.
String
()
if
actual
!=
rt
.
expected
{
t
.
Errorf
(
...
...
@@ -148,6 +155,7 @@ func TestTokenFromIDAndSecret(t *testing.T) {
actual
,
)
}
})
}
}
...
...
@@ -175,6 +183,7 @@ func TestNewBootstrapTokenString(t *testing.T) {
{
token
:
"123456.1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
token
,
func
(
t
*
testing
.
T
)
{
actual
,
err
:=
NewBootstrapTokenString
(
rt
.
token
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
t
.
Errorf
(
...
...
@@ -191,6 +200,7 @@ func TestNewBootstrapTokenString(t *testing.T) {
actual
,
)
}
})
}
}
...
...
@@ -215,6 +225,7 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
{
id
:
"123456"
,
secret
:
"1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
id
,
func
(
t
*
testing
.
T
)
{
actual
,
err
:=
NewBootstrapTokenStringFromIDAndSecret
(
rt
.
id
,
rt
.
secret
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
t
.
Errorf
(
...
...
@@ -233,5 +244,6 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
actual
,
)
}
})
}
}
cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion_test.go
View file @
d57ec598
...
...
@@ -46,13 +46,15 @@ func TestJoinConfigurationConversion(t *testing.T) {
expectedError
:
true
,
},
}
for
_
,
tc
:=
range
testcases
{
for
name
,
tc
:=
range
testcases
{
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
internal
:=
&
kubeadm
.
JoinConfiguration
{}
err
:=
Convert_v1alpha3_JoinConfiguration_To_kubeadm_JoinConfiguration
(
tc
.
old
,
internal
,
nil
)
if
(
err
!=
nil
)
!=
tc
.
expectedError
{
t
.
Errorf
(
"ImageToImageMeta returned unexpected error: %v, saw: %v"
,
tc
.
expectedError
,
(
err
!=
nil
))
return
}
})
}
}
...
...
@@ -76,12 +78,14 @@ func TestInitConfigurationConversion(t *testing.T) {
expectedErr
:
true
,
},
}
for
_
,
tc
:=
range
testcases
{
for
name
,
tc
:=
range
testcases
{
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
internal
:=
&
kubeadm
.
InitConfiguration
{}
err
:=
Convert_v1alpha3_InitConfiguration_To_kubeadm_InitConfiguration
(
tc
.
old
,
internal
,
nil
)
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 @
d57ec598
...
...
@@ -34,6 +34,7 @@ func TestMarshalJSON(t *testing.T) {
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
`"h.b"`
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
bts
.
ID
,
func
(
t
*
testing
.
T
)
{
b
,
err
:=
json
.
Marshal
(
rt
.
bts
)
if
err
!=
nil
{
t
.
Fatalf
(
"json.Marshal returned an unexpected error: %v"
,
err
)
...
...
@@ -45,6 +46,7 @@ func TestMarshalJSON(t *testing.T) {
string
(
b
),
)
}
})
}
}
...
...
@@ -64,6 +66,7 @@ func TestUnmarshalJSON(t *testing.T) {
{
`"123456.aabbccddeeffgghh"`
,
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"aabbccddeeffgghh"
},
false
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
input
,
func
(
t
*
testing
.
T
)
{
newbts
:=
&
BootstrapTokenString
{}
err
:=
json
.
Unmarshal
([]
byte
(
rt
.
input
),
newbts
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
...
...
@@ -75,6 +78,7 @@ func TestUnmarshalJSON(t *testing.T) {
newbts
,
)
}
})
}
}
...
...
@@ -87,9 +91,11 @@ func TestJSONRoundtrip(t *testing.T) {
{
""
,
&
BootstrapTokenString
{
ID
:
"abcdef"
,
Secret
:
"abcdef0123456789"
}},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
input
,
func
(
t
*
testing
.
T
)
{
if
err
:=
roundtrip
(
rt
.
input
,
rt
.
bts
);
err
!=
nil
{
t
.
Errorf
(
"failed BootstrapTokenString JSON roundtrip with error: %v"
,
err
)
}
})
}
}
...
...
@@ -140,6 +146,7 @@ func TestTokenFromIDAndSecret(t *testing.T) {
{
BootstrapTokenString
{
ID
:
"h"
,
Secret
:
"b"
},
"h.b"
},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
bts
.
ID
,
func
(
t
*
testing
.
T
)
{
actual
:=
rt
.
bts
.
String
()
if
actual
!=
rt
.
expected
{
t
.
Errorf
(
...
...
@@ -148,6 +155,7 @@ func TestTokenFromIDAndSecret(t *testing.T) {
actual
,
)
}
})
}
}
...
...
@@ -175,6 +183,7 @@ func TestNewBootstrapTokenString(t *testing.T) {
{
token
:
"123456.1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
token
,
func
(
t
*
testing
.
T
)
{
actual
,
err
:=
NewBootstrapTokenString
(
rt
.
token
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
t
.
Errorf
(
...
...
@@ -191,6 +200,7 @@ func TestNewBootstrapTokenString(t *testing.T) {
actual
,
)
}
})
}
}
...
...
@@ -215,6 +225,7 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
{
id
:
"123456"
,
secret
:
"1234560123456789"
,
expectedError
:
false
,
bts
:
&
BootstrapTokenString
{
ID
:
"123456"
,
Secret
:
"1234560123456789"
}},
}
for
_
,
rt
:=
range
tests
{
t
.
Run
(
rt
.
id
,
func
(
t
*
testing
.
T
)
{
actual
,
err
:=
NewBootstrapTokenStringFromIDAndSecret
(
rt
.
id
,
rt
.
secret
)
if
(
err
!=
nil
)
!=
rt
.
expectedError
{
t
.
Errorf
(
...
...
@@ -233,5 +244,6 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
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