Skip to content

Commit

Permalink
Merge pull request kubernetes#72366 from bart0sh/PR0047-kubeadm-test-…
Browse files Browse the repository at this point in the history
…cmd-use-T.Run

kubeadm: use T.Run API in test/cmd
  • Loading branch information
k8s-ci-robot authored Dec 27, 2018
2 parents bb7973a + 6391012 commit 36049ef
Showing 4 changed files with 219 additions and 183 deletions.
27 changes: 15 additions & 12 deletions cmd/kubeadm/test/cmd/completion_test.go
Original file line number Diff line number Diff line change
@@ -27,23 +27,26 @@ 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 {
_, _, actual := RunCmd(kubeadmPath, "completion", rt.args)
if (actual == nil) != rt.expected {
t.Errorf(
"failed CmdCompletion running 'kubeadm completion %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
t.Run(rt.name, func(t *testing.T) {
_, _, actual := RunCmd(kubeadmPath, "completion", rt.args)
if (actual == nil) != rt.expected {
t.Errorf(
"failed CmdCompletion running 'kubeadm completion %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
})
}
}
228 changes: 126 additions & 102 deletions cmd/kubeadm/test/cmd/join_test.go
Original file line number Diff line number Diff line change
@@ -32,26 +32,29 @@ 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 {
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
if (actual == nil) != rt.expected {
t.Errorf(
"failed CmdJoinConfig running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
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(
"failed CmdJoinConfig running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
})
}
}

@@ -62,26 +65,29 @@ 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 {
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
if (actual == nil) != rt.expected {
t.Errorf(
"failed CmdJoinDiscoveryFile running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
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(
"failed CmdJoinDiscoveryFile running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
})
}
}

@@ -92,26 +98,29 @@ 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 {
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
if (actual == nil) != rt.expected {
t.Errorf(
"failed CmdJoinDiscoveryToken running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
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(
"failed CmdJoinDiscoveryToken running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
})
}
}

@@ -122,25 +131,28 @@ 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 {
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
if (actual == nil) != rt.expected {
t.Errorf(
"failed CmdJoinNodeName running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
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(
"failed CmdJoinNodeName running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
})
}
}

@@ -151,26 +163,29 @@ 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 {
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
if (actual == nil) != rt.expected {
t.Errorf(
"failed CmdJoinTLSBootstrapToken running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
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(
"failed CmdJoinTLSBootstrapToken running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
})
}
}

@@ -181,26 +196,29 @@ 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 {
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
if (actual == nil) != rt.expected {
t.Errorf(
"failed CmdJoinToken running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
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(
"failed CmdJoinToken running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
})
}
}

@@ -212,25 +230,28 @@ 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 {
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
if (actual == nil) != rt.expected {
t.Errorf(
"failed CmdJoinBadArgs 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
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(
"failed CmdJoinBadArgs 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
})
}
}

@@ -241,24 +262,27 @@ 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 {
_, _, actual := RunCmd(kubeadmPath, "join", rt.args, "--ignore-preflight-errors=all")
if (actual == nil) != rt.expected {
t.Errorf(
"failed CmdJoinArgsMixed running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
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(
"failed CmdJoinArgsMixed running 'kubeadm join %s' with an error: %v\n\texpected: %t\n\t actual: %t",
rt.args,
actual,
rt.expected,
(actual == nil),
)
}
kubeadmReset()
})
}
}
Loading

0 comments on commit 36049ef

Please sign in to comment.