mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
Add tests for ValidateSocketPath
This commit is contained in:
parent
a1ac30db40
commit
b5c08caa34
@ -99,22 +99,17 @@ func TestValidateTokenGroups(t *testing.T) {
|
||||
func TestValidateNodeRegistrationOptions(t *testing.T) {
|
||||
var tests = []struct {
|
||||
nodeName string
|
||||
criSocket string
|
||||
expectedErrors bool
|
||||
}{
|
||||
{"", "/some/path", true}, // node name can't be empty
|
||||
{"INVALID-NODENAME", "/some/path", true}, // Upper cases is invalid
|
||||
{"invalid-nodename-", "/some/path", true}, // Can't have trailing dashes
|
||||
{"invalid-node?name", "/some/path", true}, // Unsupported characters
|
||||
{"valid-nodename", "/some/path", false}, // supported
|
||||
{"valid-nodename-with-numbers01234", "/some/path/with/numbers/01234/", false}, // supported, with numbers as well
|
||||
{"valid-nodename", kubeadmapiv1beta2.DefaultUrlScheme + "://" + "/some/path", false}, // supported, with socket url
|
||||
{"valid-nodename", "bla:///some/path", true}, // unsupported url scheme
|
||||
{"valid-nodename", ":::", true}, // unparseable url
|
||||
{"valid-nodename", "", true}, // invalid CRISocket (path is not absolute)
|
||||
{"", true}, // node name can't be empty
|
||||
{"INVALID-NODENAME", true}, // Upper cases is invalid
|
||||
{"invalid-nodename-", true}, // Can't have trailing dashes
|
||||
{"invalid-node?name", true}, // Unsupported characters
|
||||
{"valid-nodename", false}, // supported
|
||||
// test cases for criSocket are covered in TestValidateSocketPath
|
||||
}
|
||||
for _, rt := range tests {
|
||||
nro := kubeadm.NodeRegistrationOptions{Name: rt.nodeName, CRISocket: rt.criSocket}
|
||||
nro := kubeadm.NodeRegistrationOptions{Name: rt.nodeName, CRISocket: "/some/path"}
|
||||
actual := ValidateNodeRegistrationOptions(&nro, field.NewPath("nodeRegistration"))
|
||||
actualErrors := len(actual) > 0
|
||||
if actualErrors != rt.expectedErrors {
|
||||
@ -897,3 +892,25 @@ func TestValidateDiscoveryKubeConfigPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateSocketPath(t *testing.T) {
|
||||
var tests = []struct {
|
||||
name string
|
||||
criSocket string
|
||||
expectedErrors bool
|
||||
}{
|
||||
{name: "valid path", criSocket: "/some/path", expectedErrors: false},
|
||||
{name: "valid socket url", criSocket: kubeadmapiv1beta2.DefaultUrlScheme + "://" + "/some/path", expectedErrors: false},
|
||||
{name: "unsupported url scheme", criSocket: "bla:///some/path", expectedErrors: true},
|
||||
{name: "unparseable url", criSocket: ":::", expectedErrors: true},
|
||||
{name: "invalid CRISocket (path is not absolute)", criSocket: "some/path", expectedErrors: true},
|
||||
{name: "empty CRISocket (path is not absolute)", criSocket: "", expectedErrors: true},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
actual := ValidateSocketPath(tc.criSocket, field.NewPath("criSocket"))
|
||||
actualErrors := len(actual) > 0
|
||||
if actualErrors != tc.expectedErrors {
|
||||
t.Errorf("error: socket path: %q\n\texpected: %t\n\t actual: %t", tc.criSocket, tc.expectedErrors, actualErrors)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user