mirror of https://github.com/k3s-io/k3s
Merge pull request #72366 from bart0sh/PR0047-kubeadm-test-cmd-use-T.Run
kubeadm: use T.Run API in test/cmdpull/564/head
commit
36049ef914
|
@ -27,14 +27,16 @@ func TestCmdCompletion(t *testing.T) {
|
|||
}
|
||||
|
||||
var tests = []struct {
|
||||
name string
|
||||
args string
|
||||
expected bool
|
||||
}{
|
||||
{"", false}, // shell not specified
|
||||
{"foo", false}, // unsupported shell type
|
||||
{"shell not expected", "", false},
|
||||
{"unsupported shell type", "foo", false},
|
||||
}
|
||||
|
||||
for _, rt := range tests {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
_, _, actual := RunCmd(kubeadmPath, "completion", rt.args)
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
|
@ -45,5 +47,6 @@ func TestCmdCompletion(t *testing.T) {
|
|||
(actual == nil),
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,15 +32,17 @@ func TestCmdJoinConfig(t *testing.T) {
|
|||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
expected bool
|
||||
}{
|
||||
{"--config=foobar", false},
|
||||
{"--config=/does/not/exist/foo/bar", false},
|
||||
{"config", "--config=foobar", false},
|
||||
{"config path", "--config=/does/not/exist/foo/bar", false},
|
||||
}
|
||||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
for _, rt := range initTest {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
|
@ -52,6 +54,7 @@ func TestCmdJoinConfig(t *testing.T) {
|
|||
)
|
||||
}
|
||||
kubeadmReset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,15 +65,17 @@ func TestCmdJoinDiscoveryFile(t *testing.T) {
|
|||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
expected bool
|
||||
}{
|
||||
{"--discovery-file=foobar", false},
|
||||
{"--discovery-file=file:wrong", false},
|
||||
{"valid discovery file", "--discovery-file=foobar", false},
|
||||
{"invalid discovery file", "--discovery-file=file:wrong", false},
|
||||
}
|
||||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
for _, rt := range initTest {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
|
@ -82,6 +87,7 @@ func TestCmdJoinDiscoveryFile(t *testing.T) {
|
|||
)
|
||||
}
|
||||
kubeadmReset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,15 +98,17 @@ func TestCmdJoinDiscoveryToken(t *testing.T) {
|
|||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
expected bool
|
||||
}{
|
||||
{"--discovery-token=foobar", false},
|
||||
{"--discovery-token=token://asdf:asdf", false},
|
||||
{"valid discovery token", "--discovery-token=foobar", false},
|
||||
{"valid discovery token url", "--discovery-token=token://asdf:asdf", false},
|
||||
}
|
||||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
for _, rt := range initTest {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
|
@ -112,6 +120,7 @@ func TestCmdJoinDiscoveryToken(t *testing.T) {
|
|||
)
|
||||
}
|
||||
kubeadmReset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,14 +131,16 @@ func TestCmdJoinNodeName(t *testing.T) {
|
|||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
expected bool
|
||||
}{
|
||||
{"--node-name=foobar", false},
|
||||
{"valid node name", "--node-name=foobar", false},
|
||||
}
|
||||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
for _, rt := range initTest {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
|
@ -141,6 +152,7 @@ func TestCmdJoinNodeName(t *testing.T) {
|
|||
)
|
||||
}
|
||||
kubeadmReset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,15 +163,17 @@ func TestCmdJoinTLSBootstrapToken(t *testing.T) {
|
|||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
expected bool
|
||||
}{
|
||||
{"--tls-bootstrap-token=foobar", false},
|
||||
{"--tls-bootstrap-token=token://asdf:asdf", false},
|
||||
{"valid bootstrap token", "--tls-bootstrap-token=foobar", false},
|
||||
{"valid bootstrap token url", "--tls-bootstrap-token=token://asdf:asdf", false},
|
||||
}
|
||||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
for _, rt := range initTest {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
|
@ -171,6 +185,7 @@ func TestCmdJoinTLSBootstrapToken(t *testing.T) {
|
|||
)
|
||||
}
|
||||
kubeadmReset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,15 +196,17 @@ func TestCmdJoinToken(t *testing.T) {
|
|||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
expected bool
|
||||
}{
|
||||
{"--token=foobar", false},
|
||||
{"--token=token://asdf:asdf", false},
|
||||
{"valid token", "--token=foobar", false},
|
||||
{"valid token url", "--token=token://asdf:asdf", false},
|
||||
}
|
||||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
for _, rt := range initTest {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
|
@ -201,6 +218,7 @@ func TestCmdJoinToken(t *testing.T) {
|
|||
)
|
||||
}
|
||||
kubeadmReset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,14 +230,16 @@ func TestCmdJoinBadArgs(t *testing.T) {
|
|||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
expected bool
|
||||
}{
|
||||
{"--discovery-token=abcdef.1234567890123456 --discovery-file=file:///tmp/foo.bar", false}, // DiscoveryToken, DiscoveryFile can't both be set
|
||||
{"", false}, // DiscoveryToken or DiscoveryFile must be set
|
||||
{"discovery-token and discovery-file can't both be set", "--discovery-token=abcdef.1234567890123456 --discovery-file=file:///tmp/foo.bar", false}, // DiscoveryToken, DiscoveryFile can't both be set
|
||||
{"discovery-token or discovery-file must be set", "", false}, // DiscoveryToken or DiscoveryFile must be set
|
||||
}
|
||||
|
||||
for _, rt := range initTest {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
|
@ -231,6 +251,7 @@ func TestCmdJoinBadArgs(t *testing.T) {
|
|||
)
|
||||
}
|
||||
kubeadmReset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,14 +262,16 @@ func TestCmdJoinArgsMixed(t *testing.T) {
|
|||
}
|
||||
|
||||
var initTest = []struct {
|
||||
name string
|
||||
args string
|
||||
expected bool
|
||||
}{
|
||||
{"--discovery-token=abcdef.1234567890abcdef --config=/etc/kubernetes/kubeadm.config", false},
|
||||
{"discovery-token and config", "--discovery-token=abcdef.1234567890abcdef --config=/etc/kubernetes/kubeadm.config", false},
|
||||
}
|
||||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
for _, rt := range initTest {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
|
@ -260,5 +283,6 @@ func TestCmdJoinArgsMixed(t *testing.T) {
|
|||
)
|
||||
}
|
||||
kubeadmReset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,15 +90,17 @@ func TestCmdTokenDelete(t *testing.T) {
|
|||
}
|
||||
|
||||
var tests = []struct {
|
||||
name string
|
||||
args string
|
||||
expected bool
|
||||
}{
|
||||
{"", false}, // no token provided
|
||||
{"foobar", false}, // invalid token
|
||||
{"no token provided", "", false},
|
||||
{"invalid token", "foobar", false},
|
||||
}
|
||||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
for _, rt := range tests {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
_, _, actual := RunCmd(kubeadmPath, "token", "delete", rt.args)
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
|
@ -110,5 +112,6 @@ func TestCmdTokenDelete(t *testing.T) {
|
|||
)
|
||||
}
|
||||
kubeadmReset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,17 +40,19 @@ func TestCmdVersion(t *testing.T) {
|
|||
}
|
||||
|
||||
var versionTest = []struct {
|
||||
name string
|
||||
args string
|
||||
regex string
|
||||
expected bool
|
||||
}{
|
||||
{"--output=valid", "", false},
|
||||
{"--output=short", ShortExpectedRegex, true},
|
||||
{"", NormalExpectedRegex, true},
|
||||
{"invalid output option", "--output=valid", "", false},
|
||||
{"short output", "--output=short", ShortExpectedRegex, true},
|
||||
{"default output", "", NormalExpectedRegex, true},
|
||||
}
|
||||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
for _, rt := range versionTest {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
stdout, _, actual := RunCmd(kubeadmPath, "version", rt.args)
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
|
@ -71,6 +73,7 @@ func TestCmdVersion(t *testing.T) {
|
|||
t.Errorf("'kubeadm version %s' stdout did not match expected regex; wanted: [%q], got: [%s]", rt.args, rt.regex, stdout)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,16 +84,18 @@ func TestCmdVersionOutputJsonOrYaml(t *testing.T) {
|
|||
}
|
||||
|
||||
var versionTest = []struct {
|
||||
name string
|
||||
args string
|
||||
format string
|
||||
expected bool
|
||||
}{
|
||||
{"--output=json", "json", true},
|
||||
{"--output=yaml", "yaml", true},
|
||||
{"json output", "--output=json", "json", true},
|
||||
{"yaml output", "--output=yaml", "yaml", true},
|
||||
}
|
||||
|
||||
kubeadmPath := getKubeadmPath()
|
||||
for _, rt := range versionTest {
|
||||
t.Run(rt.name, func(t *testing.T) {
|
||||
stdout, _, actual := RunCmd(kubeadmPath, "version", rt.args)
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
|
@ -128,5 +133,6 @@ func TestCmdVersionOutputJsonOrYaml(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue