plugins.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. # Copyright 2018 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. run_plugins_tests() {
  19. set -o nounset
  20. set -o errexit
  21. kube::log::status "Testing kubectl plugins"
  22. # test plugins that overwrite existing kubectl commands
  23. output_message=$(! PATH=${PATH}:"test/fixtures/pkg/kubectl/plugins/version" kubectl plugin list 2>&1)
  24. kube::test::if_has_string "${output_message}" 'kubectl-version overwrites existing command: "kubectl version"'
  25. # test plugins that overwrite similarly-named plugins
  26. output_message=$(! PATH=${PATH}:"test/fixtures/pkg/kubectl/plugins:test/fixtures/pkg/kubectl/plugins/foo" kubectl plugin list 2>&1)
  27. kube::test::if_has_string "${output_message}" 'test/fixtures/pkg/kubectl/plugins/foo/kubectl-foo is overshadowed by a similarly named plugin'
  28. # test plugins with no warnings
  29. output_message=$(PATH=${PATH}:"test/fixtures/pkg/kubectl/plugins" kubectl plugin list 2>&1)
  30. kube::test::if_has_string "${output_message}" 'plugins are available'
  31. # no plugins
  32. output_message=$(! PATH=${PATH}:"test/fixtures/pkg/kubectl/plugins/empty" kubectl plugin list 2>&1)
  33. kube::test::if_has_string "${output_message}" 'unable to find any kubectl plugins in your PATH'
  34. # attempt to run a plugin in the user's PATH
  35. output_message=$(PATH=${PATH}:"test/fixtures/pkg/kubectl/plugins" kubectl foo)
  36. kube::test::if_has_string "${output_message}" 'plugin foo'
  37. # ensure that a kubectl command supersedes a plugin that overshadows it
  38. output_message=$(PATH=${PATH}:"test/fixtures/pkg/kubectl/plugins/version" kubectl version)
  39. kube::test::if_has_string "${output_message}" 'Client Version'
  40. kube::test::if_has_not_string "${output_message}" 'overshadows an existing plugin'
  41. set +o nounset
  42. set +o errexit
  43. }