-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add symbol color option and testing framework
- Loading branch information
Showing
5 changed files
with
127 additions
and
5 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bats | ||
|
||
load '../../../node_modules/bats-support/load' | ||
load '../../../node_modules/bats-assert/load' | ||
|
||
setup() { | ||
source "${BATS_TEST_DIRNAME}/../kube-ps1.sh" >/dev/null 2>/dev/null | ||
export _KUBE_PS1_DISABLE_PATH="/tmp/kube_ps1_disable" | ||
export KUBECONFIG="/tmp/kubeconfig" | ||
mkdir -p /tmp/kube-ps1 | ||
touch /tmp/kubeconfig | ||
} | ||
|
||
teardown() { | ||
unset _KUBE_PS1_DISABLE_PATH | ||
unset KUBECONFIG | ||
unset KUBE_PS1_ENABLED | ||
unset KUBE_PS1_CONTEXT | ||
unset KUBE_PS1_NAMESPACE | ||
unset KUBE_PS1_SYBBOL_COLOR | ||
rm -rf /tmp/kube-ps1 | ||
rm -f /tmp/kubeconfig | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env bats | ||
|
||
source "${BATS_TEST_DIRNAME}/../kube-ps1.sh" >/dev/null 2>/dev/null | ||
|
||
load common | ||
|
||
@test "kubeon with no arguments" { | ||
run bash -c 'kubeon; echo "KUBE_PS1_ENABLED=$KUBE_PS1_ENABLED"' | ||
echo "$output" | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "kubeon with --help" { | ||
run kubeon --help | ||
[ "$status" -eq 0 ] | ||
[[ "$output" == *"Toggle kube-ps1 prompt on"* ]] | ||
} | ||
|
||
@test "kubeon with -g" { | ||
run kubeon -g | ||
[ "$status" -eq 0 ] | ||
[ ! -f "$_KUBE_PS1_DISABLE_PATH" ] | ||
} | ||
|
||
@test "kubeoff with no arguments" { | ||
run bash -c 'kubeooff; echo "$KUBE_PS1_ENABLED"' | ||
[ "$status" -eq 0 ] | ||
[[ "$output" == *"off"* ]] | ||
} | ||
|
||
@test "kubeoff with --help" { | ||
run kubeoff --help | ||
[ "$status" -eq 0 ] | ||
[[ "$output" == *"Toggle kube-ps1 prompt off"* ]] | ||
} | ||
|
||
@test "kubeoff with -g" { | ||
run kubeoff -g | ||
[ "$status" -eq 0 ] | ||
[ -f "$_KUBE_PS1_DISABLE_PATH" ] | ||
} | ||
|
||
# @test "kubeoff with invalid flag" { | ||
# run kubeoff --invalid | ||
# [ "$status" -ne 0 ] | ||
# [[ "$output" == *"error: unrecognized flag --invalid"* ]] | ||
# } | ||
|
||
@test "kube_ps1_shell_type returns correct shell type" { | ||
# Simulate bash | ||
export BASH_VERSION="5.0.0" | ||
run _kube_ps1_shell_type | ||
[ "$status" -eq 0 ] | ||
[ "$output" = "bash" ] | ||
|
||
# Simulate zsh | ||
unset BASH_VERSION | ||
export ZSH_VERSION="5.0.0" | ||
run _kube_ps1_shell_type | ||
[ "$status" -eq 0 ] | ||
[ "$output" = "zsh" ] | ||
} | ||
|
||
@test "_kube_ps1_binary_check returns true for existing command" { | ||
run _kube_ps1_binary_check ls | ||
[ "$status" -eq 0 ] | ||
} | ||
|
||
@test "_kube_ps1_binary_check returns false for non-existing command" { | ||
run _kube_ps1_binary_check nonexistingcommand | ||
[ "$status" -ne 0 ] | ||
} | ||
|
||
@test "_kube_ps1_symbol returns the default symbol" { | ||
run _kube_ps1_symbol | ||
assert_output --regexp '⎈' | ||
} | ||
|
||
@test "kube_ps1 returns correct prompt when enabled" { | ||
export KUBE_PS1_ENABLED="on" | ||
export KUBE_PS1_CONTEXT="minikube" | ||
export KUBE_PS1_NAMESPACE="default" | ||
run kube_ps1 | ||
[ "$status" -eq 0 ] | ||
[[ "$output" == *"minikube"* ]] | ||
[[ "$output" == *"default"* ]] | ||
} | ||
|
||
@test "kube_ps1 returns empty prompt when disabled" { | ||
export KUBE_PS1_ENABLED="off" | ||
run kube_ps1 | ||
[ "$status" -eq 0 ] | ||
[ -z "$output" ] | ||
} | ||
|