Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* split bats test invocation by executable * add more cli tests for kubens * clean up kubens tests * small cleanup to kubens tests
- Loading branch information
1 parent
df557e4
commit 402cc2c
Showing
5 changed files
with
124 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,15 +1,104 @@ | |||
#!/usr/bin/env bats | #!/usr/bin/env bats | ||
|
|
||
COMMAND="${BATS_TEST_DIRNAME}/../kubens" | COMMAND="${BATS_TEST_DIRNAME}/../kubens" | ||
export KUBECTL="$BATS_TEST_DIRNAME/../test/mock-kubectl" | |||
|
|||
load common | |||
|
|
||
@test "--help should not fail" { | @test "--help should not fail" { | ||
run ${COMMAND} --help | run ${COMMAND} --help | ||
echo "$output">&2 | echo "$output">&2 | ||
[ "$status" -eq 0 ] | [[ "$status" -eq 0 ]] | ||
} | } | ||
|
|
||
@test "-h should not fail" { | @test "-h should not fail" { | ||
run ${COMMAND} -h | run ${COMMAND} -h | ||
echo "$output">&2 | echo "$output">&2 | ||
[ "$status" -eq 0 ] | [[ "$status" -eq 0 ]] | ||
} | |||
|
|||
@test "list namespaces when no kubeconfig exists" { | |||
run ${COMMAND} | |||
echo "$output" | |||
[[ "$status" -eq 1 ]] | |||
[[ "$output" = *"current-context is not set"* ]] | |||
} | |||
|
|||
@test "list namespaces" { | |||
use_config config1 | |||
switch_context user1@cluster1 | |||
|
|||
run ${COMMAND} | |||
echo "$output" | |||
[[ "$status" -eq 0 ]] | |||
[[ "$output" = *"ns1"* ]] | |||
[[ "$output" = *"ns2"* ]] | |||
} | |||
|
|||
@test "switch to existing namespace" { | |||
use_config config1 | |||
switch_context user1@cluster1 | |||
|
|||
run ${COMMAND} "ns1" | |||
echo "$output" | |||
[[ "$status" -eq 0 ]] | |||
[[ "$output" = *'Active namespace is "ns1"'* ]] | |||
} | |||
|
|||
@test "switch to non-existing namespace" { | |||
use_config config1 | |||
switch_context user1@cluster1 | |||
|
|||
run ${COMMAND} "unknown-namespace" | |||
echo "$output" | |||
[[ "$status" -eq 1 ]] | |||
[[ "$output" = *'no namespace exists with name "unknown-namespace"'* ]] | |||
} | |||
|
|||
@test "switch between namespaces" { | |||
use_config config1 | |||
switch_context user1@cluster1 | |||
|
|||
run ${COMMAND} ns1 | |||
echo "$output" | |||
[[ "$status" -eq 0 ]] | |||
echo "$(get_namespace)" | |||
[[ "$(get_namespace)" = "ns1" ]] | |||
|
|||
run ${COMMAND} ns2 | |||
echo "$output" | |||
[[ "$status" -eq 0 ]] | |||
echo "$(get_namespace)" | |||
[[ "$(get_namespace)" = "ns2" ]] | |||
|
|||
run ${COMMAND} - | |||
echo "$output" | |||
[[ "$status" -eq 0 ]] | |||
echo "$(get_namespace)" | |||
[[ "$(get_namespace)" = "ns1" ]] | |||
|
|||
run ${COMMAND} - | |||
echo "$output" | |||
[[ "$status" -eq 0 ]] | |||
echo "$(get_namespace)" | |||
[[ "$(get_namespace)" = "ns2" ]] | |||
} | |||
|
|||
@test "switch to previous namespace when none exists" { | |||
use_config config1 | |||
switch_context user1@cluster1 | |||
|
|||
run ${COMMAND} - | |||
echo "$output" | |||
[[ "$status" -eq 1 ]] | |||
[[ "$output" = *"No previous namespace found for current context"* ]] | |||
} | |||
|
|||
@test "switch to namespace when current context is empty" { | |||
use_config config1 | |||
|
|||
run ${COMMAND} - | |||
echo "$output" | |||
[[ "$status" -eq 1 ]] | |||
[[ "$output" = *"current-context is not set"* ]] | |||
} | } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
#!/usr/bin/env bash | |||
|
|||
[[ -n $DEBUG ]] && set -x | |||
|
|||
set -eou pipefail | |||
|
|||
if [[ $@ == *'get namespaces'* ]]; then | |||
echo "ns1" | |||
echo "ns2" | |||
else | |||
kubectl $@ | |||
fi |