Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
test: Ginkgo and Gomega update
Browse files Browse the repository at this point in the history
The new Gomega version 1.15 supports testing a function with no return
value (onsi/gomega#198 (comment)). This
makes it possible to simplify the metrics test.
  • Loading branch information
pohly committed Aug 6, 2021
1 parent 0a0e774 commit 00ad21b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ require (
github.com/kubernetes-csi/csi-test/v4 v4.2.0
github.com/miekg/dns v1.1.38 // indirect
github.com/onsi/ginkgo v1.16.4
github.com/onsi/gomega v1.13.0
github.com/onsi/gomega v1.15.0
github.com/operator-framework/operator-lib v0.4.0
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.26.0
github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40
google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea // indirect
google.golang.org/grpc v1.35.0
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/onsi/gomega v1.10.4/go.mod h1:g/HbgYopi++010VEqkFgJHKC09uJiW9UkXvMUuKHUCQ=
github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak=
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
github.com/onsi/gomega v1.13.1-0.20210610024953-2f04e6e3467d h1:xP4paM8h3wbI0mhcjOZeeRNI2HzqxIgKSMJv+brTHaE=
github.com/onsi/gomega v1.13.1-0.20210610024953-2f04e6e3467d/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
github.com/onsi/gomega v1.15.0 h1:WjP/FQ/sk43MRmnEcT+MlDw2TFvkrXlprrPST/IudjU=
github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
Expand Down Expand Up @@ -784,6 +788,8 @@ golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
41 changes: 16 additions & 25 deletions test/e2e/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var _ = deploy.Describe("direct-testing", "direct-testing-metrics", "", func(d *
pods, err := f.ClientSet.CoreV1().Pods(d.Namespace).List(context.Background(), metav1.ListOptions{})
framework.ExpectNoError(err, "list pods")

test := func() {
test := func(g Gomega) {
numPods := 0
for _, pod := range pods.Items {
if pod.Annotations["pmem-csi.intel.com/scrape"] != "containers" {
Expand All @@ -75,47 +75,38 @@ var _ = deploy.Describe("direct-testing", "direct-testing-metrics", "", func(d *

ip := pod.Status.PodIP
portNum := port.ContainerPort
Expect(ip).ToNot(BeEmpty(), "have pod IP")
Expect(portNum).ToNot(Equal(0), "have container port")
g.Expect(ip).ToNot(BeEmpty(), "have pod IP")
g.Expect(portNum).ToNot(Equal(0), "have container port")

url := fmt.Sprintf("http://%s.%s:%d/metrics",
pod.Namespace, pod.Name, port.ContainerPort)
resp, err := client.Get(url)
framework.ExpectNoError(err, "GET failed")
// 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
}
g.Expect(err).NotTo(HaveOccurred(), "GET failed")
data, err := ioutil.ReadAll(resp.Body)
framework.ExpectNoError(err, "read GET response")
g.Expect(err).NotTo(HaveOccurred(), "read GET response")
name := pod.Name + "/" + container.Name
if strings.HasPrefix(container.Name, "pmem") {
Expect(data).To(ContainSubstring("go_threads "), name)
Expect(data).To(ContainSubstring("process_open_fds "), name)
g.Expect(data).To(ContainSubstring("go_threads "), name)
g.Expect(data).To(ContainSubstring("process_open_fds "), name)
if !strings.Contains(pod.Name, "controller") {
// Only the node driver implements CSI and manages volumes.
Expect(data).To(ContainSubstring("csi_plugin_operations_seconds "), name)
Expect(data).To(ContainSubstring("pmem_amount_available "), name)
Expect(data).To(ContainSubstring("pmem_amount_managed "), name)
Expect(data).To(ContainSubstring("pmem_amount_max_volume_size "), name)
Expect(data).To(ContainSubstring("pmem_amount_total "), name)
g.Expect(data).To(ContainSubstring("csi_plugin_operations_seconds "), name)
g.Expect(data).To(ContainSubstring("pmem_amount_available "), name)
g.Expect(data).To(ContainSubstring("pmem_amount_managed "), name)
g.Expect(data).To(ContainSubstring("pmem_amount_max_volume_size "), name)
g.Expect(data).To(ContainSubstring("pmem_amount_total "), name)
}
} else {
Expect(data).To(ContainSubstring("csi_sidecar_operations_seconds "), name)
g.Expect(data).To(ContainSubstring("csi_sidecar_operations_seconds "), name)
}
}
}
}
Expect(numPorts).NotTo(Equal(0), "at least one container should have a 'metrics' port")
g.Expect(numPorts).NotTo(Equal(0), "at least one container should have a 'metrics' port")
}
Expect(numPods).NotTo(Equal(0), "at least one container should have a 'metrics' port")
g.Expect(numPods).NotTo(Equal(0), "at least one container should have a 'metrics' port")
}
Eventually(func() string {
return strings.Join(InterceptGomegaFailures(test), "\n")
}, "10s", "1s").Should(BeEmpty())
Eventually(test, "10s", "1s").Should(Succeed())
})

It("rejects large headers", func() {
Expand Down

0 comments on commit 00ad21b

Please sign in to comment.