diff --git a/scripts/completion-tests/completionTests-common.sh b/scripts/completion-tests/completionTests-common.sh new file mode 100755 index 0000000..9173a3a --- /dev/null +++ b/scripts/completion-tests/completionTests-common.sh @@ -0,0 +1,201 @@ +#!sh +# +# Copyright The Helm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +############################################################################# +# This file holds all tests that apply to all shells (bash, zsh, fish) +# It cannot use any if statements since their syntax is not portable +# between shells. +# +# For tests that are specific to a shell, use the proper specific file. +############################################################################# + + +##################### +# Static completions +##################### + +# Basic first level commands (static completion) +_completionTests_verifyCompletion "helm " "$allHelmCommands" +_completionTests_verifyCompletion "helm help " "$allHelmCommands" +_completionTests_verifyCompletion "helm sho" "show" +_completionTests_verifyCompletion "helm help sho" "show" +_completionTests_verifyCompletion "helm --debug " "$allHelmCommands" +_completionTests_verifyCompletion "helm --debug sho" "show" +_completionTests_verifyCompletion "helm -n ns " "$allHelmCommands" +_completionTests_verifyCompletion "helm -n ns sho" "show" +_completionTests_verifyCompletion "helm --namespace ns " "$allHelmCommands" +_completionTests_verifyCompletion "helm --namespace ns sho" "show" +_completionTests_verifyCompletion "helm stat" "status" +_completionTests_verifyCompletion "helm status" "status" +_completionTests_verifyCompletion "helm lis" "list" +_completionTests_verifyCompletion "helm r" "repo rollback" +_completionTests_verifyCompletion "helm re" "repo" + +# Basic second level commands (static completion) +_completionTests_verifyCompletion "helm get " "all hooks manifest notes values" +_completionTests_verifyCompletion "helm get h" "hooks" +_completionTests_verifyCompletion "helm completion " "bash zsh fish" +_completionTests_verifyCompletion "helm completion z" "zsh" +_completionTests_verifyCompletion "helm plugin " "install list uninstall update" +_completionTests_verifyCompletion "helm plugin u" "uninstall update" +_completionTests_verifyCompletion "helm --debug plugin " "install list uninstall update" +_completionTests_verifyCompletion "helm --debug plugin u" "uninstall update" +_completionTests_verifyCompletion "helm -n ns plugin " "install list uninstall update" +_completionTests_verifyCompletion "helm -n ns plugin u" "uninstall update" +_completionTests_verifyCompletion "helm --namespace ns plugin " "install list uninstall update" +_completionTests_verifyCompletion "helm --namespace ns plugin u" "uninstall update" +_completionTests_verifyCompletion "helm plugin --debug " "install list uninstall update" +_completionTests_verifyCompletion "helm plugin --debug u" "uninstall update" +_completionTests_verifyCompletion "helm plugin -n ns " "install list uninstall update" +_completionTests_verifyCompletion "helm plugin -n ns u" "uninstall update" +_completionTests_verifyCompletion "helm plugin --namespace ns " "install list uninstall update" +_completionTests_verifyCompletion "helm plugin --namespace ns u" "uninstall update" + +# With validArgs +_completionTests_verifyCompletion "helm completion " "bash zsh fish" +_completionTests_verifyCompletion "helm completion z" "zsh" +_completionTests_verifyCompletion "helm --debug completion " "bash zsh fish" +_completionTests_verifyCompletion "helm --debug completion z" "zsh" +_completionTests_verifyCompletion "helm -n ns completion " "bash zsh fish" +_completionTests_verifyCompletion "helm -n ns completion z" "zsh" +_completionTests_verifyCompletion "helm --namespace ns completion " "bash zsh fish" +_completionTests_verifyCompletion "helm --namespace ns completion z" "zsh" + +# Completion of flags +_completionTests_verifyCompletion "helm -v" "-v" +_completionTests_verifyCompletion "helm -" "$allHelmGlobalFlags" +_completionTests_verifyCompletion "helm --" "$allHelmLongFlags" +_completionTests_verifyCompletion "helm show -" "$allHelmGlobalFlags" +_completionTests_verifyCompletion "helm show --" "$allHelmLongFlags" +_completionTests_verifyCompletion "helm -n" "-n" +_completionTests_verifyCompletion "helm show -n" "-n" + +# Completion of commands while using flags +_completionTests_verifyCompletion "helm --kube-context prod sta" "status" +_completionTests_verifyCompletion "helm --kubeconfig=$COMP_DIR/config.dev1 lis" "list" +_completionTests_verifyCompletion "helm --namespace mynamespace get h" "hooks" +_completionTests_verifyCompletion "helm -v 3 get " "all hooks manifest notes values" + +# Cobra command aliases are purposefully not completed +_completionTests_verifyCompletion "helm ls" "" +_completionTests_verifyCompletion "helm dependenci" "" + +# Static completion for plugins +_completionTests_verifyCompletion "helm 2to3 " "cleanup convert move" +_completionTests_verifyCompletion "helm 2to3 c" "cleanup convert" +_completionTests_verifyCompletion "helm 2to3 move " "config" +_completionTests_verifyCompletion "helm push " "cleanup convert move" +_completionTests_verifyCompletion "helm push c" "cleanup convert" +_completionTests_verifyCompletion "helm push move " "config" + +_completionTests_verifyCompletion "helm 2to3 cleanup -" "$allHelmGlobalFlags -r -s --label --cleanup --storage" +_completionTests_verifyCompletion "helm push cleanup -" "$allHelmGlobalFlags -r -s --label --cleanup --storage" +# For plugin completion, when there are more short flags than long flags, a long flag is created for the extra short flags +# So here we expect the extra --t +_completionTests_verifyCompletion "helm 2to3 convert -" "$allHelmGlobalFlags -l -s -t --t --label --storage" +_completionTests_verifyCompletion "helm 2to3 move config --" "$allHelmLongFlags --dry-run" +_completionTests_verifyCompletion "helm push convert -" "$allHelmGlobalFlags -l -s -t --t --label --storage" +_completionTests_verifyCompletion "helm push move config --" "$allHelmLongFlags --dry-run" + +##################### +# Dynamic completions +##################### + +# For release name completion +_completionTests_verifyCompletion "helm status " "athos porthos aramis" +_completionTests_verifyCompletion "helm history a" "athos aramis" +_completionTests_verifyCompletion "helm uninstall a" "athos aramis" +_completionTests_verifyCompletion "helm upgrade a" "athos aramis" +_completionTests_verifyCompletion "helm get manifest -n default " "athos porthos aramis" +_completionTests_verifyCompletion "helm --namespace gascony get manifest " "dartagnan" +_completionTests_verifyCompletion "helm --namespace gascony test d" "dartagnan" +_completionTests_verifyCompletion "helm rollback d" "" + +# For the repo command +_completionTests_verifyCompletion "helm repo remove " "stable zztest1 zztest2" +_completionTests_verifyCompletion "helm repo remove zztest" "zztest1 zztest2" + +# For the plugin command +_completionTests_verifyCompletion "helm plugin uninstall " "2to3 push push-artifactory" +_completionTests_verifyCompletion "helm plugin uninstall pu" "push push-artifactory" +_completionTests_verifyCompletion "helm plugin update " "2to3 push push-artifactory" +_completionTests_verifyCompletion "helm plugin update pus" "push push-artifactory" + +# For the global --kube-context flag +_completionTests_verifyCompletion "helm --kube-context " "dev1 dev2 accept prod" +_completionTests_verifyCompletion "helm upgrade --kube-context " "dev1 dev2 accept prod" +_completionTests_verifyCompletion "helm upgrade --kube-context d" "dev1 dev2" + +# Now requires a real cluster +# # For the global --namespace flag +# _completionTests_verifyCompletion "helm --namespace " "casterly-rock white-harbor winterfell" +# _completionTests_verifyCompletion "helm --namespace w" "white-harbor winterfell" +# _completionTests_verifyCompletion "helm upgrade --namespace " "casterly-rock white-harbor winterfell" +# _completionTests_verifyCompletion "helm -n " "casterly-rock white-harbor winterfell" +# _completionTests_verifyCompletion "helm -n w" "white-harbor winterfell" +# _completionTests_verifyCompletion "helm upgrade -n " "casterly-rock white-harbor winterfell" +# # With override flags +# _completionTests_verifyCompletion "helm --kubeconfig myconfig --namespace " "meereen myr volantis" +# _completionTests_verifyCompletion "helm --kubeconfig=myconfig --namespace " "meereen myr volantis" +# _completionTests_verifyCompletion "helm --kube-context mycontext --namespace " "braavos old-valyria yunkai" +# _completionTests_verifyCompletion "helm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" + +# For the --output flag that applies to multiple commands +_completionTests_verifyCompletion "helm repo list --output " "json table yaml" +_completionTests_verifyCompletion "helm install --output " "json table yaml" +_completionTests_verifyCompletion "helm history -o " "json table yaml" +_completionTests_verifyCompletion "helm list -o " "json table yaml" + +# For completing specification of charts +touch zztest2file files + +_completionTests_verifyCompletion "helm show values " "./ / zztest1/ zztest2/ stable/ file:// http:// https://" +_completionTests_verifyCompletion "helm show values ht" "http:// https://" +_completionTests_verifyCompletion "helm show values zz" "zztest1/ zztest2/ zztest2file" +_completionTests_verifyCompletion "helm show values zztest2" "zztest2/ zztest2file" +_completionTests_verifyCompletion "helm show values zztest2f" "" +_completionTests_verifyCompletion "helm show values stable/yyy" "" +_completionTests_verifyCompletion "helm show values stable/z" "stable/zeppelin stable/zetcd" +_completionTests_verifyCompletion "helm show values fil" "file:// files" + +_completionTests_verifyCompletion "helm show chart zz" "zztest1/ zztest2/ zztest2file" +_completionTests_verifyCompletion "helm show readme zz" "zztest1/ zztest2/ zztest2file" +_completionTests_verifyCompletion "helm show values zz" "zztest1/ zztest2/ zztest2file" + +_completionTests_verifyCompletion "helm pull " "zztest1/ zztest2/ stable/ file:// http:// https://" +_completionTests_verifyCompletion "helm pull zz" "zztest1/ zztest2/" + +_completionTests_verifyCompletion "helm install name " "./ / zztest1/ zztest2/ stable/ file:// http:// https://" +_completionTests_verifyCompletion "helm install name zz" "zztest1/ zztest2/ zztest2file" +_completionTests_verifyCompletion "helm install name stable/z" "stable/zeppelin stable/zetcd" + +_completionTests_verifyCompletion "helm template name " "./ / zztest1/ zztest2/ stable/ file:// http:// https://" +_completionTests_verifyCompletion "helm template name zz" "zztest1/ zztest2/ zztest2file" +_completionTests_verifyCompletion "helm template name stable/z" "stable/zeppelin stable/zetcd" + +_completionTests_verifyCompletion "helm upgrade release " "./ / zztest1/ zztest2/ stable/ file:// http:// https://" +_completionTests_verifyCompletion "helm upgrade release zz" "zztest1/ zztest2/ zztest2file" +_completionTests_verifyCompletion "helm upgrade release stable/z" "stable/zeppelin stable/zetcd" + +_completionTests_verifyCompletion "helm show values stab" "stable/ stable/." + +rm zztest2file files + +# Dynamic completion for plugins +_completionTests_verifyCompletion "helm 2to3 -n dumbledore convert " "case-ns convert dumbledore" +_completionTests_verifyCompletion "helm 2to3 convert " "hermione harry ron" +_completionTests_verifyCompletion "helm push-artifactory -n dumbledore convert " "case-ns convert dumbledore" +_completionTests_verifyCompletion "helm push-artifactory convert " "hermione harry ron" diff --git a/scripts/completion-tests/completionTests.bash b/scripts/completion-tests/completionTests.bash new file mode 100755 index 0000000..fcf8b26 --- /dev/null +++ b/scripts/completion-tests/completionTests.bash @@ -0,0 +1,166 @@ +#!bash +# +# Copyright The Helm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################### +# Static completions +##################### + +# Completion of flags +_completionTests_verifyCompletion "helm --kube-con" "--kube-context= --kube-context" +_completionTests_verifyCompletion "helm --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "helm --v" "--v= --vmodule= --v --vmodule" +_completionTests_verifyCompletion "helm --name" "--namespace= --namespace" +_completionTests_verifyCompletion "helm --s" "--skip-headers --skip-log-headers --stderrthreshold --stderrthreshold=" +_completionTests_verifyCompletion "helm show --s" "--skip-headers --skip-log-headers --stderrthreshold --stderrthreshold=" +_completionTests_verifyCompletion "helm get hooks --kubec" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "helm get --name" "--namespace= --namespace" + +##################### +# Dynamic completions +##################### + +# For the global --kube-context flag +_completionTests_verifyCompletion "helm --kube-context=" "dev1 dev2 accept prod" + +# Make sure completion works as expected when there are no repositories configured +XDG_CONFIG_HOME='/invalid/path' _completionTests_verifyCompletion "helm repo remove " "" +# Make sure completion works as expected when there are no plugins +XDG_DATA_HOME='/invalid/path' _completionTests_verifyCompletion "helm plugin uninstall " "" + +# Dynamic completion for plugins +_completionTests_verifyCompletion "helm 2to3 move config g" "gryffindor" +_completionTests_verifyCompletion "helm 2to3 convert -s flag d" "dobby draco" +_completionTests_verifyCompletion "helm push-artifactory move config g" "gryffindor" +_completionTests_verifyCompletion "helm push-artifactory convert -s flag d" "dobby draco" + +# Now requires a real cluster +# _completionTests_verifyCompletion "helm --namespace=" "casterly-rock white-harbor winterfell" +# _completionTests_verifyCompletion "helm --namespace=w" "white-harbor winterfell" +# _completionTests_verifyCompletion "helm upgrade --namespace=w" "white-harbor winterfell" +# _completionTests_verifyCompletion "helm upgrade --namespace=" "casterly-rock white-harbor winterfell" +# _completionTests_verifyCompletion "helm -n=" "casterly-rock white-harbor winterfell" +# _completionTests_verifyCompletion "helm -n=w" "white-harbor winterfell" +# _completionTests_verifyCompletion "helm upgrade -n=w" "white-harbor winterfell" +# _completionTests_verifyCompletion "helm upgrade -n=" "casterly-rock white-harbor winterfell" + +############################################################## +# Completion with helm called through an alias or using a path +############################################################## + +# We want to specify a different helm for completion than the one +# that is found on the PATH variable. +# This is particularly valuable to check that dynamic completion +# uses the correct location for helm. + +# Copy helm to a location that is not on PATH +TMP_HELM_DIR=$(mktemp -d ${ROBOT_OUTPUT_DIR}/helm-acceptance-temp-bin.XXXXXX) +trap "rm -rf ${TMP_HELM_DIR}" EXIT + +mkdir -p $TMP_HELM_DIR +HELM_DIR=$(dirname $(which helm)) +cp $HELM_DIR/helm $TMP_HELM_DIR/helm + +# Make 'helm' unavailable to make sure it can't be called directly +# by the dynamic completion code, which should instead use the helm +# as called in the completion calls that follow. +alias helm=echo + +# Create aliases to helm +# This alias will be created after the variable is expanded +alias helmAlias="${TMP_HELM_DIR}/helm" +# This alias will be created without expanding the variable (because of single quotes) +alias helmAliasWithVar='${TMP_HELM_DIR}/helm' + +# Hook these new aliases to the helm completion function. +complete -o default -F $(_completionTests_findCompletionFunction helm) helmAlias +complete -o default -F $(_completionTests_findCompletionFunction helm) helmAliasWithVar + +# Completion with normal alias +_completionTests_verifyCompletion "helmAlias lis" "list" +_completionTests_verifyCompletion "helmAlias completion z" "zsh" +_completionTests_verifyCompletion "helmAlias --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "helmAlias get hooks --kubec" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "helmAlias repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "helmAlias plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "helmAlias upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "helmAlias --kube-context=mycontext --namespace " "braavos old-valyria yunkai" + +# Completion with alias that contains a variable +_completionTests_verifyCompletion "helmAliasWithVar lis" "list" +_completionTests_verifyCompletion "helmAliasWithVar completion z" "zsh" +_completionTests_verifyCompletion "helmAliasWithVar --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "helmAliasWithVar get hooks --kubec" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "helmAliasWithVar repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "helmAliasWithVar plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "helmAliasWithVar upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "helmAliasWithVar --kube-context=mycontext --namespace " "braavos old-valyria yunkai" + +# Completion with absolute path +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm lis" "list" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm completion z" "zsh" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "$TMP_HELM_DIR/helm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm get hooks --kubec" "--kubeconfig= --kubeconfig" + +# Completion with relative path +cd $TMP_HELM_DIR +_completionTests_verifyCompletion "./helm lis" "list" +_completionTests_verifyCompletion "./helm completion z" "zsh" +_completionTests_verifyCompletion "./helm repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "./helm plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "./helm upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "./helm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" +_completionTests_verifyCompletion "./helm --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "./helm get hooks --kubec" "--kubeconfig= --kubeconfig" + +cd - >/dev/null + +# Completion with a different name for helm +mv $TMP_HELM_DIR/helm $TMP_HELM_DIR/myhelm + +# Generating the completion script using the new binary name +# should make completion work for that binary name +source /dev/stdin <<- EOF + $(${TMP_HELM_DIR}/myhelm completion bash) +EOF +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm lis" "list" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm completion z" "zsh" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm get hooks --kubec" "--kubeconfig= --kubeconfig" + +# Completion with a different name for helm that is on PATH +mv $TMP_HELM_DIR/myhelm $HELM_DIR/myhelm +_completionTests_verifyCompletion "myhelm lis" "list" +_completionTests_verifyCompletion "myhelm completion z" "zsh" +_completionTests_verifyCompletion "myhelm repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "myhelm plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "myhelm upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "myhelm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" +_completionTests_verifyCompletion "myhelm --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "myhelm get hooks --kubec" "--kubeconfig= --kubeconfig" + +unalias helm + +# This must be the last call. It allows to exit with an exit code +# that reflects the final status of all the tests. +_completionTests_exit diff --git a/scripts/completion-tests/completionTests.fish b/scripts/completion-tests/completionTests.fish new file mode 100755 index 0000000..42760f4 --- /dev/null +++ b/scripts/completion-tests/completionTests.fish @@ -0,0 +1,179 @@ +#!bash +# +# Copyright The Helm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################### +# Static completions +##################### + +# Completion of flags +_completionTests_verifyCompletion "helm --kube-con" "--kube-context= --kube-context" +_completionTests_verifyCompletion "helm --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "helm --v" "--v= --vmodule= --v --vmodule" +_completionTests_verifyCompletion "helm --name" "--namespace= --namespace" +_completionTests_verifyCompletion "helm --s" "--skip-headers --skip-log-headers --stderrthreshold --stderrthreshold=" +_completionTests_verifyCompletion "helm show --s" "--skip-headers --skip-log-headers --stderrthreshold --stderrthreshold=" +_completionTests_verifyCompletion "helm get hooks --kubec" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "helm get --name" "--namespace= --namespace" + +# Invalid kubeconfig file. Should not cause error in the completion. +_completionTests_verifyCompletion "helm --kubeconfig=/invalid/path lis" "" + +##################### +# Dynamic completions +##################### + +# For the global --kube-context flag +_completionTests_verifyCompletion "helm --kube-context=" "--kube-context=dev1 --kube-context=dev2 --kube-context=accept --kube-context=prod" + +# Make sure completion works as expected when there are no repositories configured +# This form requires Fish 3.1 +XDG_CONFIG_HOME='/invalid/path' _completionTests_verifyCompletion "helm repo remove " "" +# Make sure completion works as expected when there are no plugins +XDG_DATA_HOME='/invalid/path' _completionTests_verifyCompletion "helm plugin uninstall " "" + +# Dynamic completion for plugins +# The tests for fish don't get the filtered list based on the completion prefix, but instead get the full list. +# This is a problem with the test, not the completion. +# No point in running them. There are other tests for plugin dynamic completion in the common test file +# _completionTests_verifyCompletion "helm 2to3 move config g" "gryffindor" +# _completionTests_verifyCompletion "helm 2to3 convert -s flag d" "dobby draco" +# _completionTests_verifyCompletion "helm push-artifactory move config g" "gryffindor" +# _completionTests_verifyCompletion "helm push-artifactory convert -s flag d" "dobby draco" + +# Now requires a real cluster +# _completionTests_verifyCompletion "helm --namespace=" "casterly-rock white-harbor winterfell" +# _completionTests_verifyCompletion "helm --namespace=w" "white-harbor winterfell" +# _completionTests_verifyCompletion "helm upgrade --namespace=w" "white-harbor winterfell" +# _completionTests_verifyCompletion "helm upgrade --namespace=" "casterly-rock white-harbor winterfell" +# _completionTests_verifyCompletion "helm -n=" "casterly-rock white-harbor winterfell" +# _completionTests_verifyCompletion "helm -n=w" "white-harbor winterfell" +# _completionTests_verifyCompletion "helm upgrade -n=w" "white-harbor winterfell" +# _completionTests_verifyCompletion "helm upgrade -n=" "casterly-rock white-harbor winterfell" + +############################################################## +# Completion with helm called through an alias or using a path +############################################################## + +# We want to specify a different helm for completion than the one +# that is found on the PATH variable. +# This is particularly valuable to check that dynamic completion +# uses the correct location for helm. + +# Copy helm to a location that is not on PATH +set --global TMP_HELM_DIR (mktemp -d $ROBOT_OUTPUT_DIR/helm-acceptance-temp-bin.XXXXXX) + +mkdir -p $TMP_HELM_DIR +set --global HELM_DIR (dirname (which helm)) +cp $HELM_DIR/helm $TMP_HELM_DIR/helm + +# Make 'helm' unavailable to make sure it can't be called directly +# by the dynamic completion code, which should instead use the helm +# as called in the completion calls that follow. +alias helm echo + +# Create aliases to helm +# This alias will be created after the variable is expanded +alias helmAlias "$TMP_HELM_DIR/helm" +# This alias will be created without expanding the variable (because of single quotes) +alias helmAliasWithVar '$TMP_HELM_DIR/helm' + +# Completion with normal alias +_completionTests_verifyCompletion "helmAlias lis" "list" +_completionTests_verifyCompletion "helmAlias completion z" "zsh" +_completionTests_verifyCompletion "helmAlias --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "helmAlias get hooks --kubec" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "helmAlias repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "helmAlias plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "helmAlias upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "helmAlias --kube-context=mycontext --namespace " "braavos old-valyria yunkai" + +# Completion with alias that contains a variable +_completionTests_verifyCompletion "helmAliasWithVar lis" "list" +_completionTests_verifyCompletion "helmAliasWithVar completion z" "zsh" +_completionTests_verifyCompletion "helmAliasWithVar --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "helmAliasWithVar get hooks --kubec" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "helmAliasWithVar repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "helmAliasWithVar plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "helmAliasWithVar upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "helmAliasWithVar --kube-context=mycontext --namespace " "braavos old-valyria yunkai" + +# Completion with absolute path +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm lis" "list" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm completion z" "zsh" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "$TMP_HELM_DIR/helm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm get hooks --kubec" "--kubeconfig= --kubeconfig" + +# Completion with relative path +cd $TMP_HELM_DIR +_completionTests_verifyCompletion "./helm lis" "list" +_completionTests_verifyCompletion "./helm completion z" "zsh" +_completionTests_verifyCompletion "./helm repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "./helm plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "./helm upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "./helm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" +_completionTests_verifyCompletion "./helm --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "./helm get hooks --kubec" "--kubeconfig= --kubeconfig" + +cd - >/dev/null + +# TODO improve the below tests. +# Currently, _completionTests_verifyCompletion simply calls the fish function that +# creates the completion; it does not actually make sure there is a complete command +# registered for the new binary name that will call this function. +# We should instead extract the name of the fish function by doing +# complete | grep myhelm +# to make sure that there are complete commands for myhelm + +# Completion with a different name for helm +mv $TMP_HELM_DIR/helm $TMP_HELM_DIR/myhelm + +# Generating the completion script using the new binary name +# should make completion work for that binary name +$TMP_HELM_DIR/myhelm completion fish --no-descriptions| source + +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm lis" "list" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm completion z" "zsh" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm get hooks --kubec" "--kubeconfig= --kubeconfig" + +# Completion with a different name for helm that is on PATH +mv $TMP_HELM_DIR/myhelm $HELM_DIR/myhelm + +_completionTests_verifyCompletion "myhelm lis" "list" +_completionTests_verifyCompletion "myhelm completion z" "zsh" +_completionTests_verifyCompletion "myhelm repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "myhelm plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "myhelm upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "myhelm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" +_completionTests_verifyCompletion "myhelm --kubecon" "--kubeconfig= --kubeconfig" +_completionTests_verifyCompletion "myhelm get hooks --kubec" "--kubeconfig= --kubeconfig" + +# This is how you unalias +functions --erase helm + +rm -rf $TMP_HELM_DIR + +# This must be the last call. It allows to exit with an exit code +# that reflects the final status of all the tests. +_completionTests_exit diff --git a/scripts/completion-tests/completionTests.sh b/scripts/completion-tests/completionTests.sh deleted file mode 100755 index 4b9641a..0000000 --- a/scripts/completion-tests/completionTests.sh +++ /dev/null @@ -1,722 +0,0 @@ -#!bash -# -# Copyright The Helm Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This script tests different scenarios of completion. The tests can be -# run by sourcing this file from a bash shell or a zsh shell. - -source ${COMP_DIR}/lib/completionTests-base.sh - -export PATH=${COMP_DIR}/bin:$PATH - -# Use the memory driver with pre-defined releases to easily -# test release name completion -export HELM_DRIVER=memory -export HELM_MEMORY_DRIVER_DATA=${COMP_DIR}/releases.yaml - -# Helm setup -if [ ! -z ${ROBOT_HELM_V3} ]; then - export XDG_CACHE_HOME=${COMP_DIR}/cache && rm -rf ${XDG_CACHE_HOME} && mkdir -p ${XDG_CACHE_HOME} - export XDG_CONFIG_HOME=${COMP_DIR}/config && rm -rf ${XDG_CONFIG_HOME} && mkdir -p ${XDG_CONFIG_HOME} - export XDG_DATA_HOME=${COMP_DIR}/data && rm -rf ${XDG_DATA_HOME} && mkdir -p ${XDG_DATA_HOME} - - REPO_ROOT=${XDG_CONFIG_HOME}/helm - PLUGIN_ROOT=${XDG_DATA_HOME}/helm/plugins -else - export HELM_HOME=${COMP_DIR}/.helm && rm -rf ${HELM_HOME} && mkdir -p ${HELM_HOME} - helm init --client-only - - REPO_ROOT=${HELM_HOME}/repository - PLUGIN_ROOT=${HELM_HOME}/plugins -fi - -############################################################## -# REPOS SETUP -############################################################## - -# Setup some repos to allow testing completion of the helm repo command -# We inject the content of the repositories.yaml file directly to avoid requiring -# an internet connection if we were to use 'helm repo add' -mkdir -p ${REPO_ROOT} -cat > ${REPO_ROOT}/repositories.yaml << EOF -apiVersion: v1 -generated: "2019-08-11T22:28:44.841141-04:00" -repositories: -- name: stable - url: https://kubernetes-charts.storage.googleapis.com -- name: zztest1 - url: https://charts.example.com -- name: zztest2 - url: https://charts2.example.com -EOF -helm repo list -# Fetch the details of the stable repo -helm repo update - -############################################################## -# PLUGINS SETUP -############################################################## - -# Setup some plugins to allow testing completion of the helm plugin command -# We inject the content of different plugin.yaml files directly to avoid having -# to install a real plugin which can take a long time. - -########### -# Plugin 1 -########### -PLUGIN_DIR=${PLUGIN_ROOT}/helm-2to3 -mkdir -p ${PLUGIN_DIR} -# The plugin file -cat > ${PLUGIN_DIR}/plugin.yaml << EOF -name: "2to3" -version: "2.5.1+2" -description: "Migrate from helm v2 to helm v3" -EOF - -# The plugin's static completion file -cat > ${PLUGIN_DIR}/completion.yaml << EOF -commands: -- name: cleanup - flags: - - r - - label - - cleanup - - s - - storage -- name: convert - flags: - - l - - label - - s - - storage - - t -- name: move - commands: - - name: config - flags: - - dry-run -EOF - -# The plugin's dynamic completion file -cat > ${PLUGIN_DIR}/plugin.complete << EOF -#!/usr/bin/env sh - -if [ "\$2" = "config" ]; then - echo case-config - echo gryffindor - echo slytherin - echo ravenclaw - echo hufflepuff - echo :0 - exit -fi - -if [ "\$HELM_NAMESPACE" != "default" ]; then - echo case-ns - # Check the namespace flag is not passed - echo \$1 - # Check plugin variables are set - echo \$HELM_NAMESPACE - echo :4 - exit -fi - -if [ "\$2" = -s ]; then - echo case-flag - echo lucius - echo draco - echo dobby - echo :4 - exit -fi - -# Check missing directive -echo hermione -echo harry -echo ron -EOF -chmod u+x ${PLUGIN_DIR}/plugin.complete - -########### -# Plugin 2 -########### -PLUGIN_DIR=${PLUGIN_ROOT}/helm-push -mkdir -p ${PLUGIN_DIR} -# The plugin file -cat > ${PLUGIN_DIR}/plugin.yaml << EOF -name: "push" -version: "0.7.1" -description: "Push chart package to ChartMuseum" -EOF - -# A plugin's static completion file without a dynamic completion file -cat > ${PLUGIN_DIR}/completion.yaml << EOF -commands: -- name: cleanup - flags: - - r - - label - - cleanup - - s - - storage -- name: convert - flags: - - l - - label - - s - - storage - - t -- name: move - commands: - - name: config - flags: - - dry-run -EOF - -########### -# Plugin 3 -########### -PLUGIN_DIR=${PLUGIN_ROOT}/helm-push-artifactory -mkdir -p ${PLUGIN_DIR} -# The plugin file -cat > ${PLUGIN_DIR}/plugin.yaml << EOF -name: "push-artifactory" -version: "0.3.0" -description: "Push helm charts to artifactory" -EOF - -# A plugin's dynamic completion file without a static completion file -cat > ${PLUGIN_DIR}/plugin.complete << EOF -#!/usr/bin/env sh - -if [ "\$2" = "config" ]; then - echo case-config - echo gryffindor - echo slytherin - echo ravenclaw - echo hufflepuff - echo :0 - exit -fi - -if [ "\$HELM_NAMESPACE" != "default" ]; then - echo case-ns - # Check the namespace flag is not passed - echo \$1 - # Check plugin variables are set - echo \$HELM_NAMESPACE - echo :4 - exit -fi - -if [ "\$2" = -s ]; then - echo case-flag - echo lucius - echo draco - echo dobby - echo :4 - exit -fi - -# Check missing directive -echo hermione -echo harry -echo ron -EOF -chmod u+x ${PLUGIN_DIR}/plugin.complete - -helm plugin list - -############################################################## -# CONTEXTS SETUP -############################################################## - -# config file stubs -cat > ${COMP_DIR}/config.dev1 << EOF -kind: Config -apiVersion: v1 -contexts: -- context: - name: dev1 -current-context: dev1 -EOF -cat > ${COMP_DIR}/config.dev2 << EOF -kind: Config -apiVersion: v1 -contexts: -- context: - name: dev2 -current-context: dev2 -EOF -cat > ${COMP_DIR}/config.accept << EOF -kind: Config -apiVersion: v1 -contexts: -- context: - name: accept -current-context: accept -EOF -cat > ${COMP_DIR}/config.prod << EOF -kind: Config -apiVersion: v1 -contexts: -- context: - name: prod -current-context: prod -EOF -export KUBECONFIG=${COMP_DIR}/config.dev1:${COMP_DIR}/config.dev2:${COMP_DIR}/config.accept:${COMP_DIR}/config.prod - -# Source the completion script after setting things up, so it can -# take the configuration into consideration (such as plugin names) -# Don't use the new source <() form as it does not work with bash v3 -source /dev/stdin <<- EOF - $(helm completion $SHELL_TYPE) -EOF - -allHelmCommands="completion create dependency env 2to3 get history install lint list package plugin pull push push-artifactory repo rollback search show status template test uninstall upgrade verify version" -if [ "$SHELL_TYPE" = bash ]; then - allHelmGlobalFlags="--add-dir-header --alsologtostderr --debug --kube-apiserver --kube-apiserver= --kube-context --kube-context= --kube-token --kube-token= --kubeconfig --kubeconfig= --log-backtrace-at --log-backtrace-at= --log-dir --log-dir= --log-file --log-file-max-size --log-file-max-size= --log-file= --logtostderr --namespace --namespace= --registry-config --registry-config= --repository-cache --repository-cache= --repository-config --repository-config= --skip-headers --skip-log-headers --stderrthreshold --stderrthreshold= --v --v= --vmodule --vmodule= -n -v" - allHelmLongFlags="--add-dir-header --alsologtostderr --debug --kube-apiserver --kube-apiserver= --kube-context --kube-context= --kube-token --kube-token= --kubeconfig --kubeconfig= --log-backtrace-at --log-backtrace-at= --log-dir --log-dir= --log-file --log-file-max-size --log-file-max-size= --log-file= --logtostderr --namespace --namespace= --registry-config --registry-config= --repository-cache --repository-cache= --repository-config --repository-config= --skip-headers --skip-log-headers --stderrthreshold --stderrthreshold= --v --v= --vmodule --vmodule=" -else - allHelmGlobalFlags="--add-dir-header --alsologtostderr --debug --kube-apiserver --kube-apiserver --kube-apiserver --kube-context --kube-context --kube-context --kube-token --kube-token --kube-token --kubeconfig --kubeconfig --kubeconfig --log-backtrace-at --log-backtrace-at --log-backtrace-at --log-dir --log-dir --log-dir --log-file --log-file --log-file --log-file-max-size --log-file-max-size --log-file-max-size --logtostderr --namespace --namespace --namespace --registry-config --registry-config --registry-config --repository-cache --repository-cache --repository-cache --repository-config --repository-config --repository-config --skip-headers --skip-log-headers --stderrthreshold --stderrthreshold --stderrthreshold --v --v --v --vmodule --vmodule --vmodule -n -v" - allHelmLongFlags="--add-dir-header --alsologtostderr --debug --kube-apiserver --kube-apiserver --kube-apiserver --kube-context --kube-context --kube-context --kube-token --kube-token --kube-token --kubeconfig --kubeconfig --kubeconfig --log-backtrace-at --log-backtrace-at --log-backtrace-at --log-dir --log-dir --log-dir --log-file --log-file --log-file --log-file-max-size --log-file-max-size --log-file-max-size --logtostderr --namespace --namespace --namespace --registry-config --registry-config --registry-config --repository-cache --repository-cache --repository-cache --repository-config --repository-config --repository-config --skip-headers --skip-log-headers --stderrthreshold --stderrthreshold --stderrthreshold --v --v --v --vmodule --vmodule --vmodule" -fi - -##################### -# Static completions -##################### - -# Basic first level commands (static completion) -_completionTests_verifyCompletion "helm " "$allHelmCommands" -_completionTests_verifyCompletion "helm help " "$allHelmCommands" -_completionTests_verifyCompletion "helm sho" "show" -_completionTests_verifyCompletion "helm help sho" "show" -_completionTests_verifyCompletion "helm --debug " "$allHelmCommands" -_completionTests_verifyCompletion "helm --debug sho" "show" -_completionTests_verifyCompletion "helm -n ns " "$allHelmCommands" -_completionTests_verifyCompletion "helm -n ns sho" "show" -_completionTests_verifyCompletion "helm --namespace ns " "$allHelmCommands" -_completionTests_verifyCompletion "helm --namespace ns sho" "show" -_completionTests_verifyCompletion "helm stat" "status" -_completionTests_verifyCompletion "helm status" "status" -_completionTests_verifyCompletion "helm lis" "list" -if [ ! -z ${ROBOT_HELM_V3} ]; then - _completionTests_verifyCompletion "helm r" "repo rollback" - _completionTests_verifyCompletion "helm re" "repo" -else - _completionTests_verifyCompletion "helm r" "repo reset rollback" - _completionTests_verifyCompletion "helm re" "repo reset" -fi - -# Basic second level commands (static completion) -if [ ! -z ${ROBOT_HELM_V3} ]; then - _completionTests_verifyCompletion "helm get " "all hooks manifest notes values" -else - _completionTests_verifyCompletion "helm get " "all hooks manifest notes values" -fi -_completionTests_verifyCompletion "helm get h" "hooks" -_completionTests_verifyCompletion "helm completion " "bash zsh fish" -_completionTests_verifyCompletion "helm completion z" "zsh" -_completionTests_verifyCompletion "helm plugin " "install list uninstall update" -_completionTests_verifyCompletion "helm plugin u" "uninstall update" -_completionTests_verifyCompletion "helm --debug plugin " "install list uninstall update" -_completionTests_verifyCompletion "helm --debug plugin u" "uninstall update" -_completionTests_verifyCompletion "helm -n ns plugin " "install list uninstall update" -_completionTests_verifyCompletion "helm -n ns plugin u" "uninstall update" -_completionTests_verifyCompletion "helm --namespace ns plugin " "install list uninstall update" -_completionTests_verifyCompletion "helm --namespace ns plugin u" "uninstall update" -_completionTests_verifyCompletion "helm plugin --debug " "install list uninstall update" -_completionTests_verifyCompletion "helm plugin --debug u" "uninstall update" -_completionTests_verifyCompletion "helm plugin -n ns " "install list uninstall update" -_completionTests_verifyCompletion "helm plugin -n ns u" "uninstall update" -_completionTests_verifyCompletion "helm plugin --namespace ns " "install list uninstall update" -_completionTests_verifyCompletion "helm plugin --namespace ns u" "uninstall update" - -# With validArgs -_completionTests_verifyCompletion "helm completion " "bash zsh fish" -_completionTests_verifyCompletion "helm completion z" "zsh" -_completionTests_verifyCompletion "helm --debug completion " "bash zsh fish" -_completionTests_verifyCompletion "helm --debug completion z" "zsh" -_completionTests_verifyCompletion "helm -n ns completion " "bash zsh fish" -_completionTests_verifyCompletion "helm -n ns completion z" "zsh" -_completionTests_verifyCompletion "helm --namespace ns completion " "bash zsh fish" -_completionTests_verifyCompletion "helm --namespace ns completion z" "zsh" - -# Completion of flags -if [ "$SHELL_TYPE" = bash ]; then - _completionTests_verifyCompletion "helm --kube-con" "--kube-context= --kube-context" - _completionTests_verifyCompletion "helm --kubecon" "--kubeconfig= --kubeconfig" -else - _completionTests_verifyCompletion "helm --kube-con" "--kube-context --kube-context --kube-context" - _completionTests_verifyCompletion "helm --kubecon" "--kubeconfig --kubeconfig --kubeconfig" -fi -if [ ! -z ${ROBOT_HELM_V3} ]; then - _completionTests_verifyCompletion "helm -v" "-v" - if [ "$SHELL_TYPE" = bash ]; then - _completionTests_verifyCompletion "helm --v" "--v= --vmodule= --v --vmodule" - _completionTests_verifyCompletion "helm --name" "--namespace= --namespace" - else - _completionTests_verifyCompletion "helm --v" "--v --vmodule --v --vmodule --v --vmodule" - _completionTests_verifyCompletion "helm --name" "--namespace --namespace --namespace" - fi -fi - -_completionTests_verifyCompletion "helm -" "$allHelmGlobalFlags" -_completionTests_verifyCompletion "helm --" "$allHelmLongFlags" -_completionTests_verifyCompletion "helm show -" "$allHelmGlobalFlags" -_completionTests_verifyCompletion "helm show --" "$allHelmLongFlags" - -if [ "$SHELL_TYPE" = bash ]; then - _completionTests_verifyCompletion "helm --s" "--skip-headers --skip-log-headers --stderrthreshold --stderrthreshold=" - _completionTests_verifyCompletion "helm show --s" "--skip-headers --skip-log-headers --stderrthreshold --stderrthreshold=" -else - _completionTests_verifyCompletion "helm --s" "--skip-headers --skip-log-headers --stderrthreshold --stderrthreshold --stderrthreshold" - _completionTests_verifyCompletion "helm show --s" "--skip-headers --skip-log-headers --stderrthreshold --stderrthreshold --stderrthreshold" -fi - -_completionTests_verifyCompletion "helm -n" "-n" -_completionTests_verifyCompletion "helm show -n" "-n" - -# Completion of commands while using flags -_completionTests_verifyCompletion "helm --kube-context prod sta" "status" -_completionTests_verifyCompletion "helm --kubeconfig=/tmp/config lis" "list" -if [ "$SHELL_TYPE" = bash ]; then - _completionTests_verifyCompletion "helm get hooks --kubec" "--kubeconfig= --kubeconfig" -else - _completionTests_verifyCompletion "helm get hooks --kubec" "--kubeconfig --kubeconfig --kubeconfig" -fi -if [ ! -z ${ROBOT_HELM_V3} ]; then - _completionTests_verifyCompletion "helm --namespace mynamespace get h" "hooks" - _completionTests_verifyCompletion "helm -v 3 get " "all hooks manifest notes values" - if [ "$SHELL_TYPE" = bash ]; then - _completionTests_verifyCompletion "helm get --name" "--namespace= --namespace" - else - _completionTests_verifyCompletion "helm get --name" "--namespace --namespace --namespace" - fi -fi - -# Cobra command aliases are purposefully not completed -_completionTests_verifyCompletion "helm ls" "" -_completionTests_verifyCompletion "helm dependenci" "" - -# Static completion for plugins -_completionTests_verifyCompletion "helm 2to3 " "cleanup convert move" -_completionTests_verifyCompletion "helm 2to3 c" "cleanup convert" -_completionTests_verifyCompletion "helm 2to3 move " "config" -_completionTests_verifyCompletion "helm push " "cleanup convert move" -_completionTests_verifyCompletion "helm push c" "cleanup convert" -_completionTests_verifyCompletion "helm push move " "config" - -_completionTests_verifyCompletion "helm 2to3 cleanup -" "$allHelmGlobalFlags -r -s --label --cleanup --storage" -_completionTests_verifyCompletion "helm push cleanup -" "$allHelmGlobalFlags -r -s --label --cleanup --storage" -# For plugin completion, when there are more short flags than long flags, a long flag is created for the extra short flags -# So here we expect the extra --t -_completionTests_verifyCompletion "helm 2to3 convert -" "$allHelmGlobalFlags -l -s -t --t --label --storage" -_completionTests_verifyCompletion "helm 2to3 move config --" "$allHelmLongFlags --dry-run" -_completionTests_verifyCompletion "helm push convert -" "$allHelmGlobalFlags -l -s -t --t --label --storage" -_completionTests_verifyCompletion "helm push move config --" "$allHelmLongFlags --dry-run" - -##################### -# Dynamic completions -##################### - -# For release name completion -_completionTests_verifyCompletion "helm status " "athos porthos aramis" -_completionTests_verifyCompletion "helm history a" "athos aramis" -_completionTests_verifyCompletion "helm uninstall a" "athos aramis" -_completionTests_verifyCompletion "helm upgrade a" "athos aramis" -_completionTests_verifyCompletion "helm get manifest -n default " "athos porthos aramis" -_completionTests_verifyCompletion "helm --namespace gascony get manifest " "dartagnan" -_completionTests_verifyCompletion "helm --namespace gascony test d" "dartagnan" -_completionTests_verifyCompletion "helm rollback d" "" - -# For the repo command -_completionTests_verifyCompletion "helm repo remove " "stable zztest1 zztest2" -_completionTests_verifyCompletion "helm repo remove zztest" "zztest1 zztest2" -if [ ! -z ${ROBOT_HELM_V3} ]; then - # Make sure completion works as expected when there are no repositories configured - tmp=$XDG_CONFIG_HOME - XDG_CONFIG_HOME='/invalid/path' _completionTests_verifyCompletion "helm repo remove " "" - XDG_CONFIG_HOME=$tmp -fi - -# For the plugin command -_completionTests_verifyCompletion "helm plugin uninstall " "2to3 push push-artifactory" -_completionTests_verifyCompletion "helm plugin uninstall pu" "push push-artifactory" -_completionTests_verifyCompletion "helm plugin update " "2to3 push push-artifactory" -_completionTests_verifyCompletion "helm plugin update pus" "push push-artifactory" -if [ ! -z ${ROBOT_HELM_V3} ]; then - # Make sure completion works as expected when there are no plugins - tmp=$XDG_DATA_HOME - XDG_DATA_HOME='/invalid/path' _completionTests_verifyCompletion "helm plugin uninstall " "" - XDG_DATA_HOME=$tmp -fi - -# For the global --kube-context flag -if [ ! -z ${ROBOT_HELM_V3} ]; then - # Feature not available in v2 - _completionTests_verifyCompletion "helm --kube-context " "dev1 dev2 accept prod" - _completionTests_verifyCompletion "helm upgrade --kube-context " "dev1 dev2 accept prod" - _completionTests_verifyCompletion "helm upgrade --kube-context d" "dev1 dev2" - if [ "$SHELL_TYPE" = bash ]; then - _completionTests_verifyCompletion "helm --kube-context=" "dev1 dev2 accept prod" - else - _completionTests_verifyCompletion "helm --kube-context=" "--kube-context=dev1 --kube-context=dev2 --kube-context=accept --kube-context=prod" - fi -fi - -# Now requires a real cluster -# # For the global --namespace flag -# if [ ! -z ${ROBOT_HELM_V3} ]; then -# # No namespace flag in v2 -# _completionTests_verifyCompletion "helm --namespace " "casterly-rock white-harbor winterfell" -# _completionTests_verifyCompletion "helm --namespace w" "white-harbor winterfell" -# _completionTests_verifyCompletion "helm upgrade --namespace " "casterly-rock white-harbor winterfell" -# _completionTests_verifyCompletion "helm -n " "casterly-rock white-harbor winterfell" -# _completionTests_verifyCompletion "helm -n w" "white-harbor winterfell" -# _completionTests_verifyCompletion "helm upgrade -n " "casterly-rock white-harbor winterfell" - -# if [ "$SHELL_TYPE" = bash ]; then -# _completionTests_verifyCompletion "helm --namespace=" "casterly-rock white-harbor winterfell" -# _completionTests_verifyCompletion "helm --namespace=w" "white-harbor winterfell" -# _completionTests_verifyCompletion "helm upgrade --namespace=w" "white-harbor winterfell" -# _completionTests_verifyCompletion "helm upgrade --namespace=" "casterly-rock white-harbor winterfell" -# _completionTests_verifyCompletion "helm -n=" "casterly-rock white-harbor winterfell" -# _completionTests_verifyCompletion "helm -n=w" "white-harbor winterfell" -# _completionTests_verifyCompletion "helm upgrade -n=w" "white-harbor winterfell" -# _completionTests_verifyCompletion "helm upgrade -n=" "casterly-rock white-harbor winterfell" -# else -# _completionTests_verifyCompletion "helm --namespace=" "--namespace=casterly-rock --namespace=white-harbor --namespace=winterfell" -# _completionTests_verifyCompletion "helm --namespace=w" "--namespace=white-harbor --namespace=winterfell" -# _completionTests_verifyCompletion "helm upgrade --namespace=w" "--namespace=white-harbor --namespace=winterfell" -# _completionTests_verifyCompletion "helm upgrade --namespace=" "--namespace=casterly-rock --namespace=white-harbor --namespace=winterfell" -# _completionTests_verifyCompletion "helm -n=" "-n=casterly-rock -n=white-harbor -n=winterfell" -# _completionTests_verifyCompletion "helm -n=w" "-n=white-harbor -n=winterfell" -# _completionTests_verifyCompletion "helm upgrade -n=w" "-n=white-harbor -n=winterfell" -# _completionTests_verifyCompletion "helm upgrade -n=" "-n=casterly-rock -n=white-harbor -n=winterfell" -# fi - -# # With override flags -# _completionTests_verifyCompletion "helm --kubeconfig myconfig --namespace " "meereen myr volantis" -# _completionTests_verifyCompletion "helm --kubeconfig=myconfig --namespace " "meereen myr volantis" -# _completionTests_verifyCompletion "helm --kube-context mycontext --namespace " "braavos old-valyria yunkai" -# _completionTests_verifyCompletion "helm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" -# fi -# For the --output flag that applies to multiple commands -if [ ! -z ${ROBOT_HELM_V3} ]; then - # Feature not available in v2 - - # Also test that the list of outputs matches what the helm message gives. - # This is an imperfect way of detecting if the output format list has changed, but - # the completion wasn't updated to match. - outputFormats=$(helm repo list -h | grep -- --output | cut -d: -f2 | cut -d '(' -f1 | sed s/,//g) - _completionTests_verifyCompletion "helm repo list --output " "${outputFormats}" - _completionTests_verifyCompletion "helm install --output " "${outputFormats}" - _completionTests_verifyCompletion "helm history -o " "${outputFormats}" - _completionTests_verifyCompletion "helm list -o " "${outputFormats}" -fi - -# For completing specification of charts -if [ ! -z ${ROBOT_HELM_V3} ]; then - tmpFiles="zztest2file files" - touch $tmpFiles - - _completionTests_verifyCompletion "helm show values " "./ / zztest1/ zztest2/ stable/ file:// http:// https://" - _completionTests_verifyCompletion "helm show values ht" "http:// https://" - _completionTests_verifyCompletion "helm show values zz" "zztest1/ zztest2/ zztest2file" - _completionTests_verifyCompletion "helm show values zztest2" "zztest2/ zztest2file" - _completionTests_verifyCompletion "helm show values zztest2f" "" - _completionTests_verifyCompletion "helm show values stable/yyy" "" - _completionTests_verifyCompletion "helm show values stable/z" "stable/zeppelin stable/zetcd" - _completionTests_verifyCompletion "helm show values fil" "file:// files" - - _completionTests_verifyCompletion "helm show chart zz" "zztest1/ zztest2/ zztest2file" - _completionTests_verifyCompletion "helm show readme zz" "zztest1/ zztest2/ zztest2file" - _completionTests_verifyCompletion "helm show values zz" "zztest1/ zztest2/ zztest2file" - - _completionTests_verifyCompletion "helm pull " "zztest1/ zztest2/ stable/ file:// http:// https://" - _completionTests_verifyCompletion "helm pull zz" "zztest1/ zztest2/" - - _completionTests_verifyCompletion "helm install name " "./ / zztest1/ zztest2/ stable/ file:// http:// https://" - _completionTests_verifyCompletion "helm install name zz" "zztest1/ zztest2/ zztest2file" - _completionTests_verifyCompletion "helm install name stable/z" "stable/zeppelin stable/zetcd" - - _completionTests_verifyCompletion "helm template name " "./ / zztest1/ zztest2/ stable/ file:// http:// https://" - _completionTests_verifyCompletion "helm template name zz" "zztest1/ zztest2/ zztest2file" - _completionTests_verifyCompletion "helm template name stable/z" "stable/zeppelin stable/zetcd" - - _completionTests_verifyCompletion "helm upgrade release " "./ / zztest1/ zztest2/ stable/ file:// http:// https://" - _completionTests_verifyCompletion "helm upgrade release zz" "zztest1/ zztest2/ zztest2file" - _completionTests_verifyCompletion "helm upgrade release stable/z" "stable/zeppelin stable/zetcd" - - _completionTests_verifyCompletion "helm show values stab" "stable/ stable/." - - \rm $tmpFiles -fi - -# Dynamic completion for plugins -_completionTests_verifyCompletion "helm 2to3 move config g" "gryffindor" -_completionTests_verifyCompletion "helm 2to3 -n dumbledore convert " "case-ns convert dumbledore" -_completionTests_verifyCompletion "helm 2to3 convert -s flag d" "dobby draco" -_completionTests_verifyCompletion "helm 2to3 convert " "hermione harry ron" -_completionTests_verifyCompletion "helm push-artifactory move config g" "gryffindor" -_completionTests_verifyCompletion "helm push-artifactory -n dumbledore convert " "case-ns convert dumbledore" -_completionTests_verifyCompletion "helm push-artifactory convert -s flag d" "dobby draco" -_completionTests_verifyCompletion "helm push-artifactory convert " "hermione harry ron" - -############################################################## -# Completion with helm called through an alias or using a path -############################################################## - -# We want to specify a different helm for completion than the one -# that is found on the PATH variable. -# This is particularly valuable to check that dynamic completion -# uses the correct location for helm. - -# Copy helm to a location that is not on PATH -TMP_HELM_DIR=$(mktemp -d ${ROBOT_OUTPUT_DIR}/helm-acceptance-temp-bin.XXXXXX) -trap "rm -rf ${TMP_HELM_DIR}" EXIT - -mkdir -p $TMP_HELM_DIR -HELM_DIR=$(dirname $(which helm)) -cp $HELM_DIR/helm $TMP_HELM_DIR/helm - -# Make 'helm' unavailable to make sure it can't be called direactly -# by the dynamic completion code, which should instead use the helm -# as called in the completion calls that follow. -alias helm=echo - -# Testing with shell aliases is only applicable to bash. -# Zsh replaces the alias before calling the completion function, -# so it does not make sense to try zsh completion with an alias. -if [ "$SHELL_TYPE" = bash ]; then - - # Create aliases to helm - # This alias will be created after the variable is expanded - alias helmAlias="${TMP_HELM_DIR}/helm" - # This alias will be created without expanding the variable (because of single quotes) - alias helmAliasWithVar='${TMP_HELM_DIR}/helm' - - # Hook these new aliases to the helm completion function. - complete -o default -F $(_completionTests_findCompletionFunction helm) helmAlias - complete -o default -F $(_completionTests_findCompletionFunction helm) helmAliasWithVar - - # Completion with normal alias - _completionTests_verifyCompletion "helmAlias lis" "list" - _completionTests_verifyCompletion "helmAlias completion z" "zsh" - _completionTests_verifyCompletion "helmAlias --kubecon" "--kubeconfig= --kubeconfig" - _completionTests_verifyCompletion "helmAlias get hooks --kubec" "--kubeconfig= --kubeconfig" - _completionTests_verifyCompletion "helmAlias repo remove zztest" "zztest1 zztest2" - _completionTests_verifyCompletion "helmAlias plugin update pus" "push push-artifactory" - _completionTests_verifyCompletion "helmAlias upgrade --kube-context d" "dev1 dev2" - # if [ ! -z ${ROBOT_HELM_V3} ]; then - # _completionTests_verifyCompletion "helmAlias --kube-context=mycontext --namespace " "braavos old-valyria yunkai" - # fi - - # Completion with alias that contains a variable - _completionTests_verifyCompletion "helmAliasWithVar lis" "list" - _completionTests_verifyCompletion "helmAliasWithVar completion z" "zsh" - _completionTests_verifyCompletion "helmAliasWithVar --kubecon" "--kubeconfig= --kubeconfig" - _completionTests_verifyCompletion "helmAliasWithVar get hooks --kubec" "--kubeconfig= --kubeconfig" - _completionTests_verifyCompletion "helmAliasWithVar repo remove zztest" "zztest1 zztest2" - _completionTests_verifyCompletion "helmAliasWithVar plugin update pus" "push push-artifactory" - _completionTests_verifyCompletion "helmAliasWithVar upgrade --kube-context d" "dev1 dev2" - # if [ ! -z ${ROBOT_HELM_V3} ]; then - # _completionTests_verifyCompletion "helmAliasWithVar --kube-context=mycontext --namespace " "braavos old-valyria yunkai" - # fi -fi - -# Completion with absolute path -_completionTests_verifyCompletion "$TMP_HELM_DIR/helm lis" "list" -_completionTests_verifyCompletion "$TMP_HELM_DIR/helm completion z" "zsh" -_completionTests_verifyCompletion "$TMP_HELM_DIR/helm repo remove zztest" "zztest1 zztest2" -_completionTests_verifyCompletion "$TMP_HELM_DIR/helm plugin update pus" "push push-artifactory" -_completionTests_verifyCompletion "$TMP_HELM_DIR/helm upgrade --kube-context d" "dev1 dev2" -# if [ ! -z ${ROBOT_HELM_V3} ]; then -# _completionTests_verifyCompletion "$TMP_HELM_DIR/helm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" -# fi -if [ "$SHELL_TYPE" = bash ]; then - _completionTests_verifyCompletion "$TMP_HELM_DIR/helm --kubecon" "--kubeconfig= --kubeconfig" - _completionTests_verifyCompletion "$TMP_HELM_DIR/helm get hooks --kubec" "--kubeconfig= --kubeconfig" -else - _completionTests_verifyCompletion "$TMP_HELM_DIR/helm --kubecon" "--kubeconfig --kubeconfig --kubeconfig" - _completionTests_verifyCompletion "$TMP_HELM_DIR/helm get hooks --kubec" "--kubeconfig --kubeconfig --kubeconfig" -fi - -# Completion with relative path -cd $TMP_HELM_DIR -_completionTests_verifyCompletion "./helm lis" "list" -_completionTests_verifyCompletion "./helm completion z" "zsh" -_completionTests_verifyCompletion "./helm repo remove zztest" "zztest1 zztest2" -_completionTests_verifyCompletion "./helm plugin update pus" "push push-artifactory" -_completionTests_verifyCompletion "./helm upgrade --kube-context d" "dev1 dev2" -# if [ ! -z ${ROBOT_HELM_V3} ]; then -# _completionTests_verifyCompletion "./helm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" -# fi -if [ "$SHELL_TYPE" = bash ]; then - _completionTests_verifyCompletion "./helm --kubecon" "--kubeconfig= --kubeconfig" - _completionTests_verifyCompletion "./helm get hooks --kubec" "--kubeconfig= --kubeconfig" -else - _completionTests_verifyCompletion "./helm --kubecon" "--kubeconfig --kubeconfig --kubeconfig" - _completionTests_verifyCompletion "./helm get hooks --kubec" "--kubeconfig --kubeconfig --kubeconfig" -fi -cd - >/dev/null - -# Completion with a different name for helm -mv $TMP_HELM_DIR/helm $TMP_HELM_DIR/myhelm - -# Generating the completion script using the new binary name -# should make completion work for that binary name -source /dev/stdin <<- EOF - $(${TMP_HELM_DIR}/myhelm completion $SHELL_TYPE) -EOF -_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm lis" "list" -_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm completion z" "zsh" -_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm repo remove zztest" "zztest1 zztest2" -_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm plugin update pus" "push push-artifactory" -_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm upgrade --kube-context d" "dev1 dev2" -# if [ ! -z ${ROBOT_HELM_V3} ]; then -# _completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" -# fi -if [ "$SHELL_TYPE" = bash ]; then - _completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm --kubecon" "--kubeconfig= --kubeconfig" - _completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm get hooks --kubec" "--kubeconfig= --kubeconfig" -else - _completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm --kubecon" "--kubeconfig --kubeconfig --kubeconfig" - _completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm get hooks --kubec" "--kubeconfig --kubeconfig --kubeconfig" -fi - -# Completion with a different name for helm that is on PATH -mv $TMP_HELM_DIR/myhelm $HELM_DIR/myhelm -_completionTests_verifyCompletion "myhelm lis" "list" -_completionTests_verifyCompletion "myhelm completion z" "zsh" -_completionTests_verifyCompletion "myhelm repo remove zztest" "zztest1 zztest2" -_completionTests_verifyCompletion "myhelm plugin update pus" "push push-artifactory" -_completionTests_verifyCompletion "myhelm upgrade --kube-context d" "dev1 dev2" -# if [ ! -z ${ROBOT_HELM_V3} ]; then -# _completionTests_verifyCompletion "myhelm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" -# fi -if [ "$SHELL_TYPE" = bash ]; then - _completionTests_verifyCompletion "myhelm --kubecon" "--kubeconfig= --kubeconfig" - _completionTests_verifyCompletion "myhelm get hooks --kubec" "--kubeconfig= --kubeconfig" -else - _completionTests_verifyCompletion "myhelm --kubecon" "--kubeconfig --kubeconfig --kubeconfig" - _completionTests_verifyCompletion "myhelm get hooks --kubec" "--kubeconfig --kubeconfig --kubeconfig" -fi -unalias helm - -# This must be the last call. It allows to exit with an exit code -# that reflects the final status of all the tests. -_completionTests_exit diff --git a/scripts/completion-tests/completionTests.zsh b/scripts/completion-tests/completionTests.zsh new file mode 100755 index 0000000..bf1aa63 --- /dev/null +++ b/scripts/completion-tests/completionTests.zsh @@ -0,0 +1,144 @@ +#!bash +# +# Copyright The Helm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +##################### +# Static completions +##################### + +# Completion of flags +_completionTests_verifyCompletion "helm --kube-con" "--kube-context --kube-context --kube-context" +_completionTests_verifyCompletion "helm --kubecon" "--kubeconfig --kubeconfig --kubeconfig" +_completionTests_verifyCompletion "helm --v" "--v --vmodule --v --vmodule --v --vmodule" +_completionTests_verifyCompletion "helm --name" "--namespace --namespace --namespace" +_completionTests_verifyCompletion "helm --s" "--skip-headers --skip-log-headers --stderrthreshold --stderrthreshold --stderrthreshold" +_completionTests_verifyCompletion "helm show --s" "--skip-headers --skip-log-headers --stderrthreshold --stderrthreshold --stderrthreshold" +_completionTests_verifyCompletion "helm get hooks --kubec" "--kubeconfig --kubeconfig --kubeconfig" +_completionTests_verifyCompletion "helm get --name" "--namespace --namespace --namespace" + +##################### +# Dynamic completions +##################### + +# For the global --kube-context flag +_completionTests_verifyCompletion "helm --kube-context=" "--kube-context=dev1 --kube-context=dev2 --kube-context=accept --kube-context=prod" + +# Make sure completion works as expected when there are no repositories configured +TMP=$XDG_CONFIG_HOME +XDG_CONFIG_HOME='/invalid/path' _completionTests_verifyCompletion "helm repo remove " "" +XDG_CONFIG_HOME=$TMP + +# Make sure completion works as expected when there are no plugins +TMP=$XDG_DATA_HOME +XDG_DATA_HOME='/invalid/path' _completionTests_verifyCompletion "helm plugin uninstall " "" +XDG_DATA_HOME=$TMP + +# Dynamic completion for plugins +_completionTests_verifyCompletion "helm 2to3 move config g" "gryffindor" +_completionTests_verifyCompletion "helm 2to3 convert -s flag d" "dobby draco" +_completionTests_verifyCompletion "helm push-artifactory move config g" "gryffindor" +_completionTests_verifyCompletion "helm push-artifactory convert -s flag d" "dobby draco" + +# Now requires a real cluster +# _completionTests_verifyCompletion "helm --namespace=" "--namespace=casterly-rock --namespace=white-harbor --namespace=winterfell" +# _completionTests_verifyCompletion "helm --namespace=w" "--namespace=white-harbor --namespace=winterfell" +# _completionTests_verifyCompletion "helm upgrade --namespace=w" "--namespace=white-harbor --namespace=winterfell" +# _completionTests_verifyCompletion "helm upgrade --namespace=" "--namespace=casterly-rock --namespace=white-harbor --namespace=winterfell" +# _completionTests_verifyCompletion "helm -n=" "-n=casterly-rock -n=white-harbor -n=winterfell" +# _completionTests_verifyCompletion "helm -n=w" "-n=white-harbor -n=winterfell" +# _completionTests_verifyCompletion "helm upgrade -n=w" "-n=white-harbor -n=winterfell" +# _completionTests_verifyCompletion "helm upgrade -n=" "-n=casterly-rock -n=white-harbor -n=winterfell" + +############################################################## +# Completion with helm called through an alias or using a path +############################################################## + +# We want to specify a different helm for completion than the one +# that is found on the PATH variable. +# This is particularly valuable to check that dynamic completion +# uses the correct location for helm. + +# Copy helm to a location that is not on PATH +TMP_HELM_DIR=$(mktemp -d ${ROBOT_OUTPUT_DIR}/helm-acceptance-temp-bin.XXXXXX) +trap "rm -rf ${TMP_HELM_DIR}" EXIT + +mkdir -p $TMP_HELM_DIR +HELM_DIR=$(dirname $(which helm)) +cp $HELM_DIR/helm $TMP_HELM_DIR/helm + +# Make 'helm' unavailable to make sure it can't be called directly +# by the dynamic completion code, which should instead use the helm +# as called in the completion calls that follow. +alias helm=echo + +# Testing with shell aliases is only applicable to bash. +# Zsh replaces the alias before calling the completion function, +# so it does not make sense to try zsh completion with an alias. + +# Completion with absolute path +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm lis" "list" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm completion z" "zsh" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "$TMP_HELM_DIR/helm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm --kubecon" "--kubeconfig --kubeconfig --kubeconfig" +_completionTests_verifyCompletion "$TMP_HELM_DIR/helm get hooks --kubec" "--kubeconfig --kubeconfig --kubeconfig" + +# Completion with relative path +cd $TMP_HELM_DIR +_completionTests_verifyCompletion "./helm lis" "list" +_completionTests_verifyCompletion "./helm completion z" "zsh" +_completionTests_verifyCompletion "./helm repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "./helm plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "./helm upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "./helm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" +_completionTests_verifyCompletion "./helm --kubecon" "--kubeconfig --kubeconfig --kubeconfig" +_completionTests_verifyCompletion "./helm get hooks --kubec" "--kubeconfig --kubeconfig --kubeconfig" + +cd - >/dev/null + +# Completion with a different name for helm +mv $TMP_HELM_DIR/helm $TMP_HELM_DIR/myhelm + +# Generating the completion script using the new binary name +# should make completion work for that binary name +source <(${TMP_HELM_DIR}/myhelm completion zsh) + +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm lis" "list" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm completion z" "zsh" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm --kubecon" "--kubeconfig --kubeconfig --kubeconfig" +_completionTests_verifyCompletion "$TMP_HELM_DIR/myhelm get hooks --kubec" "--kubeconfig --kubeconfig --kubeconfig" + +# Completion with a different name for helm that is on PATH +mv $TMP_HELM_DIR/myhelm $HELM_DIR/myhelm +_completionTests_verifyCompletion "myhelm lis" "list" +_completionTests_verifyCompletion "myhelm completion z" "zsh" +_completionTests_verifyCompletion "myhelm repo remove zztest" "zztest1 zztest2" +_completionTests_verifyCompletion "myhelm plugin update pus" "push push-artifactory" +_completionTests_verifyCompletion "myhelm upgrade --kube-context d" "dev1 dev2" +#_completionTests_verifyCompletion "myhelm --kube-context=mycontext --namespace " "braavos old-valyria yunkai" +_completionTests_verifyCompletion "myhelm --kubecon" "--kubeconfig --kubeconfig --kubeconfig" +_completionTests_verifyCompletion "myhelm get hooks --kubec" "--kubeconfig --kubeconfig --kubeconfig" + +unalias helm + +# This must be the last call. It allows to exit with an exit code +# that reflects the final status of all the tests. +_completionTests_exit diff --git a/scripts/completion-tests/lib/completionTests-base.sh b/scripts/completion-tests/run-completionTests-common.sh similarity index 83% rename from scripts/completion-tests/lib/completionTests-base.sh rename to scripts/completion-tests/run-completionTests-common.sh index 8ca3f52..2ec0b24 100755 --- a/scripts/completion-tests/lib/completionTests-base.sh +++ b/scripts/completion-tests/run-completionTests-common.sh @@ -33,6 +33,11 @@ # # _completionTests_verifyCompletion "helm stat" "status" # +# Don't use the new source <() form as it does not work with bash v3 +source /dev/stdin <<- EOF + $(helm completion ${SHELL_TYPE}) +EOF + # Global variable to keep track of if a test has failed. _completionTests_TEST_FAILED=0 @@ -167,35 +172,3 @@ _completionTests_exit() { compopt() { : } - -# Start of script -SHELL_TYPE=bash -if [ ! -z "$BASH_VERSION" ];then - echo "====================================================" - echo "Running completions tests on $(uname) with bash $BASH_VERSION" - echo "====================================================" - - # Enable aliases to work even though we are in a script (non-interactive shell). - # This allows to test completion with aliases. - # Only needed for bash, zsh does this automatically. - shopt -s expand_aliases - - bashCompletionScript="/usr/share/bash-completion/bash_completion" - if [ $(uname) = "Darwin" ]; then - bashCompletionScript="/usr/local/etc/bash_completion" - fi - - source ${bashCompletionScript} -else - SHELL_TYPE=zsh - - echo "====================================================" - echo "Running completions tests on $(uname) with zsh $ZSH_VERSION" - echo "====================================================" - autoload -Uz compinit - compinit - # When zsh calls real completion, it sets some options and emulates sh. - # We need to do the same. - emulate -L sh - setopt kshglob noshglob braceexpand -fi diff --git a/scripts/completion-tests/run-completionTests.bash b/scripts/completion-tests/run-completionTests.bash new file mode 100755 index 0000000..eb80b56 --- /dev/null +++ b/scripts/completion-tests/run-completionTests.bash @@ -0,0 +1,36 @@ +#!zsh +# +# Copyright The Helm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +echo "====================================================" +echo "Running completions tests on $(uname) with bash $BASH_VERSION" +echo "====================================================" + +# Enable aliases to work even though we are in a script (non-interactive shell). +# This allows to test completion with aliases. +# Only needed for bash, zsh does this automatically. +shopt -s expand_aliases + +bashCompletionScript="/usr/share/bash-completion/bash_completion" +if [ $(uname) = "Darwin" ]; then + bashCompletionScript="/usr/local/etc/bash_completion" +fi + +source ${bashCompletionScript} + +source ${COMP_DIR}/run-completionTests-common.sh +source ${COMP_DIR}/completionTests-common.sh +source ${COMP_DIR}/completionTests.bash \ No newline at end of file diff --git a/scripts/completion-tests/run-completionTests.fish b/scripts/completion-tests/run-completionTests.fish new file mode 100755 index 0000000..983414f --- /dev/null +++ b/scripts/completion-tests/run-completionTests.fish @@ -0,0 +1,92 @@ +#!bash +# +# Copyright The Helm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +echo "====================================================" +echo Running completions tests on (uname) with fish $version +echo "====================================================" + +# Global variable to keep track of if a test has failed. +set -g _completionTests_TEST_FAILED 0 + +# Must set the path again for Fish as the path gets modified when the shell starts +set PATH $COMP_DIR/bin:$PATH + +# Run completion and indicate success or failure. +# $1 is the command line that should be completed +# $2 is the expected result of the completion +# If $1 = KFAIL indicates a Known failure +# $1 = BFAIL indicates a Known failure only for bash +# $1 = ZFAIL indicates a Known failure only for zsh +function _completionTests_verifyCompletion + set cmdLine $argv[1] + set expected $argv[2] + set currentFailure 0 + + set --global __helm_comp_commandLine "$cmdLine" + __helm_prepare_completions + + set result $__helm_comp_results + + set result (_completionTests_sort "$result") + set expected (_completionTests_sort "$expected") + + set resultOut "$result" + if test (string length -- "$result") -gt 50 + set resultOut (string sub --length 50 -- $result) "" + end + + if test "$result" = "$expected" + echo "SUCCESS: \"$cmdLine\" completes to \"$resultOut\"" + else + set _completionTests_TEST_FAILED 1 + set currentFailure 1 + echo "ERROR: \"$cmdLine\" should complete to \"$expected\" but we got \"$result\"" + end + + return $currentFailure +end + +function _completionTests_disable_sort + set -g _completionTests_DISABLE_SORT 1 +end + +function _completionTests_enable_sort + set -e _completionTests_DISABLE_SORT +end + +function _completionTests_sort + if test -n "$_completionTests_DISABLE_SORT" + # We use printf instead of echo as the $1 could be -n which would be + # interpreted as an argument to echo + printf "%s\n" "$argv[1]" + else + # We use printf instead of echo as the $1 could be -n which would be + # interpreted as an argument to echo + printf "%s\n" "$argv[1]" | sed -e 's/^ *//' -e 's/ *$//' | tr ' ' '\n' | sort -n | tr '\n' ' ' + end +end + +function _completionTests_exit + # Return the global result each time. This allows for the very last call to + # this method to return the correct success or failure code for the entire script + return $_completionTests_TEST_FAILED +end + +helm completion fish --no-descriptions | source + +source $COMP_DIR/completionTests-common.sh +source $COMP_DIR/completionTests.fish diff --git a/scripts/completion-tests/run-completionTests.zsh b/scripts/completion-tests/run-completionTests.zsh new file mode 100755 index 0000000..ef2fee3 --- /dev/null +++ b/scripts/completion-tests/run-completionTests.zsh @@ -0,0 +1,30 @@ +#!zsh +# +# Copyright The Helm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +echo "====================================================" +echo "Running completions tests on $(uname) with zsh $ZSH_VERSION" +echo "====================================================" +autoload -Uz compinit +compinit +# When zsh calls real completion, it sets some options and emulates sh. +# We need to do the same. +emulate -L sh +setopt kshglob noshglob braceexpand + +source ${COMP_DIR}/run-completionTests-common.sh +source ${COMP_DIR}/completionTests-common.sh +source ${COMP_DIR}/completionTests.zsh \ No newline at end of file diff --git a/scripts/completion-tests/setup-completion.sh b/scripts/completion-tests/setup-completion.sh new file mode 100755 index 0000000..6731e3e --- /dev/null +++ b/scripts/completion-tests/setup-completion.sh @@ -0,0 +1,315 @@ +#!/usr/bin/env bash +# +# Copyright The Helm Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This script tests different scenarios of completion. The tests can be +# run by sourcing this file from a bash shell or a zsh shell. + +export SHELL_TYPE=$1 +case "$SHELL_TYPE" in +bash|zsh|fish) + ;; +"") + echo "Missing parameter for shell to test" + exit 1 + ;; +*) + echo "Invalid shell to test: $SHELL_TYPE" + exit 1 + ;; +esac + +export PATH=${COMP_DIR}/bin:$PATH + +# Use the memory driver with pre-defined releases to easily +# test release name completion +export HELM_DRIVER=memory +export HELM_MEMORY_DRIVER_DATA=${COMP_DIR}/releases.yaml + +# Helm setup +if [ ! -z ${ROBOT_HELM_V3} ]; then + export XDG_CACHE_HOME=${COMP_DIR}/cache && rm -rf ${XDG_CACHE_HOME} && mkdir -p ${XDG_CACHE_HOME} + export XDG_CONFIG_HOME=${COMP_DIR}/config && rm -rf ${XDG_CONFIG_HOME} && mkdir -p ${XDG_CONFIG_HOME} + export XDG_DATA_HOME=${COMP_DIR}/data && rm -rf ${XDG_DATA_HOME} && mkdir -p ${XDG_DATA_HOME} + + REPO_ROOT=${XDG_CONFIG_HOME}/helm + PLUGIN_ROOT=${XDG_DATA_HOME}/helm/plugins +else + export HELM_HOME=${COMP_DIR}/.helm && rm -rf ${HELM_HOME} && mkdir -p ${HELM_HOME} + helm init --client-only + + REPO_ROOT=${HELM_HOME}/repository + PLUGIN_ROOT=${HELM_HOME}/plugins +fi + +############################################################## +# REPOS SETUP +############################################################## + +# Setup some repos to allow testing completion of the helm repo command +# We inject the content of the repositories.yaml file directly to avoid requiring +# an internet connection if we were to use 'helm repo add' +mkdir -p ${REPO_ROOT} +cat > ${REPO_ROOT}/repositories.yaml << EOF +apiVersion: v1 +generated: "2019-08-11T22:28:44.841141-04:00" +repositories: +- name: stable + url: https://kubernetes-charts.storage.googleapis.com +- name: zztest1 + url: https://charts.example.com +- name: zztest2 + url: https://charts2.example.com +EOF +helm repo list +# Fetch the details of the stable repo +helm repo update + +############################################################## +# PLUGINS SETUP +############################################################## + +# Setup some plugins to allow testing completion of the helm plugin command +# We inject the content of different plugin.yaml files directly to avoid having +# to install a real plugin which can take a long time. + +########### +# Plugin 1 +########### +PLUGIN_DIR=${PLUGIN_ROOT}/helm-2to3 +mkdir -p ${PLUGIN_DIR} +# The plugin file +cat > ${PLUGIN_DIR}/plugin.yaml << EOF +name: "2to3" +version: "2.5.1+2" +description: "Migrate from helm v2 to helm v3" +EOF + +# The plugin's static completion file +cat > ${PLUGIN_DIR}/completion.yaml << EOF +commands: +- name: cleanup + flags: + - r + - label + - cleanup + - s + - storage +- name: convert + flags: + - l + - label + - s + - storage + - t +- name: move + commands: + - name: config + flags: + - dry-run +EOF + +# The plugin's dynamic completion file +cat > ${PLUGIN_DIR}/plugin.complete << EOF +#!/usr/bin/env sh + +if [ "\$2" = "config" ]; then + echo case-config + echo gryffindor + echo slytherin + echo ravenclaw + echo hufflepuff + echo :0 + exit +fi + +if [ "\$HELM_NAMESPACE" != "default" ]; then + echo case-ns + # Check the namespace flag is not passed + echo \$1 + # Check plugin variables are set + echo \$HELM_NAMESPACE + echo :4 + exit +fi + +if [ "\$2" = -s ]; then + echo case-flag + echo lucius + echo draco + echo dobby + echo :4 + exit +fi + +# Check missing directive +echo hermione +echo harry +echo ron +EOF +chmod u+x ${PLUGIN_DIR}/plugin.complete + +########### +# Plugin 2 +########### +PLUGIN_DIR=${PLUGIN_ROOT}/helm-push +mkdir -p ${PLUGIN_DIR} +# The plugin file +cat > ${PLUGIN_DIR}/plugin.yaml << EOF +name: "push" +version: "0.7.1" +description: "Push chart package to ChartMuseum" +EOF + +# A plugin's static completion file without a dynamic completion file +cat > ${PLUGIN_DIR}/completion.yaml << EOF +commands: +- name: cleanup + flags: + - r + - label + - cleanup + - s + - storage +- name: convert + flags: + - l + - label + - s + - storage + - t +- name: move + commands: + - name: config + flags: + - dry-run +EOF + +########### +# Plugin 3 +########### +PLUGIN_DIR=${PLUGIN_ROOT}/helm-push-artifactory +mkdir -p ${PLUGIN_DIR} +# The plugin file +cat > ${PLUGIN_DIR}/plugin.yaml << EOF +name: "push-artifactory" +version: "0.3.0" +description: "Push helm charts to artifactory" +EOF + +# A plugin's dynamic completion file without a static completion file +cat > ${PLUGIN_DIR}/plugin.complete << EOF +#!/usr/bin/env sh + +if [ "\$2" = "config" ]; then + echo case-config + echo gryffindor + echo slytherin + echo ravenclaw + echo hufflepuff + echo :0 + exit +fi + +if [ "\$HELM_NAMESPACE" != "default" ]; then + echo case-ns + # Check the namespace flag is not passed + echo \$1 + # Check plugin variables are set + echo \$HELM_NAMESPACE + echo :4 + exit +fi + +if [ "\$2" = -s ]; then + echo case-flag + echo lucius + echo draco + echo dobby + echo :4 + exit +fi + +# Check missing directive +echo hermione +echo harry +echo ron +EOF +chmod u+x ${PLUGIN_DIR}/plugin.complete + +helm plugin list + +############################################################## +# CONTEXTS SETUP +############################################################## + +# config file stubs +cat > ${COMP_DIR}/config.dev1 << EOF +kind: Config +apiVersion: v1 +contexts: +- context: + name: dev1 +current-context: dev1 +EOF +cat > ${COMP_DIR}/config.dev2 << EOF +kind: Config +apiVersion: v1 +contexts: +- context: + name: dev2 +current-context: dev2 +EOF +cat > ${COMP_DIR}/config.accept << EOF +kind: Config +apiVersion: v1 +contexts: +- context: + name: accept +current-context: accept +EOF +cat > ${COMP_DIR}/config.prod << EOF +kind: Config +apiVersion: v1 +contexts: +- context: + name: prod +current-context: prod +EOF +export KUBECONFIG=${COMP_DIR}/config.dev1:${COMP_DIR}/config.dev2:${COMP_DIR}/config.accept:${COMP_DIR}/config.prod + +export allHelmCommands="completion create dependency env 2to3 get history install lint list package plugin pull push push-artifactory repo rollback search show status template test uninstall upgrade verify version" +case "$SHELL_TYPE" in +bash|fish) + export allHelmGlobalFlags="--add-dir-header --alsologtostderr --debug --kube-apiserver --kube-apiserver= --kube-context --kube-context= --kube-token --kube-token= --kubeconfig --kubeconfig= --log-backtrace-at --log-backtrace-at= --log-dir --log-dir= --log-file --log-file-max-size --log-file-max-size= --log-file= --logtostderr --namespace --namespace= --registry-config --registry-config= --repository-cache --repository-cache= --repository-config --repository-config= --skip-headers --skip-log-headers --stderrthreshold --stderrthreshold= --v --v= --vmodule --vmodule= -n -v" + export allHelmLongFlags="--add-dir-header --alsologtostderr --debug --kube-apiserver --kube-apiserver= --kube-context --kube-context= --kube-token --kube-token= --kubeconfig --kubeconfig= --log-backtrace-at --log-backtrace-at= --log-dir --log-dir= --log-file --log-file-max-size --log-file-max-size= --log-file= --logtostderr --namespace --namespace= --registry-config --registry-config= --repository-cache --repository-cache= --repository-config --repository-config= --skip-headers --skip-log-headers --stderrthreshold --stderrthreshold= --v --v= --vmodule --vmodule=" + ;; +zsh) + export allHelmGlobalFlags="--add-dir-header --alsologtostderr --debug --kube-apiserver --kube-apiserver --kube-apiserver --kube-context --kube-context --kube-context --kube-token --kube-token --kube-token --kubeconfig --kubeconfig --kubeconfig --log-backtrace-at --log-backtrace-at --log-backtrace-at --log-dir --log-dir --log-dir --log-file --log-file --log-file --log-file-max-size --log-file-max-size --log-file-max-size --logtostderr --namespace --namespace --namespace --registry-config --registry-config --registry-config --repository-cache --repository-cache --repository-cache --repository-config --repository-config --repository-config --skip-headers --skip-log-headers --stderrthreshold --stderrthreshold --stderrthreshold --v --v --v --vmodule --vmodule --vmodule -n -v" + export allHelmLongFlags="--add-dir-header --alsologtostderr --debug --kube-apiserver --kube-apiserver --kube-apiserver --kube-context --kube-context --kube-context --kube-token --kube-token --kube-token --kubeconfig --kubeconfig --kubeconfig --log-backtrace-at --log-backtrace-at --log-backtrace-at --log-dir --log-dir --log-dir --log-file --log-file --log-file --log-file-max-size --log-file-max-size --log-file-max-size --logtostderr --namespace --namespace --namespace --registry-config --registry-config --registry-config --repository-cache --repository-cache --repository-cache --repository-config --repository-config --repository-config --skip-headers --skip-log-headers --stderrthreshold --stderrthreshold --stderrthreshold --v --v --v --vmodule --vmodule --vmodule" + ;; +esac + +case "$SHELL_TYPE" in +bash) + bash -c "source ${COMP_DIR}/run-completionTests.bash" + ;; +zsh) + zsh -c "source ${COMP_DIR}/run-completionTests.zsh" + ;; +fish) + fish -c "source ${COMP_DIR}/run-completionTests.fish" + ;; +esac diff --git a/scripts/completion-tests/test-completion.sh b/scripts/completion-tests/test-completion.sh index a7cfdc2..fa1e02b 100755 --- a/scripts/completion-tests/test-completion.sh +++ b/scripts/completion-tests/test-completion.sh @@ -48,14 +48,24 @@ fi export COMP_DIR=$(mktemp -d ${ROBOT_OUTPUT_DIR}/helm-acceptance-completion.XXXXXX) trap "rm -rf ${COMP_DIR}" EXIT -COMP_SCRIPT_NAME=completionTests.sh +COMP_SCRIPT_NAME=setup-completion.sh COMP_SCRIPT=${COMP_DIR}/${COMP_SCRIPT_NAME} rm -rf ${COMP_DIR} mkdir -p ${COMP_DIR}/lib mkdir -p ${COMP_DIR}/bin cp ${SCRIPT_DIR}/${COMP_SCRIPT_NAME} ${COMP_DIR} -cp ${SCRIPT_DIR}/lib/completionTests-base.sh ${COMP_DIR}/lib + +cp ${SCRIPT_DIR}/run-completionTests-common.sh ${COMP_DIR} +cp ${SCRIPT_DIR}/run-completionTests.bash ${COMP_DIR} +cp ${SCRIPT_DIR}/run-completionTests.zsh ${COMP_DIR} +cp ${SCRIPT_DIR}/run-completionTests.fish ${COMP_DIR} + +cp ${SCRIPT_DIR}/completionTests-common.sh ${COMP_DIR} +cp ${SCRIPT_DIR}/completionTests.bash ${COMP_DIR} +cp ${SCRIPT_DIR}/completionTests.zsh ${COMP_DIR} +cp ${SCRIPT_DIR}/completionTests.fish ${COMP_DIR} + cp ${SCRIPT_DIR}/releases.yaml ${COMP_DIR} if [[ "${GITHUB_SHA}" == "" ]]; then @@ -92,7 +102,7 @@ docker run --rm \ -e ROBOT_HELM_V3=${ROBOT_HELM_V3} \ -e ROBOT_DEBUG_LEVEL=${ROBOT_DEBUG_LEVEL} \ -e COMP_DIR=${COMP_DIR} \ - ${BASH4_IMAGE} bash -c "source ${COMP_SCRIPT}" + ${BASH4_IMAGE} ${COMP_SCRIPT} bash ######################################## # Bash 3.2 completion tests @@ -117,7 +127,7 @@ docker run --rm \ -e ROBOT_HELM_V3=${ROBOT_HELM_V3} \ -e ROBOT_DEBUG_LEVEL=${ROBOT_DEBUG_LEVEL} \ -e COMP_DIR=${COMP_DIR} \ - ${BASH3_IMAGE} bash -c "source ${COMP_SCRIPT}" + ${BASH3_IMAGE} ${COMP_SCRIPT} bash ######################################## # Bash centos completion tests @@ -135,7 +145,7 @@ docker run --rm \ -e ROBOT_HELM_V3=${ROBOT_HELM_V3} \ -e ROBOT_DEBUG_LEVEL=${ROBOT_DEBUG_LEVEL} \ -e COMP_DIR=${COMP_DIR} \ - ${BASH_IMAGE} bash -c "source ${COMP_SCRIPT}" + ${BASH_IMAGE} ${COMP_SCRIPT} bash ######################################## # Zsh completion tests @@ -153,7 +163,7 @@ docker run --rm \ -e ROBOT_HELM_V3=${ROBOT_HELM_V3} \ -e ROBOT_DEBUG_LEVEL=${ROBOT_DEBUG_LEVEL} \ -e COMP_DIR=${COMP_DIR} \ - ${ZSH_IMAGE} zsh -c "source ${COMP_SCRIPT}" + ${ZSH_IMAGE} ${COMP_SCRIPT} zsh ######################################## # Zsh alpine/busybox completion tests @@ -164,14 +174,32 @@ ZSH_IMAGE=completion-zsh-alpine echo;echo; docker build -t ${ZSH_IMAGE} - <<- EOF FROM alpine - RUN apk update && apk add zsh ca-certificates + RUN apk update && apk add bash zsh ca-certificates EOF docker run --rm \ -v ${COMP_DIR}:${COMP_DIR} \ -e ROBOT_HELM_V3=${ROBOT_HELM_V3} \ -e ROBOT_DEBUG_LEVEL=${ROBOT_DEBUG_LEVEL} \ -e COMP_DIR=${COMP_DIR} \ - ${ZSH_IMAGE} zsh -c "source ${COMP_SCRIPT}" + ${ZSH_IMAGE} ${COMP_SCRIPT} zsh + +######################################## +# Fish completion tests +######################################## +FISH_IMAGE=completion-fish + +docker build -t ${FISH_IMAGE} - <<- EOF + FROM centos + RUN cd /etc/yum.repos.d/ && \ + curl -O https://download.opensuse.org/repositories/shells:/fish/CentOS_8/shells:fish.repo && \ + yum install -y fish which +EOF +docker run --rm \ + -v ${COMP_DIR}:${COMP_DIR} \ + -e ROBOT_HELM_V3=${ROBOT_HELM_V3} \ + -e ROBOT_DEBUG_LEVEL=${ROBOT_DEBUG_LEVEL} \ + -e COMP_DIR=${COMP_DIR} \ + ${FISH_IMAGE} ${COMP_SCRIPT} fish ######################################## # MacOS completion tests @@ -193,13 +221,19 @@ if [ "$(uname)" == "Darwin" ]; then if which bash>/dev/null && [ -f /usr/local/etc/bash_completion ]; then echo;echo; echo "Completion tests for bash running locally" - bash -c "source ${COMP_SCRIPT}" + ${COMP_SCRIPT} bash fi if which zsh>/dev/null; then echo;echo; echo "Completion tests for zsh running locally" - zsh -c "source ${COMP_SCRIPT}" + ${COMP_SCRIPT} zsh + fi + + if which fish>/dev/null; then + echo;echo; + echo "Completion tests for fish running locally" + ${COMP_SCRIPT} fish fi fi