summaryrefslogtreecommitdiff
path: root/test/segments/kubecontext.spec
diff options
context:
space:
mode:
authorDan <2481552+opes@users.noreply.github.com>2018-04-30 21:07:55 +0300
committerGitHub <noreply@github.com>2018-04-30 21:07:55 +0300
commitfbb85e77e3dc307c21b79c655302158077fad916 (patch)
treef31b99e9fa274d247551537a694f615167895379 /test/segments/kubecontext.spec
parent75c6838a0dbb2fc84f2cf7d71cae9b147b04a379 (diff)
parent13b0e383a066c9c37d5cf71d4af521f9b73a173e (diff)
Merge branch 'master' into chruby_options
Diffstat (limited to 'test/segments/kubecontext.spec')
-rwxr-xr-xtest/segments/kubecontext.spec80
1 files changed, 80 insertions, 0 deletions
diff --git a/test/segments/kubecontext.spec b/test/segments/kubecontext.spec
new file mode 100755
index 00000000..eaaa2300
--- /dev/null
+++ b/test/segments/kubecontext.spec
@@ -0,0 +1,80 @@
+#!/usr/bin/env zsh
+#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8
+
+# Required for shunit2 to run correctly
+setopt shwordsplit
+SHUNIT_PARENT=$0
+
+function setUp() {
+ export TERM="xterm-256color"
+ # Load Powerlevel9k
+ source powerlevel9k.zsh-theme
+}
+
+function mockKubectl() {
+ case "$1" in
+ 'version')
+ echo 'non-empty text'
+ ;;
+ 'config')
+ case "$2" in
+ 'current-context')
+ echo 'minikube'
+ ;;
+ 'get-contexts')
+ echo '* minikube minikube minikube '
+ ;;
+ esac
+ ;;
+ esac
+}
+
+function mockKubectlOtherNamespace() {
+ case "$1" in
+ 'version')
+ echo 'non-empty text'
+ ;;
+ 'config')
+ case "$2" in
+ 'current-context')
+ echo 'minikube'
+ ;;
+ 'get-contexts')
+ echo '* minikube minikube minikube kube-system'
+ ;;
+ esac
+ ;;
+ esac
+}
+
+function testKubeContext() {
+ alias kubectl=mockKubectl
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext)
+
+ assertEquals "%K{magenta} %F{white%}⎈%f %F{white}minikube/default %k%F{magenta}%f " "$(build_left_prompt)"
+
+ unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ unalias kubectl
+}
+function testKubeContextOtherNamespace() {
+ alias kubectl=mockKubectlOtherNamespace
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(kubecontext)
+
+ assertEquals "%K{magenta} %F{white%}⎈%f %F{white}minikube/kube-system %k%F{magenta}%f " "$(build_left_prompt)"
+
+ unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ unalias kubectl
+}
+function testKubeContextPrintsNothingIfKubectlNotAvailable() {
+ alias kubectl=noKubectl
+ POWERLEVEL9K_CUSTOM_WORLD='echo world'
+ POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world kubecontext)
+
+ assertEquals "%K{white} %F{black}world %k%F{white}%f " "$(build_left_prompt)"
+
+ unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
+ unset POWERLEVEL9K_CUSTOM_WORLD
+ unalias kubectl
+}
+
+source shunit2/source/2.1/src/shunit2