Skip to content

Commit 6990358

Browse files
authored
Add additional debugging to test command execution (#825)
Signed-off-by: Jonathan West <[email protected]>
1 parent f652316 commit 6990358

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

test/e2e/argocd_metrics_test.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package e2e
1818

1919
import (
20+
"bytes"
2021
"fmt"
2122
"os/exec"
2223
"path/filepath"
@@ -30,15 +31,36 @@ import (
3031
"k8s.io/apimachinery/pkg/types"
3132
)
3233

34+
func runCommandWithOutput(cmdList ...string) (string, string, error) {
35+
36+
// Output the commands to be run, so that if the test fails we can determine why
37+
fmt.Println(cmdList)
38+
39+
cmd := exec.Command(cmdList[0], cmdList[1:]...)
40+
var stdout bytes.Buffer
41+
var stderr bytes.Buffer
42+
cmd.Stdout = &stdout
43+
cmd.Stderr = &stderr
44+
45+
err := cmd.Run()
46+
stdoutStr := stdout.String()
47+
stderrStr := stderr.String()
48+
49+
// Output the stdout/sterr text, so that if the test fails we can determine why
50+
fmt.Println(stdoutStr, stderrStr)
51+
52+
return stdoutStr, stderrStr, err
53+
54+
}
55+
3356
var _ = Describe("Argo CD metrics controller", func() {
3457
Context("Check if monitoring resources are created", func() {
3558
It("Role is created", func() {
3659
buildYAML := filepath.Join("..", "appcrs", "build_appcr.yaml")
3760
ocPath, err := exec.LookPath("oc")
3861
Expect(err).NotTo(HaveOccurred())
3962

40-
cmd := exec.Command(ocPath, "apply", "-f", buildYAML)
41-
err = cmd.Run()
63+
_, _, err = runCommandWithOutput(ocPath, "apply", "-f", buildYAML)
4264
Expect(err).NotTo(HaveOccurred())
4365
// Alert delay
4466
time.Sleep(60 * time.Second)

test/e2e/gitopsservice_test.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ var _ = Describe("GitOpsServiceController", func() {
129129
ocPath, err := exec.LookPath("oc")
130130
Expect(err).NotTo(HaveOccurred())
131131

132-
cmd := exec.Command(ocPath, "apply", "-f", imageYAML)
133-
err = cmd.Run()
132+
_, _, err = runCommandWithOutput(ocPath, "apply", "-f", imageYAML)
134133
Expect(err).NotTo(HaveOccurred())
135134
})
136135

@@ -191,8 +190,7 @@ var _ = Describe("GitOpsServiceController", func() {
191190
nonDefaultAppCR := filepath.Join("..", "appcrs", "non_default_appcr.yaml")
192191
ocPath, err := exec.LookPath("oc")
193192
Expect(err).NotTo(HaveOccurred())
194-
cmd := exec.Command(ocPath, "apply", "-f", nonDefaultAppCR)
195-
_, err = cmd.CombinedOutput()
193+
_, _, err = runCommandWithOutput(ocPath, "apply", "-f", nonDefaultAppCR)
196194
if err != nil {
197195
Expect(err).NotTo(HaveOccurred())
198196
}
@@ -321,8 +319,7 @@ var _ = Describe("GitOpsServiceController", func() {
321319
ocPath, err := exec.LookPath("oc")
322320
Expect(err).NotTo(HaveOccurred())
323321
schedulerYAML := filepath.Join("..", "appcrs", "scheduler_appcr.yaml")
324-
cmd := exec.Command(ocPath, "apply", "-f", schedulerYAML)
325-
_, err = cmd.CombinedOutput()
322+
_, _, err = runCommandWithOutput(ocPath, "apply", "-f", schedulerYAML)
326323
Expect(err).NotTo(HaveOccurred())
327324

328325
Eventually(func() error {
@@ -420,8 +417,7 @@ var _ = Describe("GitOpsServiceController", func() {
420417
nginxAppCr := filepath.Join("..", "appcrs", "nginx_appcr.yaml")
421418
ocPath, err := exec.LookPath("oc")
422419
Expect(err).NotTo(HaveOccurred())
423-
cmd := exec.Command(ocPath, "apply", "-f", nginxAppCr)
424-
err = cmd.Run()
420+
_, _, err = runCommandWithOutput(ocPath, "apply", "-f", nginxAppCr)
425421
Expect(err).NotTo(HaveOccurred())
426422

427423
Eventually(func() error {
@@ -487,8 +483,7 @@ var _ = Describe("GitOpsServiceController", func() {
487483
nginxAppCr := filepath.Join("..", "appcrs", "nginx_default_ns_appcr.yaml")
488484
ocPath, err := exec.LookPath("oc")
489485
Expect(err).NotTo(HaveOccurred())
490-
cmd := exec.Command(ocPath, "apply", "-f", nginxAppCr)
491-
err = cmd.Run()
486+
_, _, err = runCommandWithOutput(ocPath, "apply", "-f", nginxAppCr)
492487
Expect(err).NotTo(HaveOccurred())
493488

494489
Eventually(func() error {

0 commit comments

Comments
 (0)