Merge pull request #72445 from bart0sh/PR0052-app-apis-kubeadm-use-T.Run

kubeadm: use T.Run API in app/apis/kubeadm
This commit is contained in:
Kubernetes Prow Robot 2018-12-31 00:38:29 -08:00 committed by GitHub
commit 7946a9a327
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 368 additions and 293 deletions

View File

@ -64,6 +64,7 @@ func TestToSecret(t *testing.T) {
}, },
} }
for _, rt := range tests { for _, rt := range tests {
t.Run(rt.bt.Token.ID, func(t *testing.T) {
actual := rt.bt.ToSecret() actual := rt.bt.ToSecret()
if !reflect.DeepEqual(actual, rt.secret) { if !reflect.DeepEqual(actual, rt.secret) {
t.Errorf( t.Errorf(
@ -72,6 +73,7 @@ func TestToSecret(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }
@ -92,6 +94,7 @@ func TestBootstrapTokenToSecretRoundtrip(t *testing.T) {
}, },
} }
for _, rt := range tests { for _, rt := range tests {
t.Run(rt.bt.Token.ID, func(t *testing.T) {
actual, err := BootstrapTokenFromSecret(rt.bt.ToSecret()) actual, err := BootstrapTokenFromSecret(rt.bt.ToSecret())
if err != nil { if err != nil {
t.Errorf("failed BootstrapToken to Secret roundtrip with error: %v", err) t.Errorf("failed BootstrapToken to Secret roundtrip with error: %v", err)
@ -103,16 +106,19 @@ func TestBootstrapTokenToSecretRoundtrip(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }
func TestEncodeTokenSecretData(t *testing.T) { func TestEncodeTokenSecretData(t *testing.T) {
var tests = []struct { var tests = []struct {
name string
bt *BootstrapToken bt *BootstrapToken
data map[string][]byte 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"}, Token: &BootstrapTokenString{ID: "abcdef", Secret: "abcdef0123456789"},
}, },
map[string][]byte{ map[string][]byte{
@ -121,7 +127,8 @@ func TestEncodeTokenSecretData(t *testing.T) {
}, },
}, },
{ {
&BootstrapToken{ // adds description "adds description",
&BootstrapToken{
Token: &BootstrapTokenString{ID: "abcdef", Secret: "abcdef0123456789"}, Token: &BootstrapTokenString{ID: "abcdef", Secret: "abcdef0123456789"},
Description: "foo", Description: "foo",
}, },
@ -132,7 +139,8 @@ func TestEncodeTokenSecretData(t *testing.T) {
}, },
}, },
{ {
&BootstrapToken{ // adds ttl "adds ttl",
&BootstrapToken{
Token: &BootstrapTokenString{ID: "abcdef", Secret: "abcdef0123456789"}, Token: &BootstrapTokenString{ID: "abcdef", Secret: "abcdef0123456789"},
TTL: &metav1.Duration{ TTL: &metav1.Duration{
Duration: mustParseDuration("2h", t), 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"}, Token: &BootstrapTokenString{ID: "abcdef", Secret: "abcdef0123456789"},
Expires: &metav1.Time{ Expires: &metav1.Time{
Time: refTime, 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"}, Token: &BootstrapTokenString{ID: "abcdef", Secret: "abcdef0123456789"},
TTL: &metav1.Duration{ TTL: &metav1.Duration{
Duration: mustParseDuration("2h", t), 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"}, Token: &BootstrapTokenString{ID: "abcdef", Secret: "abcdef0123456789"},
Usages: []string{"authentication", "signing"}, 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"}, Token: &BootstrapTokenString{ID: "abcdef", Secret: "abcdef0123456789"},
Groups: []string{"system:bootstrappers", "system:bootstrappers:foo"}, 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"}, Token: &BootstrapTokenString{ID: "abcdef", Secret: "abcdef0123456789"},
Description: "foo", Description: "foo",
TTL: &metav1.Duration{ TTL: &metav1.Duration{
@ -221,6 +234,7 @@ func TestEncodeTokenSecretData(t *testing.T) {
}, },
} }
for _, rt := range tests { for _, rt := range tests {
t.Run(rt.name, func(t *testing.T) {
actual := encodeTokenSecretData(rt.bt, refTime) actual := encodeTokenSecretData(rt.bt, refTime)
if !reflect.DeepEqual(actual, rt.data) { if !reflect.DeepEqual(actual, rt.data) {
t.Errorf( t.Errorf(
@ -229,6 +243,7 @@ func TestEncodeTokenSecretData(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }
@ -242,12 +257,14 @@ func mustParseDuration(durationStr string, t *testing.T) time.Duration {
func TestBootstrapTokenFromSecret(t *testing.T) { func TestBootstrapTokenFromSecret(t *testing.T) {
var tests = []struct { var tests = []struct {
desc string
name string name string
data map[string][]byte data map[string][]byte
bt *BootstrapToken bt *BootstrapToken
expectedError bool expectedError bool
}{ }{
{ // minimum information {
"minimum information",
"bootstrap-token-abcdef", "bootstrap-token-abcdef",
map[string][]byte{ map[string][]byte{
"token-id": []byte("abcdef"), "token-id": []byte("abcdef"),
@ -258,7 +275,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
}, },
false, false,
}, },
{ // invalid token id {
"invalid token id",
"bootstrap-token-abcdef", "bootstrap-token-abcdef",
map[string][]byte{ map[string][]byte{
"token-id": []byte("abcdeF"), "token-id": []byte("abcdeF"),
@ -267,7 +285,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
nil, nil,
true, true,
}, },
{ // invalid secret naming {
"invalid secret naming",
"foo", "foo",
map[string][]byte{ map[string][]byte{
"token-id": []byte("abcdef"), "token-id": []byte("abcdef"),
@ -276,7 +295,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
nil, nil,
true, true,
}, },
{ // invalid token secret {
"invalid token secret",
"bootstrap-token-abcdef", "bootstrap-token-abcdef",
map[string][]byte{ map[string][]byte{
"token-id": []byte("abcdef"), "token-id": []byte("abcdef"),
@ -285,7 +305,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
nil, nil,
true, true,
}, },
{ // adds description {
"adds description",
"bootstrap-token-abcdef", "bootstrap-token-abcdef",
map[string][]byte{ map[string][]byte{
"token-id": []byte("abcdef"), "token-id": []byte("abcdef"),
@ -298,7 +319,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
}, },
false, false,
}, },
{ // adds expiration {
"adds expiration",
"bootstrap-token-abcdef", "bootstrap-token-abcdef",
map[string][]byte{ map[string][]byte{
"token-id": []byte("abcdef"), "token-id": []byte("abcdef"),
@ -313,7 +335,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
}, },
false, false,
}, },
{ // invalid expiration {
"invalid expiration",
"bootstrap-token-abcdef", "bootstrap-token-abcdef",
map[string][]byte{ map[string][]byte{
"token-id": []byte("abcdef"), "token-id": []byte("abcdef"),
@ -323,7 +346,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
nil, nil,
true, true,
}, },
{ // adds usages {
"adds usages",
"bootstrap-token-abcdef", "bootstrap-token-abcdef",
map[string][]byte{ map[string][]byte{
"token-id": []byte("abcdef"), "token-id": []byte("abcdef"),
@ -337,7 +361,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
}, },
false, false,
}, },
{ // should ignore usages that aren't set to true {
"should ignore usages that aren't set to true",
"bootstrap-token-abcdef", "bootstrap-token-abcdef",
map[string][]byte{ map[string][]byte{
"token-id": []byte("abcdef"), "token-id": []byte("abcdef"),
@ -353,7 +378,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
}, },
false, false,
}, },
{ // adds groups {
"adds groups",
"bootstrap-token-abcdef", "bootstrap-token-abcdef",
map[string][]byte{ map[string][]byte{
"token-id": []byte("abcdef"), "token-id": []byte("abcdef"),
@ -366,7 +392,8 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
}, },
false, false,
}, },
{ // all fields set {
"all fields set",
"bootstrap-token-abcdef", "bootstrap-token-abcdef",
map[string][]byte{ map[string][]byte{
"token-id": []byte("abcdef"), "token-id": []byte("abcdef"),
@ -390,6 +417,7 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
}, },
} }
for _, rt := range tests { for _, rt := range tests {
t.Run(rt.desc, func(t *testing.T) {
actual, err := BootstrapTokenFromSecret(&v1.Secret{ actual, err := BootstrapTokenFromSecret(&v1.Secret{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: rt.name, Name: rt.name,
@ -407,7 +435,7 @@ func TestBootstrapTokenFromSecret(t *testing.T) {
} else { } else {
if actual == nil && rt.bt == nil { if actual == nil && rt.bt == nil {
// if both pointers are nil, it's okay, just continue // 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 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) { 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) { func TestGetSecretString(t *testing.T) {
var tests = []struct { var tests = []struct {
name string
secret *v1.Secret secret *v1.Secret
key string key string
expectedVal string expectedVal string
}{ }{
{ {
name: "existing key",
secret: &v1.Secret{ secret: &v1.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Data: map[string][]byte{ Data: map[string][]byte{
@ -443,6 +474,7 @@ func TestGetSecretString(t *testing.T) {
expectedVal: "bar", expectedVal: "bar",
}, },
{ {
name: "non-existing key",
secret: &v1.Secret{ secret: &v1.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Data: map[string][]byte{ Data: map[string][]byte{
@ -453,6 +485,7 @@ func TestGetSecretString(t *testing.T) {
expectedVal: "", expectedVal: "",
}, },
{ {
name: "no data",
secret: &v1.Secret{ secret: &v1.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "foo"}, ObjectMeta: metav1.ObjectMeta{Name: "foo"},
}, },
@ -461,6 +494,7 @@ func TestGetSecretString(t *testing.T) {
}, },
} }
for _, rt := range tests { for _, rt := range tests {
t.Run(rt.name, func(t *testing.T) {
actual := getSecretString(rt.secret, rt.key) actual := getSecretString(rt.secret, rt.key)
if actual != rt.expectedVal { if actual != rt.expectedVal {
t.Errorf( t.Errorf(
@ -469,5 +503,6 @@ func TestGetSecretString(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }

View File

@ -34,6 +34,7 @@ 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 {
t.Run(rt.bts.ID, func(t *testing.T) {
b, err := json.Marshal(rt.bts) b, err := json.Marshal(rt.bts)
if err != nil { if err != nil {
t.Fatalf("json.Marshal returned an unexpected error: %v", err) t.Fatalf("json.Marshal returned an unexpected error: %v", err)
@ -45,6 +46,7 @@ func TestMarshalJSON(t *testing.T) {
string(b), string(b),
) )
} }
})
} }
} }
@ -64,6 +66,7 @@ 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 {
t.Run(rt.input, func(t *testing.T) {
newbts := &BootstrapTokenString{} newbts := &BootstrapTokenString{}
err := json.Unmarshal([]byte(rt.input), newbts) err := json.Unmarshal([]byte(rt.input), newbts)
if (err != nil) != rt.expectedError { if (err != nil) != rt.expectedError {
@ -75,6 +78,7 @@ func TestUnmarshalJSON(t *testing.T) {
newbts, newbts,
) )
} }
})
} }
} }
@ -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 {
t.Run(rt.input, func(t *testing.T) {
if err := roundtrip(rt.input, rt.bts); err != nil { if err := roundtrip(rt.input, rt.bts); err != nil {
t.Errorf("failed BootstrapTokenString JSON roundtrip with error: %v", err) 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"}, {BootstrapTokenString{ID: "h", Secret: "b"}, "h.b"},
} }
for _, rt := range tests { for _, rt := range tests {
t.Run(rt.bts.ID, func(t *testing.T) {
actual := rt.bts.String() actual := rt.bts.String()
if actual != rt.expected { if actual != rt.expected {
t.Errorf( t.Errorf(
@ -148,6 +155,7 @@ func TestTokenFromIDAndSecret(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }
@ -175,6 +183,7 @@ 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 {
t.Run(rt.token, func(t *testing.T) {
actual, err := NewBootstrapTokenString(rt.token) actual, err := NewBootstrapTokenString(rt.token)
if (err != nil) != rt.expectedError { if (err != nil) != rt.expectedError {
t.Errorf( t.Errorf(
@ -191,6 +200,7 @@ func TestNewBootstrapTokenString(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }
@ -215,6 +225,7 @@ 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 {
t.Run(rt.id, func(t *testing.T) {
actual, err := NewBootstrapTokenStringFromIDAndSecret(rt.id, rt.secret) actual, err := NewBootstrapTokenStringFromIDAndSecret(rt.id, rt.secret)
if (err != nil) != rt.expectedError { if (err != nil) != rt.expectedError {
t.Errorf( t.Errorf(
@ -233,5 +244,6 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }

View File

@ -34,6 +34,7 @@ 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 {
t.Run(rt.bts.ID, func(t *testing.T) {
b, err := json.Marshal(rt.bts) b, err := json.Marshal(rt.bts)
if err != nil { if err != nil {
t.Fatalf("json.Marshal returned an unexpected error: %v", err) t.Fatalf("json.Marshal returned an unexpected error: %v", err)
@ -45,6 +46,7 @@ func TestMarshalJSON(t *testing.T) {
string(b), string(b),
) )
} }
})
} }
} }
@ -64,6 +66,7 @@ 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 {
t.Run(rt.input, func(t *testing.T) {
newbts := &BootstrapTokenString{} newbts := &BootstrapTokenString{}
err := json.Unmarshal([]byte(rt.input), newbts) err := json.Unmarshal([]byte(rt.input), newbts)
if (err != nil) != rt.expectedError { if (err != nil) != rt.expectedError {
@ -75,6 +78,7 @@ func TestUnmarshalJSON(t *testing.T) {
newbts, newbts,
) )
} }
})
} }
} }
@ -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 {
t.Run(rt.input, func(t *testing.T) {
if err := roundtrip(rt.input, rt.bts); err != nil { if err := roundtrip(rt.input, rt.bts); err != nil {
t.Errorf("failed BootstrapTokenString JSON roundtrip with error: %v", err) 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"}, {BootstrapTokenString{ID: "h", Secret: "b"}, "h.b"},
} }
for _, rt := range tests { for _, rt := range tests {
t.Run(rt.bts.ID, func(t *testing.T) {
actual := rt.bts.String() actual := rt.bts.String()
if actual != rt.expected { if actual != rt.expected {
t.Errorf( t.Errorf(
@ -148,6 +155,7 @@ func TestTokenFromIDAndSecret(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }
@ -175,6 +183,7 @@ 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 {
t.Run(rt.token, func(t *testing.T) {
actual, err := NewBootstrapTokenString(rt.token) actual, err := NewBootstrapTokenString(rt.token)
if (err != nil) != rt.expectedError { if (err != nil) != rt.expectedError {
t.Errorf( t.Errorf(
@ -191,6 +200,7 @@ func TestNewBootstrapTokenString(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }
@ -215,6 +225,7 @@ 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 {
t.Run(rt.id, func(t *testing.T) {
actual, err := NewBootstrapTokenStringFromIDAndSecret(rt.id, rt.secret) actual, err := NewBootstrapTokenStringFromIDAndSecret(rt.id, rt.secret)
if (err != nil) != rt.expectedError { if (err != nil) != rt.expectedError {
t.Errorf( t.Errorf(
@ -233,5 +244,6 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }

View File

@ -46,13 +46,15 @@ func TestJoinConfigurationConversion(t *testing.T) {
expectedError: true, expectedError: true,
}, },
} }
for _, tc := range testcases { for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
internal := &kubeadm.JoinConfiguration{} internal := &kubeadm.JoinConfiguration{}
err := Convert_v1alpha3_JoinConfiguration_To_kubeadm_JoinConfiguration(tc.old, internal, nil) err := Convert_v1alpha3_JoinConfiguration_To_kubeadm_JoinConfiguration(tc.old, internal, nil)
if (err != nil) != tc.expectedError { if (err != nil) != tc.expectedError {
t.Errorf("ImageToImageMeta returned unexpected error: %v, saw: %v", tc.expectedError, (err != nil)) t.Errorf("ImageToImageMeta returned unexpected error: %v, saw: %v", tc.expectedError, (err != nil))
return return
} }
})
} }
} }
@ -76,12 +78,14 @@ func TestInitConfigurationConversion(t *testing.T) {
expectedErr: true, expectedErr: true,
}, },
} }
for _, tc := range testcases { for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
internal := &kubeadm.InitConfiguration{} internal := &kubeadm.InitConfiguration{}
err := Convert_v1alpha3_InitConfiguration_To_kubeadm_InitConfiguration(tc.old, internal, nil) err := Convert_v1alpha3_InitConfiguration_To_kubeadm_InitConfiguration(tc.old, internal, nil)
if (err != nil) != tc.expectedErr { if (err != nil) != tc.expectedErr {
t.Errorf("no error was expected but '%s' was found", err) t.Errorf("no error was expected but '%s' was found", err)
} }
})
} }
} }

View File

@ -34,6 +34,7 @@ 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 {
t.Run(rt.bts.ID, func(t *testing.T) {
b, err := json.Marshal(rt.bts) b, err := json.Marshal(rt.bts)
if err != nil { if err != nil {
t.Fatalf("json.Marshal returned an unexpected error: %v", err) t.Fatalf("json.Marshal returned an unexpected error: %v", err)
@ -45,6 +46,7 @@ func TestMarshalJSON(t *testing.T) {
string(b), string(b),
) )
} }
})
} }
} }
@ -64,6 +66,7 @@ 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 {
t.Run(rt.input, func(t *testing.T) {
newbts := &BootstrapTokenString{} newbts := &BootstrapTokenString{}
err := json.Unmarshal([]byte(rt.input), newbts) err := json.Unmarshal([]byte(rt.input), newbts)
if (err != nil) != rt.expectedError { if (err != nil) != rt.expectedError {
@ -75,6 +78,7 @@ func TestUnmarshalJSON(t *testing.T) {
newbts, newbts,
) )
} }
})
} }
} }
@ -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 {
t.Run(rt.input, func(t *testing.T) {
if err := roundtrip(rt.input, rt.bts); err != nil { if err := roundtrip(rt.input, rt.bts); err != nil {
t.Errorf("failed BootstrapTokenString JSON roundtrip with error: %v", err) 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"}, {BootstrapTokenString{ID: "h", Secret: "b"}, "h.b"},
} }
for _, rt := range tests { for _, rt := range tests {
t.Run(rt.bts.ID, func(t *testing.T) {
actual := rt.bts.String() actual := rt.bts.String()
if actual != rt.expected { if actual != rt.expected {
t.Errorf( t.Errorf(
@ -148,6 +155,7 @@ func TestTokenFromIDAndSecret(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }
@ -175,6 +183,7 @@ 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 {
t.Run(rt.token, func(t *testing.T) {
actual, err := NewBootstrapTokenString(rt.token) actual, err := NewBootstrapTokenString(rt.token)
if (err != nil) != rt.expectedError { if (err != nil) != rt.expectedError {
t.Errorf( t.Errorf(
@ -191,6 +200,7 @@ func TestNewBootstrapTokenString(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }
@ -215,6 +225,7 @@ 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 {
t.Run(rt.id, func(t *testing.T) {
actual, err := NewBootstrapTokenStringFromIDAndSecret(rt.id, rt.secret) actual, err := NewBootstrapTokenStringFromIDAndSecret(rt.id, rt.secret)
if (err != nil) != rt.expectedError { if (err != nil) != rt.expectedError {
t.Errorf( t.Errorf(
@ -233,5 +244,6 @@ func TestNewBootstrapTokenStringFromIDAndSecret(t *testing.T) {
actual, actual,
) )
} }
})
} }
} }