Validate usage strings when creating bootstrap tokens via kubeadm

This commit is contained in:
wackxu
2017-10-14 20:44:57 +08:00
parent 338ee7f5d5
commit 0e1a74731d
6 changed files with 70 additions and 7 deletions

View File

@@ -50,3 +50,27 @@ func TestValidateBootstrapGroupName(t *testing.T) {
}
}
}
func TestValidateUsages(t *testing.T) {
tests := []struct {
name string
input []string
valid bool
}{
{"valid of signing", []string{"signing"}, true},
{"valid of authentication", []string{"authentication"}, true},
{"all valid", []string{"authentication", "signing"}, true},
{"single invalid", []string{"authentication", "foo"}, false},
{"all invalid", []string{"foo", "bar"}, false},
}
for _, test := range tests {
err := ValidateUsages(test.input)
if err != nil && test.valid {
t.Errorf("test %q: ValidateUsages(%v) returned unexpected error: %v", test.name, test.input, err)
}
if err == nil && !test.valid {
t.Errorf("test %q: ValidateUsages(%v) was supposed to return an error but didn't", test.name, test.input)
}
}
}