Skip to content

Commit a6977f9

Browse files
test
1 parent ecca3e5 commit a6977f9

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

testdata/project-v4-multigroup/test/e2e/e2e_test.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const metricsRoleBindingName = "project-v4-multigroup-metrics-binding"
4444

4545
var _ = Describe("Manager", Ordered, func() {
4646
var controllerPodName string
47-
47+
4848
// Before running the tests, set up the environment by creating the namespace,
4949
// installing CRDs, and deploying the controller.
5050
BeforeAll(func() {
@@ -91,27 +91,27 @@ var _ = Describe("Manager", Ordered, func() {
9191
cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
9292
controllerLogs, err := utils.Run(cmd)
9393
if err == nil {
94-
fmt.Println("Controller logs:\n", controllerLogs)
94+
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Controller logs:\n %s", controllerLogs))
9595
} else {
96-
fmt.Println("Failed to get controller logs")
96+
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Controller logs: %s", err))
9797
}
9898

9999
By("Fetching Kubernetes events")
100100
cmd = exec.Command("kubectl", "get", "events", "-n", namespace, "--sort-by=.lastTimestamp")
101101
eventsOutput, err := utils.Run(cmd)
102102
if err == nil {
103-
fmt.Println("Kubernetes events:\n", eventsOutput)
103+
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Kubernetes events:\n%s", eventsOutput))
104104
} else {
105-
fmt.Println("Failed to get Kubernetes events")
105+
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get Kubernetes events: %s", err))
106106
}
107107

108108
By("Fetching curl-metrics logs")
109109
cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
110110
metricsOutput, err := utils.Run(cmd)
111111
if err == nil {
112-
fmt.Println("Metrics logs:\n", metricsOutput)
112+
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Metrics logs:\n %s", metricsOutput))
113113
} else {
114-
fmt.Println("Failed to get curl-metrics logs")
114+
_, _ = fmt.Fprintf(GinkgoWriter, fmt.Sprintf("Failed to get curl-metrics logs: %s", err))
115115
}
116116

117117
By("Fetching controller manager pod description")
@@ -144,7 +144,7 @@ var _ = Describe("Manager", Ordered, func() {
144144

145145
podOutput, err := utils.Run(cmd)
146146
g.Expect(err).NotTo(HaveOccurred(), "Failed to retrieve controller-manager pod information")
147-
podNames := utils.GetNonEmptyLines(string(podOutput))
147+
podNames := utils.GetNonEmptyLines(podOutput)
148148
g.Expect(podNames).To(HaveLen(1), "expected 1 controller pod running")
149149
controllerPodName = podNames[0]
150150
g.Expect(controllerPodName).To(ContainSubstring("controller-manager"))
@@ -155,7 +155,7 @@ var _ = Describe("Manager", Ordered, func() {
155155
)
156156
output, err := utils.Run(cmd)
157157
g.Expect(err).NotTo(HaveOccurred())
158-
g.Expect(string(output)).To(BeEquivalentTo("Running"), "Incorrect controller-manager pod status")
158+
g.Expect(output).To(BeEquivalentTo("Running"), "Incorrect controller-manager pod status")
159159
}
160160
Eventually(verifyControllerUp).Should(Succeed())
161161
})
@@ -189,7 +189,7 @@ var _ = Describe("Manager", Ordered, func() {
189189
cmd := exec.Command("kubectl", "get", "endpoints", metricsServiceName, "-n", namespace)
190190
output, err := utils.Run(cmd)
191191
g.Expect(err).NotTo(HaveOccurred())
192-
g.Expect(string(output)).To(ContainSubstring("8443"), "Metrics endpoint is not ready")
192+
g.Expect(output).To(ContainSubstring("8443"), "Metrics endpoint is not ready")
193193
}
194194
Eventually(verifyMetricsEndpointReady).Should(Succeed())
195195

@@ -198,7 +198,7 @@ var _ = Describe("Manager", Ordered, func() {
198198
cmd := exec.Command("kubectl", "logs", controllerPodName, "-n", namespace)
199199
output, err := utils.Run(cmd)
200200
g.Expect(err).NotTo(HaveOccurred())
201-
g.Expect(string(output)).To(ContainSubstring("controller-runtime.metrics\tServing metrics server"),
201+
g.Expect(output).To(ContainSubstring("controller-runtime.metrics\tServing metrics server"),
202202
"Metrics server not yet started")
203203
}
204204
Eventually(verifyMetricsServerStarted).Should(Succeed())
@@ -220,7 +220,7 @@ var _ = Describe("Manager", Ordered, func() {
220220
"-n", namespace)
221221
output, err := utils.Run(cmd)
222222
g.Expect(err).NotTo(HaveOccurred())
223-
g.Expect(string(output)).To(Equal("Succeeded"), "curl pod in wrong status")
223+
g.Expect(output).To(Equal("Succeeded"), "curl pod in wrong status")
224224
}
225225
Eventually(verifyCurlUp, 5*time.Minute).Should(Succeed())
226226

@@ -300,7 +300,6 @@ func serviceAccountToken() (string, error) {
300300
}
301301

302302
var out string
303-
var rawJson string
304303
verifyTokenCreation := func(g Gomega) {
305304
// Execute kubectl command to create the token
306305
cmd := exec.Command("kubectl", "create", "--raw", fmt.Sprintf(
@@ -312,11 +311,9 @@ func serviceAccountToken() (string, error) {
312311
output, err := cmd.CombinedOutput()
313312
g.Expect(err).NotTo(HaveOccurred())
314313

315-
rawJson = string(output)
316-
317314
// Parse the JSON output to extract the token
318315
var token tokenRequest
319-
err = json.Unmarshal([]byte(rawJson), &token)
316+
err = json.Unmarshal([]byte(output), &token)
320317
g.Expect(err).NotTo(HaveOccurred())
321318

322319
out = token.Status.Token
@@ -332,9 +329,8 @@ func getMetricsOutput() string {
332329
cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
333330
metricsOutput, err := utils.Run(cmd)
334331
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
335-
metricsOutputStr := string(metricsOutput)
336-
Expect(metricsOutputStr).To(ContainSubstring("< HTTP/1.1 200 OK"))
337-
return metricsOutputStr
332+
Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
333+
return metricsOutput
338334
}
339335

340336
// tokenRequest is a simplified representation of the Kubernetes TokenRequest API response,

testdata/project-v4-multigroup/test/utils/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func warnError(err error) {
4141
}
4242

4343
// Run executes the provided command within this context
44-
func Run(cmd *exec.Cmd) ([]byte, error) {
44+
func Run(cmd *exec.Cmd) (string, error) {
4545
dir, _ := GetProjectDir()
4646
cmd.Dir = dir
4747

@@ -54,10 +54,10 @@ func Run(cmd *exec.Cmd) ([]byte, error) {
5454
_, _ = fmt.Fprintf(GinkgoWriter, "running: %s\n", command)
5555
output, err := cmd.CombinedOutput()
5656
if err != nil {
57-
return output, fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output))
57+
return string(output), fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output))
5858
}
5959

60-
return output, nil
60+
return string(output), nil
6161
}
6262

6363
// InstallPrometheusOperator installs the prometheus Operator to be used to export the enabled metrics.

0 commit comments

Comments
 (0)