Skip to content

Commit

Permalink
do not clutter the output with the general CLI help output on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Aug 19, 2024
1 parent bd92033 commit 01ba4ae
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cmd/test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"errors"
"fmt"
"os"

Expand All @@ -16,7 +15,7 @@ var (
testCmd = &cobra.Command{
Use: "test",
Short: "Run a set of tests to check CRD schema stability.",
RunE: runTest,
Run: runTest,
}

testArgs struct {
Expand All @@ -31,19 +30,23 @@ func init() {
f.BoolVarP(&testArgs.update, "update", "u", false, "Update any existing snapshots.")
}

func runTest(cmd *cobra.Command, args []string) error {
func runTest(cmd *cobra.Command, args []string) {
if len(args) == 0 {
return errors.New("test needs an argument where the tests are located at")
fmt.Fprintf(os.Stderr, "test needs an argument where the tests are located at")

os.Exit(1)
}

path := args[0]
runner := tests.NewSuiteRunner(path, testArgs.update)
outcome, err := runner.Run(cmd.Context())
if err != nil {
return err
os.Exit(1)
}

return displayWarnings(outcome)
if err := displayWarnings(outcome); err != nil {
os.Exit(1)
}
}

func displayWarnings(warnings []tests.Outcome) error {
Expand Down

0 comments on commit 01ba4ae

Please sign in to comment.