e2e framework: deprecate gomega wrappers
All wrappers except for ExpectNoError are identical to their gomega counterparts. The only advantage that they have is that their invocations are shorter. That advantage does not outweigh their disadvantages: - cannot be used in combination with gomega.Eventually/Consistently - not a full replacement for gomega, so we just end up using both - don't support passing a stack offset and thus cannot be used in helper functions - ginkgolinter does not work for them, so sub-optimal calls like this one are not reported: framework.ExpectEqual(len(items), 0) -> gomega.Expect(items).To(gomega.BeEmpty()) - developers try to make do with what's available in the framework, leading to sub-optimal checks like this: framework.ExpectEqual(true, strings.Contains(event.Message, expectedEventError), "Event error should indicate non-root policy caused container to not start") -> gomega.Expect(event.Message).To(gomega.ContainSubstring(expectedEventError), "Event error should indicate non-root policy caused container to not start") So let's remove these wrappers. As a first step they get marked as deprecated. This enables stricter linting (https://github.com/kubernetes/kubernetes/pull/109728), once enabled, to report new code which uses them.
This commit is contained in:
@@ -41,33 +41,6 @@ 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
|
||||
|
||||
errors_expect_no_equal=()
|
||||
for file in "${all_e2e_files[@]}"
|
||||
do
|
||||
if grep -E "Expect\(.*\)\.(NotTo|ToNot)\((gomega\.Equal|Equal)" "${file}" > /dev/null
|
||||
then
|
||||
errors_expect_no_equal+=( "${file}" )
|
||||
fi
|
||||
done
|
||||
|
||||
errors_expect_equal=()
|
||||
for file in "${all_e2e_files[@]}"
|
||||
do
|
||||
if grep -E "Expect\(.*\)\.To\((gomega\.Equal|Equal)" "${file}" > /dev/null
|
||||
then
|
||||
errors_expect_equal+=( "${file}" )
|
||||
fi
|
||||
done
|
||||
|
||||
all_e2e_framework_files=()
|
||||
kube::util::read-array all_e2e_framework_files < <(find test/e2e/framework/ -name '*.go' | grep -v "_test.go")
|
||||
errors_framework_contains_tests=()
|
||||
@@ -93,48 +66,6 @@ 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
|
||||
|
||||
if [ ${#errors_expect_no_equal[@]} -ne 0 ]; then
|
||||
{
|
||||
echo "Errors:"
|
||||
for err in "${errors_expect_no_equal[@]}"; do
|
||||
echo "$err"
|
||||
done
|
||||
echo
|
||||
echo 'The above files need to use framework.ExpectNotEqual(foo, bar) instead of '
|
||||
echo 'Expect(foo).NotTo(Equal(bar)) or gomega.Expect(foo).NotTo(gomega.Equal(bar))'
|
||||
echo
|
||||
} >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ${#errors_expect_equal[@]} -ne 0 ]; then
|
||||
{
|
||||
echo "Errors:"
|
||||
for err in "${errors_expect_equal[@]}"; do
|
||||
echo "$err"
|
||||
done
|
||||
echo
|
||||
echo 'The above files need to use framework.ExpectEqual(foo, bar) instead of '
|
||||
echo 'Expect(foo).To(Equal(bar)) or gomega.Expect(foo).To(gomega.Equal(bar))'
|
||||
echo
|
||||
} >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ${#errors_framework_contains_tests[@]} -ne 0 ]; then
|
||||
{
|
||||
echo "Errors:"
|
||||
|
Reference in New Issue
Block a user