Skip to content

Commit

Permalink
added string.contains functionality for stderr check for test respons…
Browse files Browse the repository at this point in the history
…es which are less reliable
  • Loading branch information
Catalin-Stratulat-Ericsson committed Dec 4, 2024
1 parent 54eb246 commit ad6f48f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions test/e2e/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type Command struct {
IgnoreWhitespace bool `yaml:"ignoreWhitespace,omitempty"`
// StdErrTabToWhitespace replaces "\t" (tab) character with whitespace " "
StdErrTabToWhitespace bool `yaml:"stdErrTabToWhitespace,omitempty"`
// ContainsErrorString changes Stderr check from exact string match to contains string match
ContainsErrorString bool `yaml:"containsErrorString,omitempty"`
}

type TestCaseConfig struct {
Expand Down
12 changes: 9 additions & 3 deletions test/e2e/cli/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (s *CliTestSuite) RunTestCase(t *testing.T, tc TestCaseConfig) {
command.Stdout = strings.ReplaceAll(command.Stdout, search, replace)
command.Stderr = strings.ReplaceAll(command.Stderr, search, replace)
}

if command.StdErrTabToWhitespace {
stderrStr = strings.ReplaceAll(stderrStr, "\t", " ") // Replace tabs with spaces
}
Expand All @@ -173,8 +173,14 @@ func (s *CliTestSuite) RunTestCase(t *testing.T, tc TestCaseConfig) {
got, want := stderrStr, command.Stderr
got = removeArmPlatformWarning(got)

if got != want {
t.Errorf("unexpected stderr content from '%s'; (-want, +got) %s", strings.Join(command.Args, " "), cmp.Diff(want, got))
if command.ContainsErrorString {
if !strings.Contains(got, want) {
t.Errorf("unexpected stderr content from '%s'; \n Error we got = \n(%s) \n Should contain substring = \n(%s)\n", strings.Join(command.Args, " "), got, want)
}
} else {
if got != want {
t.Errorf("unexpected stderr content from '%s'; (-want, +got) %s", strings.Join(command.Args, " "), cmp.Diff(want, got))
}
}

// hack here; but if the command registered a repo, give a few extra seconds for the repo to reach readiness
Expand Down
6 changes: 1 addition & 5 deletions test/e2e/cli/testdata/rpkg-push/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,8 @@ commands:
- git-efe3d01c68dfdcdd69114c9a7c65cce0d662a46f
- /tmp/porch-e2e/testing-invalid-render
stderr: |
Error: Internal error occurred: fn.render: pkg /:
pkg.render:
pipeline.run: func eval "gcr.io/kpt-fn/set-annotations:v0.1.4" failed: rpc error: code = Internal desc = Failed to execute function "gcr.io/kpt-fn/set-annotations:v0.1.4": exit status 1 ([error] : failed to configure function: `functionConfig` must be a `ConfigMap` or `SetAnnotations`)
Error occurred rendering package in kpt function pipeline.
Package has NOT been pushed to remote.
Please fix package locally (modify until 'kpt fn render' succeeds) and retry.
stdErrTabToWhitespace: true
containsErrorString: true
exitCode: 1

0 comments on commit ad6f48f

Please sign in to comment.