Skip to content

Commit

Permalink
test test: avoid panic in metrics test, II
Browse files Browse the repository at this point in the history
The root cause has been
identified (onsi/gomega#198 (comment)),
the right fix is to check for "err == nil" because the assertion alone
is not enough in this particular scenario.
  • Loading branch information
pohly committed Jun 8, 2021
1 parent f4c19e5 commit 6f7b982
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/e2e/metrics/metrics.go
Expand Up @@ -78,7 +78,13 @@ var _ = deploy.Describe("direct-testing", "direct-testing-metrics", "", func(d *
pod.Namespace, pod.Name, port.ContainerPort)
resp, err := client.Get(url)
framework.ExpectNoError(err, "GET failed")
Expect(resp.Body).NotTo(BeNil(), "have response body")
// When wrapped with InterceptGomegaFailures, err == nil doesn't
// cause the function to abort. We have to do that ourselves before
// using resp to avoid a panic.
// https://github.com/onsi/gomega/issues/198#issuecomment-856630787
if err != nil {
return
}
data, err := ioutil.ReadAll(resp.Body)
framework.ExpectNoError(err, "read GET response")
name := pod.Name + "/" + container.Name
Expand Down

0 comments on commit 6f7b982

Please sign in to comment.