From 56fba7010cb1facf42d6390b3e1306ecc017ca18 Mon Sep 17 00:00:00 2001 From: stevenhorsman Date: Wed, 25 Sep 2024 10:25:47 +0100 Subject: [PATCH] tests/e2e: Minor tidy-up and logging - Trace out the test command being run for debug - Remove unnecessary double if check Signed-off-by: stevenhorsman --- src/cloud-api-adaptor/test/e2e/assessment_helpers.go | 9 +++++---- src/cloud-api-adaptor/test/e2e/assessment_runner.go | 8 +++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/cloud-api-adaptor/test/e2e/assessment_helpers.go b/src/cloud-api-adaptor/test/e2e/assessment_helpers.go index 7de1951d8..10976f332 100644 --- a/src/cloud-api-adaptor/test/e2e/assessment_helpers.go +++ b/src/cloud-api-adaptor/test/e2e/assessment_helpers.go @@ -472,6 +472,7 @@ func AssessPodTestCommands(ctx context.Context, client klient.Client, pod *v1.Po return "Failed to list pod", err } for _, testCommand := range testCommands { + log.Tracef("Running test command: %v", testCommand) var stdout, stderr bytes.Buffer for _, podItem := range podlist.Items { if podItem.ObjectMeta.Name == pod.Name { @@ -480,24 +481,24 @@ func AssessPodTestCommands(ctx context.Context, client klient.Client, pod *v1.Po if err := client.Resources(pod.Namespace).ExecInPod(ctx, pod.Namespace, pod.Name, testCommand.ContainerName, testCommand.Command, &stdout, &stderr); err != nil { if testCommand.TestErrorFn != nil { if !testCommand.TestErrorFn(err) { - return err.Error(), fmt.Errorf("Command %v running in container %s produced unexpected output on error: %s", testCommand.Command, testCommand.ContainerName, err.Error()) + return err.Error(), fmt.Errorf("command %v running in container %s produced unexpected output on error: %s, stderr: %s", testCommand.Command, testCommand.ContainerName, err.Error(), stderr.String()) } } else { - return err.Error(), err + return err.Error(), fmt.Errorf("command %v running in container %s produced unexpected output on error: %s, stderr: %s", testCommand.Command, testCommand.ContainerName, err.Error(), stderr.String()) } } else if testCommand.TestErrorFn != nil { return "", fmt.Errorf("We expected an error from Pod %s, but it was not found", pod.Name) } if testCommand.TestCommandStderrFn != nil { if !testCommand.TestCommandStderrFn(stderr) { - return stderr.String(), fmt.Errorf("Command %v running in container %s produced unexpected output on stderr: %s", testCommand.Command, testCommand.ContainerName, stderr.String()) + return stderr.String(), fmt.Errorf("Command %v running in container %s produced unexpected output on stderr: %s, stdout: %s", testCommand.Command, testCommand.ContainerName, stderr.String(), stdout.String()) } else { return stderr.String(), nil } } if testCommand.TestCommandStdoutFn != nil { if !testCommand.TestCommandStdoutFn(stdout) { - return stdout.String(), fmt.Errorf("Command %v running in container %s produced unexpected output on stdout: %s", testCommand.Command, testCommand.ContainerName, stdout.String()) + return stdout.String(), fmt.Errorf("Command %v running in container %s produced unexpected output on stdout: %s, stderr: %s", testCommand.Command, testCommand.ContainerName, stdout.String(), stderr.String()) } else { return stdout.String(), nil } diff --git a/src/cloud-api-adaptor/test/e2e/assessment_runner.go b/src/cloud-api-adaptor/test/e2e/assessment_runner.go index 15788c6b0..15e75f723 100644 --- a/src/cloud-api-adaptor/test/e2e/assessment_runner.go +++ b/src/cloud-api-adaptor/test/e2e/assessment_runner.go @@ -393,11 +393,9 @@ func (tc *TestCase) Run() { if tc.podState == v1.PodRunning { if len(tc.testCommands) > 0 { - if len(tc.testCommands) > 0 { - logString, err := AssessPodTestCommands(ctx, client, tc.pod, tc.testCommands) - if err != nil { - t.Errorf("AssessPodTestCommands failed, with output: %s and error: %v", logString, err) - } + logString, err := AssessPodTestCommands(ctx, client, tc.pod, tc.testCommands) + if err != nil { + t.Errorf("AssessPodTestCommands failed, with output: %s and error: %v", logString, err) } }