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

Commit 00ad21b

Browse files
committed
test: Ginkgo and Gomega update
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.
1 parent 0a0e774 commit 00ad21b

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ require (
1414
github.com/kubernetes-csi/csi-test/v4 v4.2.0
1515
github.com/miekg/dns v1.1.38 // indirect
1616
github.com/onsi/ginkgo v1.16.4
17-
github.com/onsi/gomega v1.13.0
17+
github.com/onsi/gomega v1.15.0
1818
github.com/operator-framework/operator-lib v0.4.0
1919
github.com/prometheus/client_golang v1.11.0
2020
github.com/prometheus/client_model v0.2.0
2121
github.com/prometheus/common v0.26.0
2222
github.com/stretchr/testify v1.7.0
23-
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781
23+
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d
2424
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40
2525
google.golang.org/genproto v0.0.0-20210207032614-bba0dbe2a9ea // indirect
2626
google.golang.org/grpc v1.35.0

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
523523
github.com/onsi/gomega v1.10.4/go.mod h1:g/HbgYopi++010VEqkFgJHKC09uJiW9UkXvMUuKHUCQ=
524524
github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak=
525525
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
526+
github.com/onsi/gomega v1.13.1-0.20210610024953-2f04e6e3467d h1:xP4paM8h3wbI0mhcjOZeeRNI2HzqxIgKSMJv+brTHaE=
527+
github.com/onsi/gomega v1.13.1-0.20210610024953-2f04e6e3467d/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
528+
github.com/onsi/gomega v1.15.0 h1:WjP/FQ/sk43MRmnEcT+MlDw2TFvkrXlprrPST/IudjU=
529+
github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
526530
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
527531
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
528532
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
@@ -784,6 +788,8 @@ golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v
784788
golang.org/x/net v0.0.0-20210224082022-3d97a244fca7/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
785789
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
786790
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
791+
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI=
792+
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
787793
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
788794
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
789795
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

test/e2e/metrics/metrics.go

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var _ = deploy.Describe("direct-testing", "direct-testing-metrics", "", func(d *
5959
pods, err := f.ClientSet.CoreV1().Pods(d.Namespace).List(context.Background(), metav1.ListOptions{})
6060
framework.ExpectNoError(err, "list pods")
6161

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

7676
ip := pod.Status.PodIP
7777
portNum := port.ContainerPort
78-
Expect(ip).ToNot(BeEmpty(), "have pod IP")
79-
Expect(portNum).ToNot(Equal(0), "have container port")
78+
g.Expect(ip).ToNot(BeEmpty(), "have pod IP")
79+
g.Expect(portNum).ToNot(Equal(0), "have container port")
8080

8181
url := fmt.Sprintf("http://%s.%s:%d/metrics",
8282
pod.Namespace, pod.Name, port.ContainerPort)
8383
resp, err := client.Get(url)
84-
framework.ExpectNoError(err, "GET failed")
85-
// When wrapped with InterceptGomegaFailures, err == nil doesn't
86-
// cause the function to abort. We have to do that ourselves before
87-
// using resp to avoid a panic.
88-
// https://github.com/onsi/gomega/issues/198#issuecomment-856630787
89-
if err != nil {
90-
return
91-
}
84+
g.Expect(err).NotTo(HaveOccurred(), "GET failed")
9285
data, err := ioutil.ReadAll(resp.Body)
93-
framework.ExpectNoError(err, "read GET response")
86+
g.Expect(err).NotTo(HaveOccurred(), "read GET response")
9487
name := pod.Name + "/" + container.Name
9588
if strings.HasPrefix(container.Name, "pmem") {
96-
Expect(data).To(ContainSubstring("go_threads "), name)
97-
Expect(data).To(ContainSubstring("process_open_fds "), name)
89+
g.Expect(data).To(ContainSubstring("go_threads "), name)
90+
g.Expect(data).To(ContainSubstring("process_open_fds "), name)
9891
if !strings.Contains(pod.Name, "controller") {
9992
// Only the node driver implements CSI and manages volumes.
100-
Expect(data).To(ContainSubstring("csi_plugin_operations_seconds "), name)
101-
Expect(data).To(ContainSubstring("pmem_amount_available "), name)
102-
Expect(data).To(ContainSubstring("pmem_amount_managed "), name)
103-
Expect(data).To(ContainSubstring("pmem_amount_max_volume_size "), name)
104-
Expect(data).To(ContainSubstring("pmem_amount_total "), name)
93+
g.Expect(data).To(ContainSubstring("csi_plugin_operations_seconds "), name)
94+
g.Expect(data).To(ContainSubstring("pmem_amount_available "), name)
95+
g.Expect(data).To(ContainSubstring("pmem_amount_managed "), name)
96+
g.Expect(data).To(ContainSubstring("pmem_amount_max_volume_size "), name)
97+
g.Expect(data).To(ContainSubstring("pmem_amount_total "), name)
10598
}
10699
} else {
107-
Expect(data).To(ContainSubstring("csi_sidecar_operations_seconds "), name)
100+
g.Expect(data).To(ContainSubstring("csi_sidecar_operations_seconds "), name)
108101
}
109102
}
110103
}
111104
}
112-
Expect(numPorts).NotTo(Equal(0), "at least one container should have a 'metrics' port")
105+
g.Expect(numPorts).NotTo(Equal(0), "at least one container should have a 'metrics' port")
113106
}
114-
Expect(numPods).NotTo(Equal(0), "at least one container should have a 'metrics' port")
107+
g.Expect(numPods).NotTo(Equal(0), "at least one container should have a 'metrics' port")
115108
}
116-
Eventually(func() string {
117-
return strings.Join(InterceptGomegaFailures(test), "\n")
118-
}, "10s", "1s").Should(BeEmpty())
109+
Eventually(test, "10s", "1s").Should(Succeed())
119110
})
120111

121112
It("rejects large headers", func() {

0 commit comments

Comments
 (0)