run.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_kubectl_run_tests() {
  19. set -o nounset
  20. set -o errexit
  21. create_and_use_new_namespace
  22. kube::log::status "Testing kubectl run"
  23. # Command with dry-run
  24. kubectl run --dry-run=client nginx-extensions "--image=${IMAGE_NGINX}" "${kube_flags[@]:?}"
  25. kubectl run --dry-run=server nginx-extensions "--image=${IMAGE_NGINX}" "${kube_flags[@]:?}"
  26. # Post-Condition: no Pod exists
  27. kube::test::get_object_assert pods "{{range.items}}{{${id_field:?}}}:{{end}}" ''
  28. # Pre-Condition: no Pod exists
  29. kube::test::get_object_assert pods "{{range.items}}{{${id_field:?}}}:{{end}}" ''
  30. # Command
  31. kubectl run nginx-extensions "--image=${IMAGE_NGINX}" "${kube_flags[@]:?}"
  32. # Post-Condition: Pod "nginx" is created
  33. kube::test::get_object_assert pod "{{range.items}}{{$id_field}}:{{end}}" 'nginx-extensions:'
  34. # Clean up
  35. kubectl delete pod nginx-extensions "${kube_flags[@]}"
  36. # Test that a valid image reference value is provided as the value of --image in `kubectl run <name> --image`
  37. output_message=$(kubectl run test1 --image=validname)
  38. kube::test::if_has_string "${output_message}" 'pod/test1 created'
  39. kubectl delete pods test1
  40. # test invalid image name
  41. output_message=$(! kubectl run test2 --image=InvalidImageName 2>&1)
  42. kube::test::if_has_string "${output_message}" 'error: Invalid image name "InvalidImageName": invalid reference format'
  43. set +o nounset
  44. set +o errexit
  45. }