Skip to content

Commit

Permalink
Merge pull request #150 from Nordix/fix-misleading-error-msg
Browse files Browse the repository at this point in the history
Fix misleading error msg & adding Stderr "contains" argument check in CLI tests
  • Loading branch information
nephio-prow[bot] authored Dec 6, 2024
2 parents 93084bb + 2915ece commit 6d34cf8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
6 changes: 5 additions & 1 deletion pkg/task/generictaskhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,14 @@ func applyResourceMutations(ctx context.Context, draft repository.PackageRevisio
}
if taskResult != nil && task.Type == api.TaskTypeEval {
renderStatus = taskResult.RenderStatus
if err != nil {
klog.Error(err)
err = fmt.Errorf("%w\n\n%s\n%s\n%s", err, "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.")
return updatedResources, renderStatus, err
}
}
if err != nil {
klog.Error(err)
err = fmt.Errorf("%w\n\n%s\n%s\n%s", err, "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.")
return updatedResources, renderStatus, err
}

Expand Down
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 6d34cf8

Please sign in to comment.