Skip to content

Commit

Permalink
Fix report tool tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nocturnalastro committed Aug 15, 2024
1 parent b72ed4f commit f364523
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions addon-tools/report-creator/report/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ func TestCompareRun(t *testing.T) {
}
}
func checkCompatibilityWithCompareOutput(t *testing.T, test Test, update bool) {
cmdutil.BehaviorOnFatal(func(str string, code int) {})
cmdutil.BehaviorOnFatal(func(str string, code int) {
if str != "" && str != compare.DiffsFoundMsg {
t.Fatalf("kube-compare run failed; msg: '%s', code: %d", str, code)
}
})

tf := cmdtesting.NewTestFactory()
IOStream, _, out, _ := genericiooptions.NewTestIOStreams()
cmpCmd := compare.NewCmd(tf, IOStream)
require.NoError(t, cmpCmd.Flags().Set("reference", path.Join(compareTestRefsDir, test.referenceDir, "reference")))
require.NoError(t, cmpCmd.Flags().Set("reference", path.Join(compareTestRefsDir, test.referenceDir, "reference/metadata.yaml")))
require.NoError(t, cmpCmd.Flags().Set("filename", path.Join(compareTestRefsDir, test.referenceDir, "resources")))
require.NoError(t, cmpCmd.Flags().Set("recursive", "true"))
require.NoError(t, cmpCmd.Flags().Set("output", compare.Json))
Expand Down
3 changes: 2 additions & 1 deletion pkg/compare/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const (
skipInvalidResources = "Skipping %s Input contains additional files from supported file extensions" +
" (json/yaml) that do not contain a valid resource, error: %s.\n In case this file is " +
"expected to be a valid resource modify it accordingly. "
DiffsFoundMsg = "there are differences between the cluster CRs and the reference CRs"
)

const (
Expand Down Expand Up @@ -510,7 +511,7 @@ func (o *Options) Run() error {
// We will return exit code 1 in case there are differences between the reference CRs and cluster CRs.
// The differences can be differences found in specific CRs or the absence of CRs from the cluster.
if numDiffCRs != 0 || sum.NumMissing != 0 {
return exec.CodeExitError{Err: fmt.Errorf("there are differences between the cluster CRs and the reference CRs"), Code: 1}
return exec.CodeExitError{Err: errors.New(DiffsFoundMsg), Code: 1}
}
return nil
}
Expand Down

0 comments on commit f364523

Please sign in to comment.