Skip to content

Commit eff6105

Browse files
authored
Merge pull request kubernetes#91397 from prasadkatti/add_cri_socket_path_tests
Add cri socket path tests
2 parents aba339c + b5c08ca commit eff6105

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

cmd/kubeadm/app/apis/kubeadm/validation/validation_test.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,17 @@ func TestValidateTokenGroups(t *testing.T) {
9999
func TestValidateNodeRegistrationOptions(t *testing.T) {
100100
var tests = []struct {
101101
nodeName string
102-
criSocket string
103102
expectedErrors bool
104103
}{
105-
{"", "/some/path", true}, // node name can't be empty
106-
{"INVALID-NODENAME", "/some/path", true}, // Upper cases is invalid
107-
{"invalid-nodename-", "/some/path", true}, // Can't have trailing dashes
108-
{"invalid-node?name", "/some/path", true}, // Unsupported characters
109-
{"valid-nodename", "/some/path", false}, // supported
110-
{"valid-nodename-with-numbers01234", "/some/path/with/numbers/01234/", false}, // supported, with numbers as well
111-
{"valid-nodename", kubeadmapiv1beta2.DefaultUrlScheme + "://" + "/some/path", false}, // supported, with socket url
112-
{"valid-nodename", "bla:///some/path", true}, // unsupported url scheme
113-
{"valid-nodename", ":::", true}, // unparseable url
104+
{"", true}, // node name can't be empty
105+
{"INVALID-NODENAME", true}, // Upper cases is invalid
106+
{"invalid-nodename-", true}, // Can't have trailing dashes
107+
{"invalid-node?name", true}, // Unsupported characters
108+
{"valid-nodename", false}, // supported
109+
// test cases for criSocket are covered in TestValidateSocketPath
114110
}
115111
for _, rt := range tests {
116-
nro := kubeadm.NodeRegistrationOptions{Name: rt.nodeName, CRISocket: rt.criSocket}
112+
nro := kubeadm.NodeRegistrationOptions{Name: rt.nodeName, CRISocket: "/some/path"}
117113
actual := ValidateNodeRegistrationOptions(&nro, field.NewPath("nodeRegistration"))
118114
actualErrors := len(actual) > 0
119115
if actualErrors != rt.expectedErrors {
@@ -896,3 +892,25 @@ func TestValidateDiscoveryKubeConfigPath(t *testing.T) {
896892
}
897893
}
898894
}
895+
896+
func TestValidateSocketPath(t *testing.T) {
897+
var tests = []struct {
898+
name string
899+
criSocket string
900+
expectedErrors bool
901+
}{
902+
{name: "valid path", criSocket: "/some/path", expectedErrors: false},
903+
{name: "valid socket url", criSocket: kubeadmapiv1beta2.DefaultUrlScheme + "://" + "/some/path", expectedErrors: false},
904+
{name: "unsupported url scheme", criSocket: "bla:///some/path", expectedErrors: true},
905+
{name: "unparseable url", criSocket: ":::", expectedErrors: true},
906+
{name: "invalid CRISocket (path is not absolute)", criSocket: "some/path", expectedErrors: true},
907+
{name: "empty CRISocket (path is not absolute)", criSocket: "", expectedErrors: true},
908+
}
909+
for _, tc := range tests {
910+
actual := ValidateSocketPath(tc.criSocket, field.NewPath("criSocket"))
911+
actualErrors := len(actual) > 0
912+
if actualErrors != tc.expectedErrors {
913+
t.Errorf("error: socket path: %q\n\texpected: %t\n\t actual: %t", tc.criSocket, tc.expectedErrors, actualErrors)
914+
}
915+
}
916+
}

0 commit comments

Comments
 (0)