verify-test-code.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env bash
  2. # Copyright 2019 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. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
  19. cd "${KUBE_ROOT}"
  20. # NOTE: This checks e2e test code without the e2e framework which contains Expect().To(HaveOccurred())
  21. mapfile -t all_e2e_files < <(find test/e2e -name '*.go' | grep -v 'test/e2e/framework/')
  22. errors_expect_no_error=()
  23. for file in "${all_e2e_files[@]}"
  24. do
  25. if grep "Expect(.*)\.NotTo(.*HaveOccurred()" "${file}" > /dev/null
  26. then
  27. errors_expect_no_error+=( "${file}" )
  28. fi
  29. done
  30. errors_expect_error=()
  31. for file in "${all_e2e_files[@]}"
  32. do
  33. if grep "Expect(.*)\.To(.*HaveOccurred()" "${file}" > /dev/null
  34. then
  35. errors_expect_error+=( "${file}" )
  36. fi
  37. done
  38. if [ ${#errors_expect_no_error[@]} -ne 0 ]; then
  39. {
  40. echo "Errors:"
  41. for err in "${errors_expect_no_error[@]}"; do
  42. echo "$err"
  43. done
  44. echo
  45. echo 'The above files need to use framework.ExpectNoError(err) instead of '
  46. echo 'Expect(err).NotTo(HaveOccurred()) or gomega.Expect(err).NotTo(gomega.HaveOccurred())'
  47. echo
  48. } >&2
  49. exit 1
  50. fi
  51. if [ ${#errors_expect_error[@]} -ne 0 ]; then
  52. {
  53. echo "Errors:"
  54. for err in "${errors_expect_error[@]}"; do
  55. echo "$err"
  56. done
  57. echo
  58. echo 'The above files need to use framework.ExpectError(err) instead of '
  59. echo 'Expect(err).To(HaveOccurred()) or gomega.Expect(err).To(gomega.HaveOccurred())'
  60. echo
  61. } >&2
  62. exit 1
  63. fi
  64. echo 'Congratulations! All e2e test source files are valid.'