generated from konveyor-ecosystem/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Pranav Gaikwad <[email protected]>
- Loading branch information
1 parent
59ee33a
commit 9c845e9
Showing
4 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/go-logr/logr" | ||
"github.com/konveyor-ecosystem/kantra/pkg/testing" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type testCommand struct { | ||
testFilterString string | ||
baseProviderSettings string | ||
} | ||
|
||
func NewTestCommand(log logr.Logger) *cobra.Command { | ||
testCmd := &testCommand{} | ||
|
||
testCobraCommand := &cobra.Command{ | ||
Use: "test", | ||
Short: "Test YAML rules", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var testFilter testing.TestsFilter | ||
if testCmd.testFilterString != "" { | ||
testFilter = testing.NewInlineNameBasedFilter(testCmd.testFilterString) | ||
} | ||
tests, err := testing.Parse(args, testFilter) | ||
if err != nil { | ||
log.Error(err, "failed parsing rulesets") | ||
return err | ||
} | ||
if len(tests) == 0 { | ||
log.Info("no tests found") | ||
return nil | ||
} | ||
results, err := testing.NewRunner().Run(tests, testing.TestOptions{ | ||
RunLocal: Settings.RunLocal, | ||
ContainerImage: Settings.RunnerImage, | ||
ProgressPrinter: testing.PrintProgress, | ||
}) | ||
testing.PrintSummary(os.Stdout, results) | ||
// TODO (pgaikwad): in future, return an error so parent can return non-zero exit code | ||
if err != nil { | ||
log.Error(err, "failed running tests") | ||
} | ||
return nil | ||
}, | ||
} | ||
testCobraCommand.Flags().StringVarP(&testCmd.testFilterString, "test-filter", "t", "", "filter tests / testcases by their names") | ||
testCobraCommand.Flags().StringVarP(&testCmd.baseProviderSettings, "base-provider-settings", "b", "", "path to a provider settings file the runner will use as base") | ||
return testCobraCommand | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters