Skip to content

Commit

Permalink
unquote CLI error
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandre Gaudreault <[email protected]>
  • Loading branch information
agaudreault committed Dec 18, 2024
1 parent 35d6ec0 commit c96ecd8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions test/e2e/fixture/app/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package app

import (
"encoding/json"
goerrors "errors"
"fmt"
"os"
"slices"
"strconv"

argoexec "github.com/argoproj/pkg/exec"
log "github.com/sirupsen/logrus"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -38,6 +40,16 @@ func (a *Actions) DoNotIgnoreErrors() *Actions {
return a
}

func (a *Actions) getLastErrorMessage() string {
if cmdErr, ok := a.lastError.(*argoexec.CmdError); ok || goerrors.As(a.lastError, &cmdErr) {
if unquoted, err := strconv.Unquote(cmdErr.Stderr); err != nil {
return unquoted
}
return cmdErr.Stderr
}
return a.lastError.Error()
}

func (a *Actions) PatchFile(file string, jsonPath string) *Actions {
a.context.t.Helper()
fixture.Patch(a.context.path+"/"+file, jsonPath)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixture/app/expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func Error(message, err string, matchers ...func(string, string) bool) Expectati
if !match(c.actions.lastOutput, message) {
return failed, fmt.Sprintf("output does not contain '%s'", message)
}
if !match(c.actions.lastError.Error(), err) {
if !match(c.actions.getLastErrorMessage(), err) {
return failed, fmt.Sprintf("error does not contain '%s'", err)
}
return succeeded, fmt.Sprintf("error '%s'", message)
Expand Down

0 comments on commit c96ecd8

Please sign in to comment.