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

Add junit support for non-e2e tests/multi-suite #851

Merged
merged 1 commit into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 0 additions & 14 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 14 additions & 15 deletions pkg/client/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ import (

"github.com/heptio/sonobuoy/pkg/client/results"
"github.com/heptio/sonobuoy/pkg/client/results/e2e"
"github.com/onsi/ginkgo/reporters"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now use our own type which is an amalgamation of the ginkgo/reporters and the jstemmer types. Paired with a custom unmarshaller, this allows us to handle both cases with a single type.

"github.com/pkg/errors"
)

// GetTests extracts the junit results from a sonobuoy archive and returns the requested tests.
func (*SonobuoyClient) GetTests(reader io.Reader, show string) ([]reporters.JUnitTestCase, error) {
func (*SonobuoyClient) GetTests(reader io.Reader, show string) ([]results.JUnitTestCase, error) {
read := results.NewReaderWithVersion(reader, "irrelevant")
junitResults := reporters.JUnitTestSuite{}
e2eJunitPath := path.Join(results.PluginsDir, e2e.ResultsSubdirectory, e2e.JUnitResultsFile)
legacye2eJunitPath := path.Join(results.PluginsDir, e2e.LegacyResultsSubdirectory, e2e.JUnitResultsFile)
junitResults := results.JUnitTestSuite{}
e2eJUnitPath := path.Join(results.PluginsDir, e2e.ResultsSubdirectory, e2e.JUnitResultsFile)
legacye2eJUnitPath := path.Join(results.PluginsDir, e2e.LegacyResultsSubdirectory, e2e.JUnitResultsFile)

found := false
err := read.WalkFiles(
Expand All @@ -46,7 +45,7 @@ func (*SonobuoyClient) GetTests(reader io.Reader, show string) ([]reporters.JUni
}
// TODO(chuckha) consider reusing this function for any generic e2e-esque plugin results.
// TODO(chuckha) consider using path.Join()
if path == e2eJunitPath || path == legacye2eJunitPath {
if path == e2eJUnitPath || path == legacye2eJUnitPath {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated a bunch of little lines for consistent naming: JUnit preferred over Junit

found = true
return results.ExtractFileIntoStruct(path, path, info, &junitResults)
}
Expand All @@ -57,35 +56,35 @@ func (*SonobuoyClient) GetTests(reader io.Reader, show string) ([]reporters.JUni
}

if !found {
return nil, fmt.Errorf("failed to find results file %q in archive", e2eJunitPath)
return nil, fmt.Errorf("failed to find results file %q in archive", e2eJUnitPath)
}

out := make([]reporters.JUnitTestCase, 0)
out := make([]results.JUnitTestCase, 0)
if show == "passed" || show == "all" {
out = append(out, results.Filter(results.Passed, junitResults)...)
out = append(out, results.JUnitFilter(results.JUnitPassed, junitResults)...)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although not strictly requiring this prefix now that there isnt a junit and a e2e filter/passed/etc, it makes sense to me to leave a prefix since this is type specific.

As we add other formats we will probably need similar named things. At that point we may also want to consider some interface to do this instead though.

}
if show == "failed" || show == "all" {
out = append(out, results.Filter(results.Failed, junitResults)...)
out = append(out, results.JUnitFilter(results.JUnitFailed, junitResults)...)
}
if show == "skipped" || show == "all" {
out = append(out, results.Filter(results.Skipped, junitResults)...)
out = append(out, results.JUnitFilter(results.JUnitSkipped, junitResults)...)
}
sort.Sort(results.AlphabetizedTestCases(out))
sort.Sort(results.JUnitAlphabetizedTestCases(out))
return out, nil
}

// Focus returns a value to be used in the E2E_FOCUS variable that is
// representative of the test cases in the struct.
func Focus(testCases []reporters.JUnitTestCase) string {
func Focus(testCases []results.JUnitTestCase) string {
testNames := make([]string, len(testCases))
for i, tc := range testCases {
testNames[i] = regexp.QuoteMeta(tc.Name)
}
return strings.Join(testNames, "|")
}

// PrintableTestCases nicely strings a []reporters.JunitTestCase
type PrintableTestCases []reporters.JUnitTestCase
// PrintableTestCases nicely strings a []results.JUnitTestCase
type PrintableTestCases []results.JUnitTestCase

func (p PrintableTestCases) String() string {
if len(p) == 0 {
Expand Down
23 changes: 12 additions & 11 deletions pkg/client/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"strings"
"testing"

"github.com/onsi/ginkgo/reporters"
"github.com/heptio/sonobuoy/pkg/client/results"

"k8s.io/client-go/rest"
)

Expand Down Expand Up @@ -95,15 +96,15 @@ func TestString(t *testing.T) {
}{
{
desc: "No tests should report empty string",
cases: PrintableTestCases([]reporters.JUnitTestCase{}),
cases: PrintableTestCases([]results.JUnitTestCase{}),
expect: "",
}, {
desc: "Nil tests should report empty string",
cases: PrintableTestCases(nil),
expect: "",
}, {
desc: "Should not end with extra new line",
cases: PrintableTestCases([]reporters.JUnitTestCase{
cases: PrintableTestCases([]results.JUnitTestCase{
{Name: "a"},
{Name: "b"},
}),
Expand All @@ -128,28 +129,28 @@ func TestFocus(t *testing.T) {
}{
{
desc: "No test should result in an empty string",
cases: []reporters.JUnitTestCase{},
cases: []results.JUnitTestCase{},
expect: "",
},
{
desc: "Single test with no regexp characters is not changed",
cases: []reporters.JUnitTestCase{
reporters.JUnitTestCase{Name: "this is a test"},
cases: []results.JUnitTestCase{
{Name: "this is a test"},
},
expect: "this is a test",
},
{
desc: "Test with special regexp characters should be escaped",
cases: []reporters.JUnitTestCase{
reporters.JUnitTestCase{Name: "[sig-apps] test-1 (1.15) [Conformance]"},
cases: []results.JUnitTestCase{
{Name: "[sig-apps] test-1 (1.15) [Conformance]"},
},
expect: `\[sig-apps\] test-1 \(1\.15\) \[Conformance\]`,
},
{
desc: "Multiple tests should be separated with '|'",
cases: []reporters.JUnitTestCase{
reporters.JUnitTestCase{Name: "[sig-apps] test-1 [Conformance]"},
reporters.JUnitTestCase{Name: "[sig-apps] test-2"},
cases: []results.JUnitTestCase{
{Name: "[sig-apps] test-1 [Conformance]"},
{Name: "[sig-apps] test-2"},
},
expect: `\[sig-apps\] test-1 \[Conformance\]|\[sig-apps\] test-2`,
},
Expand Down
Loading