Skip to content

Commit

Permalink
Allow user to set reportName (#395)
Browse files Browse the repository at this point in the history
* change default report name to `kuttl-report`
* override default report name according to config file's `reportName` field
* override default or config file report name according to command line option --report-name

Addresses issue #394

Signed-off-by: Ben Blattberg <ben.blattberg@crunchydata.com>
  • Loading branch information
benjaminjb authored Nov 9, 2022
1 parent 8a65c1c commit 81994a4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crds/testsuite-json-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ properties:
type: string
reportName:
description: The name of report to create. This field is not used unless reportFormat is set.
default: "kuttl-test"
default: "kuttl-report"
type: string
namespace:
description: |
Expand Down
2 changes: 1 addition & 1 deletion crds/testsuite_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ spec:
type: string
reportName:
description: The name of report to create. This field is not used unless reportFormat is set.
default: "kuttl-test"
default: "kuttl-report"
type: string
namespace:
description: |
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/testharness/v1beta1/test_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type TestSuite struct {
// maps to report.Type, however we don't want generated.deepcopy to have reference to it.
ReportFormat string `json:"reportFormat"`

// ReportName defines the name of report to create. It defaults to "kuttl-test" and is not used unless ReportFormat is defined.
// ReportName defines the name of report to create. It defaults to "kuttl-report" and is not used unless ReportFormat is defined.
ReportName string `json:"reportName"`
// Namespace defines the namespace to use for tests
// The value "" means to auto-generate tests namespaces, these namespaces will be created and removed for each test
Expand Down
7 changes: 6 additions & 1 deletion pkg/kuttlctl/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func newTestCmd() *cobra.Command {
mockControllerFile := ""
timeout := 30
reportFormat := ""
reportName := "kuttl-report"
namespace := ""
suppress := []string{}

Expand Down Expand Up @@ -111,7 +112,6 @@ For more detailed documentation, visit: https://kuttl.dev`,
}

// Override configuration file options with any command line flags if they are set.
options.ReportName = "kuttl-test"
if isSet(flags, "crd-dir") {
options.CRDDir = crdDir
}
Expand Down Expand Up @@ -171,6 +171,10 @@ For more detailed documentation, visit: https://kuttl.dev`,
options.ReportFormat = reportType(ftype)
}

if isSet(flags, "report-name") {
options.ReportName = reportName
}

if isSet(flags, "artifacts-dir") {
options.ArtifactsDir = artifactsDir
}
Expand Down Expand Up @@ -250,6 +254,7 @@ For more detailed documentation, visit: https://kuttl.dev`,
testCmd.Flags().IntVar(&parallel, "parallel", 8, "The maximum number of tests to run at once.")
testCmd.Flags().IntVar(&timeout, "timeout", 30, "The timeout to use as default for TestSuite configuration.")
testCmd.Flags().StringVar(&reportFormat, "report", "", "Specify JSON|XML for report. Report location determined by --artifacts-dir.")
testCmd.Flags().StringVar(&reportName, "report-name", "kuttl-report", "Name for the report. Report location determined by --artifacts-dir and report file type determined by --report.")
testCmd.Flags().StringVarP(&namespace, "namespace", "n", "", "Namespace to use for tests. Provided namespaces must exist prior to running tests.")
testCmd.Flags().StringSliceVar(&suppress, "suppress-log", []string{}, "Suppress logging for these kinds of logs (events).")
// This cannot be a global flag because pkg/test/utils.RunTests calls flag.Parse which barfs on unknown top-level flags.
Expand Down
11 changes: 10 additions & 1 deletion pkg/test/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,20 @@ func (h *Harness) Report() {
if len(h.TestSuite.ReportFormat) == 0 {
return
}
if err := h.report.Report(h.TestSuite.ArtifactsDir, h.TestSuite.ReportName, report.Type(h.TestSuite.ReportFormat)); err != nil {
if err := h.report.Report(h.TestSuite.ArtifactsDir, h.GetReportName(), report.Type(h.TestSuite.ReportFormat)); err != nil {
h.fatal(fmt.Errorf("fatal error writing report: %v", err))
}
}

// GetReportName returns the configured ReportName.
func (h *Harness) GetReportName() string {
reportName := "kuttl-report"
if h.TestSuite.ReportName != "" {
reportName = h.TestSuite.ReportName
}
return reportName
}

func (h *Harness) loadKindConfig(path string) (*kindConfig.Cluster, error) {
raw, err := os.ReadFile(path)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/test/harness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ func TestGetTimeout(t *testing.T) {
assert.Equal(t, 45, h.GetTimeout())
}

func TestGetReportName(t *testing.T) {
h := Harness{}
assert.Equal(t, "kuttl-report", h.GetReportName())

h.TestSuite.ReportName = "special-kuttl-report"
assert.Equal(t, "special-kuttl-report", h.GetReportName())
}

type dockerMock struct {
ImageWriter *io.PipeWriter
imageReader *io.PipeReader
Expand Down

0 comments on commit 81994a4

Please sign in to comment.