Merge pull request #78485 from oomichi/add-use-ExpectError

Check e2e test code to use ExpectError()
This commit is contained in:
Kubernetes Prow Robot 2019-06-01 02:54:42 -07:00 committed by GitHub
commit ebdae0b3b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.'

View File

@ -175,7 +175,7 @@ var _ = SIGDescribe("Mount propagation", func() {
gomega.Expect(stdout).To(gomega.Equal(mountName), msg)
} else {
// We *expect* cat to return error here
gomega.Expect(err).To(gomega.HaveOccurred(), msg)
framework.ExpectError(err, msg)
}
}
}

View File

@ -279,7 +279,7 @@ var _ = utils.SIGDescribe("CSI mock volume", func() {
}
}
if test.disableAttach {
gomega.Expect(err).To(gomega.HaveOccurred(), "Unexpected VolumeAttachment found")
framework.ExpectError(err, "Unexpected VolumeAttachment found")
}
})
@ -449,7 +449,7 @@ var _ = utils.SIGDescribe("CSI mock volume", func() {
}
if test.expectFailure {
err = waitForResizingCondition(pvc, m.cs, csiResizingConditionWait)
gomega.Expect(err).To(gomega.HaveOccurred(), "unexpected resizing condition on PVC")
framework.ExpectError(err, "unexpected resizing condition on PVC")
return
}

View File

@ -91,7 +91,7 @@ func VerifyExecInPodFail(pod *v1.Pod, bashExec string, exitCode int) {
bashExec, exitCode, err)
}
}
gomega.Expect(err).To(gomega.HaveOccurred(), "%q should fail with exit code %d, but exit without error", bashExec, exitCode)
framework.ExpectError(err, "%q should fail with exit code %d, but exit without error", bashExec, exitCode)
}
// KubeletCommand performs `start`, `restart`, or `stop` on the kubelet running on the node of the target pod and waits

View File

@ -101,7 +101,7 @@ var _ = utils.SIGDescribe("Volume expand", func() {
ginkgo.By("Expanding non-expandable pvc")
newSize := resource.MustParse("6Gi")
pvc, err = expandPVCSize(pvc, newSize, c)
gomega.Expect(err).To(gomega.HaveOccurred(), "While updating non-expandable PVC")
framework.ExpectError(err, "While updating non-expandable PVC")
})
ginkgo.It("Verify if editing PVC allows resize", func() {