From ad6f48f2bcee91315de3442327373990fc76742c Mon Sep 17 00:00:00 2001 From: Catalin Stratulat Date: Wed, 4 Dec 2024 11:55:52 +0000 Subject: [PATCH] added string.contains functionality for stderr check for test responses which are less reliable --- test/e2e/cli/config.go | 2 ++ test/e2e/cli/suite.go | 12 +++++++++--- test/e2e/cli/testdata/rpkg-push/config.yaml | 6 +----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/test/e2e/cli/config.go b/test/e2e/cli/config.go index 689b51a9..cfef3073 100644 --- a/test/e2e/cli/config.go +++ b/test/e2e/cli/config.go @@ -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 { diff --git a/test/e2e/cli/suite.go b/test/e2e/cli/suite.go index 380320ee..f23a1d2b 100644 --- a/test/e2e/cli/suite.go +++ b/test/e2e/cli/suite.go @@ -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 } @@ -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 diff --git a/test/e2e/cli/testdata/rpkg-push/config.yaml b/test/e2e/cli/testdata/rpkg-push/config.yaml index 1fc7fe99..c71fabda 100644 --- a/test/e2e/cli/testdata/rpkg-push/config.yaml +++ b/test/e2e/cli/testdata/rpkg-push/config.yaml @@ -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