request-timeout.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_request_timeout_tests() {
  19. set -o nounset
  20. set -o errexit
  21. kube::log::status "Testing kubectl request timeout"
  22. ### Test global request timeout option
  23. # Pre-condition: no POD exists
  24. create_and_use_new_namespace
  25. kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" ''
  26. # Command
  27. kubectl create "${kube_flags[@]}" -f test/fixtures/doc-yaml/admin/limitrange/valid-pod.yaml
  28. # Post-condition: valid-pod POD is created
  29. kubectl get "${kube_flags[@]}" pods -o json
  30. kube::test::get_object_assert pods "{{range.items}}{{$id_field}}:{{end}}" 'valid-pod:'
  31. ## check --request-timeout on 'get pod'
  32. output_message=$(kubectl get pod valid-pod --request-timeout=1)
  33. kube::test::if_has_string "${output_message}" 'valid-pod'
  34. ## check --request-timeout on 'get pod' with --watch
  35. output_message=$(kubectl get pod valid-pod --request-timeout=1 --watch 2>&1)
  36. kube::test::if_has_string "${output_message}" 'Timeout exceeded while reading body'
  37. ## check --request-timeout value with no time unit
  38. output_message=$(kubectl get pod valid-pod --request-timeout=1 2>&1)
  39. kube::test::if_has_string "${output_message}" 'valid-pod'
  40. ## check --request-timeout value with invalid time unit
  41. output_message=$(! kubectl get pod valid-pod --request-timeout="1p" 2>&1)
  42. kube::test::if_has_string "${output_message}" 'Invalid timeout value'
  43. # cleanup
  44. kubectl delete pods valid-pod "${kube_flags[@]}"
  45. set +o nounset
  46. set +o errexit
  47. }