Skip to content

Commit

Permalink
Merge pull request kubernetes#44628 from dmmcquay/kubeadm_join_tests
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 42432, 44628, 45101, 44921)

kubeadm: join test cmds for new flags

**What this PR does / why we need it**: Adding test-cmds for new kubeadm join flags. 

Adding tests is a WIP from kubernetes#34136

This is a continuation from kubernetes#42812 since it had to be closed.

**Special notes for your reviewer**: /cc @luxas 

**Release note**:
```release-note
NONE
```
  • Loading branch information
Kubernetes Submit Queue committed Apr 28, 2017
2 parents 021f542 + 9daa13a commit 228219b
Showing 1 changed file with 145 additions and 0 deletions.
145 changes: 145 additions & 0 deletions cmd/kubeadm/test/cmd/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,148 @@ func TestCmdJoinConfig(t *testing.T) {
kubeadmReset()
}
}

func TestCmdJoinDiscoveryFile(t *testing.T) {
if *kubeadmCmdSkip {
t.Log("kubeadm cmd tests being skipped")
t.Skip()
}

var initTest = []struct {
args string
expected bool
}{
{"--discovery-file=foobar", false},
{"--discovery-file=file:wrong", false},
}

for _, rt := range initTest {
_, _, actual := RunCmd(*kubeadmPath, "join", rt.args, "--skip-preflight-checks")
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()
}
}

func TestCmdJoinDiscoveryToken(t *testing.T) {
if *kubeadmCmdSkip {
t.Log("kubeadm cmd tests being skipped")
t.Skip()
}

var initTest = []struct {
args string
expected bool
}{
{"--discovery-token=foobar", false},
{"--discovery-token=token://asdf:asdf", false},
}

for _, rt := range initTest {
_, _, actual := RunCmd(*kubeadmPath, "join", rt.args, "--skip-preflight-checks")
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()
}
}

func TestCmdJoinTLSBootstrapToken(t *testing.T) {
if *kubeadmCmdSkip {
t.Log("kubeadm cmd tests being skipped")
t.Skip()
}

var initTest = []struct {
args string
expected bool
}{
{"--tls-bootstrap-token=foobar", false},
{"--tls-bootstrap-token=token://asdf:asdf", false},
}

for _, rt := range initTest {
_, _, actual := RunCmd(*kubeadmPath, "join", rt.args, "--skip-preflight-checks")
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()
}
}

func TestCmdJoinToken(t *testing.T) {
if *kubeadmCmdSkip {
t.Log("kubeadm cmd tests being skipped")
t.Skip()
}

var initTest = []struct {
args string
expected bool
}{
{"--token=foobar", false},
{"--token=token://asdf:asdf", false},
}

for _, rt := range initTest {
_, _, actual := RunCmd(*kubeadmPath, "join", rt.args, "--skip-preflight-checks")
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()
}
}

func TestCmdJoinBadArgs(t *testing.T) {
if *kubeadmCmdSkip {
t.Log("kubeadm cmd tests being skipped")
t.Skip()
}

var initTest = []struct {
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
}

for _, rt := range initTest {
_, _, actual := RunCmd(*kubeadmPath, "join", rt.args, "--skip-preflight-checks")
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()
}
}

0 comments on commit 228219b

Please sign in to comment.