run.sh 1.7 KB

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