Skip to content

Commit

Permalink
tests/e2e: Minor tidy-up and logging
Browse files Browse the repository at this point in the history
- Trace out the test command being run for debug
- Remove unnecessary double if check

Signed-off-by: stevenhorsman <[email protected]>
  • Loading branch information
stevenhorsman committed Oct 17, 2024
1 parent f353b37 commit d2fa94b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/cloud-api-adaptor/test/e2e/assessment_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,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 {
Expand All @@ -346,24 +347,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
}
Expand Down
10 changes: 4 additions & 6 deletions src/cloud-api-adaptor/test/e2e/assessment_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,10 @@ func (tc *TestCase) Run() {
t.Fatal(err)
}
if len(tc.testCommands) > 0 {
if len(tc.testCommands) > 0 {
logString, err := AssessPodTestCommands(ctx, client, tc.pod, tc.testCommands)
t.Logf("Output when execute test commands: %s", logString)
if err != nil {
t.Fatal(err)
}
logString, err := AssessPodTestCommands(ctx, client, tc.pod, tc.testCommands)
t.Logf("Output when execute test commands: %s", logString)
if err != nil {
t.Fatal(err)
}
}

Expand Down

0 comments on commit d2fa94b

Please sign in to comment.