Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set reportFormat to lower before generating report #464

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/test/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,9 @@ func (h *Harness) Report() {
if len(h.TestSuite.ReportFormat) == 0 {
return
}
if err := h.report.Report(h.TestSuite.ArtifactsDir, h.reportName(), report.Type(h.TestSuite.ReportFormat)); err != nil {

reportType := report.Type(strings.ToLower(h.TestSuite.ReportFormat))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing the change here, I think what should be modified is the reportType function from pkg/kuttlctl/cmd/test.go to store the report format in lower letters. That will help to not reproduce this problem in other places where pkg/kuttlctl/cmd/test.go is used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 agree with @iblancasa
as this has been awhile from PR to review (my fault)... if I don't see an update today... I will merge (for proper attribution) and modify consistent to iblancasa comments.

if err := h.report.Report(h.TestSuite.ArtifactsDir, h.reportName(), reportType); err != nil {
h.fatal(fmt.Errorf("fatal error writing report: %v", err))
}
}
Expand Down
75 changes: 75 additions & 0 deletions pkg/test/harness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
volumetypes "github.com/docker/docker/api/types/volume"
"github.com/stretchr/testify/assert"
kindConfig "sigs.k8s.io/kind/pkg/apis/config/v1alpha4"

harness "github.com/kudobuilder/kuttl/pkg/apis/testharness/v1beta1"
"github.com/kudobuilder/kuttl/pkg/report"
)

func TestGetTimeout(t *testing.T) {
Expand All @@ -28,6 +31,78 @@ func TestGetReportName(t *testing.T) {
assert.Equal(t, "special-kuttl-report", h.reportName())
}

func TestHarnessReport(t *testing.T) {
type HarnessTest struct {
name string
expectedFormat string
h *Harness
}

tests := []HarnessTest{
{
name: "should create an XML report when format is XML",
expectedFormat: "xml",
h: &Harness{
TestSuite: harness.TestSuite{
ReportFormat: "XML",
},
report: &report.Testsuites{},
},
}, {
name: "should create an XML report when format is xml",
expectedFormat: "xml",
h: &Harness{
TestSuite: harness.TestSuite{
ReportFormat: "xml",
},
report: &report.Testsuites{},
},
}, {
name: "should create an JSON report when format is JSON",
expectedFormat: "json",
h: &Harness{
TestSuite: harness.TestSuite{
ReportFormat: "JSON",
},
report: &report.Testsuites{},
},
}, {
name: "should create an JSON report when format is json",
expectedFormat: "json",
h: &Harness{
TestSuite: harness.TestSuite{
ReportFormat: "json",
},
report: &report.Testsuites{},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// set the artifacts dir for current test run
tt.h.TestSuite.ArtifactsDir = t.TempDir()
tt.h.Report()
assert.FileExists(t, fmt.Sprintf("%s/%s.%s", tt.h.TestSuite.ArtifactsDir, "kuttl-report", tt.expectedFormat))
})
}

// unit test for not passing any report format
emptyTest := HarnessTest{
name: "should not create any report when format is empty",
expectedFormat: "json",
h: &Harness{
TestSuite: harness.TestSuite{},
report: &report.Testsuites{},
},
}
t.Run(emptyTest.name, func(t *testing.T) {
emptyTest.h.TestSuite.ArtifactsDir = t.TempDir()
emptyTest.h.Report()
assert.NoFileExists(t, fmt.Sprintf("%s/%s.%s", emptyTest.h.TestSuite.ArtifactsDir, "kuttl-report", emptyTest.expectedFormat))
})
}

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