Merge pull request #78485 from oomichi/add-use-ExpectError
Check e2e test code to use ExpectError()
This commit is contained in:
		| @@ -20,7 +20,8 @@ set -o pipefail | |||||||
| KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. | KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. | ||||||
| cd "${KUBE_ROOT}" | 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=() | errors_expect_no_error=() | ||||||
| for file in "${all_e2e_files[@]}" | for file in "${all_e2e_files[@]}" | ||||||
| do | do | ||||||
| @@ -30,6 +31,15 @@ do | |||||||
|     fi |     fi | ||||||
| done | 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 | if [ ${#errors_expect_no_error[@]} -ne 0 ]; then | ||||||
|   { |   { | ||||||
|     echo "Errors:" |     echo "Errors:" | ||||||
| @@ -44,4 +54,18 @@ if [ ${#errors_expect_no_error[@]} -ne 0 ]; then | |||||||
|   exit 1 |   exit 1 | ||||||
| fi | 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.' | echo 'Congratulations!  All e2e test source files are valid.' | ||||||
|   | |||||||
| @@ -175,7 +175,7 @@ var _ = SIGDescribe("Mount propagation", func() { | |||||||
| 					gomega.Expect(stdout).To(gomega.Equal(mountName), msg) | 					gomega.Expect(stdout).To(gomega.Equal(mountName), msg) | ||||||
| 				} else { | 				} else { | ||||||
| 					// We *expect* cat to return error here | 					// We *expect* cat to return error here | ||||||
| 					gomega.Expect(err).To(gomega.HaveOccurred(), msg) | 					framework.ExpectError(err, msg) | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -279,7 +279,7 @@ var _ = utils.SIGDescribe("CSI mock volume", func() { | |||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 				if test.disableAttach { | 				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 { | 				if test.expectFailure { | ||||||
| 					err = waitForResizingCondition(pvc, m.cs, csiResizingConditionWait) | 					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 | 					return | ||||||
| 				} | 				} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -91,7 +91,7 @@ func VerifyExecInPodFail(pod *v1.Pod, bashExec string, exitCode int) { | |||||||
| 				bashExec, exitCode, err) | 				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 | // KubeletCommand performs `start`, `restart`, or `stop` on the kubelet running on the node of the target pod and waits | ||||||
|   | |||||||
| @@ -101,7 +101,7 @@ var _ = utils.SIGDescribe("Volume expand", func() { | |||||||
| 		ginkgo.By("Expanding non-expandable pvc") | 		ginkgo.By("Expanding non-expandable pvc") | ||||||
| 		newSize := resource.MustParse("6Gi") | 		newSize := resource.MustParse("6Gi") | ||||||
| 		pvc, err = expandPVCSize(pvc, newSize, c) | 		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() { | 	ginkgo.It("Verify if editing PVC allows resize", func() { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Kubernetes Prow Robot
					Kubernetes Prow Robot