Check e2e test code to use ExpectError()

We can use framework.ExpectError() for checking the expected error
happens. However Expect(err).To(HaveOccurred()) can be used instead
and that makes the e2e test code unreadable.
This adds the check to use framework.ExpectError() for readable code.
This commit is contained in:
Kenichi Omichi
2019-05-29 16:39:38 +00:00
parent d8fd232ea1
commit 63e0507fd9
5 changed files with 30 additions and 6 deletions

View File

@@ -20,7 +20,8 @@ set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
cd "${KUBE_ROOT}"
mapfile -t all_e2e_files < <(find test/e2e -name '*.go')
# NOTE: This checks e2e test code without the e2e framework which contains Expect().To(HaveOccurred())
mapfile -t all_e2e_files < <(find test/e2e -name '*.go' | grep -v 'test/e2e/framework/')
errors_expect_no_error=()
for file in "${all_e2e_files[@]}"
do
@@ -30,6 +31,15 @@ do
fi
done
errors_expect_error=()
for file in "${all_e2e_files[@]}"
do
if grep "Expect(.*)\.To(.*HaveOccurred()" "${file}" > /dev/null
then
errors_expect_error+=( "${file}" )
fi
done
if [ ${#errors_expect_no_error[@]} -ne 0 ]; then
{
echo "Errors:"
@@ -44,4 +54,18 @@ if [ ${#errors_expect_no_error[@]} -ne 0 ]; then
exit 1
fi
if [ ${#errors_expect_error[@]} -ne 0 ]; then
{
echo "Errors:"
for err in "${errors_expect_error[@]}"; do
echo "$err"
done
echo
echo 'The above files need to use framework.ExpectError(err) instead of '
echo 'Expect(err).To(HaveOccurred()) or gomega.Expect(err).To(gomega.HaveOccurred())'
echo
} >&2
exit 1
fi
echo 'Congratulations! All e2e test source files are valid.'