Skip to content
Merged
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
3 changes: 2 additions & 1 deletion cmd/container-structure-test/app/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func run(out io.Writer) error {
channel := make(chan interface{}, 1)
go runTests(out, channel, args, driverImpl)
// TODO(nkubala): put a sync.WaitGroup here
return test.ProcessResults(out, opts.Output, channel)
return test.ProcessResults(out, opts.Output, opts.JunitSuiteName, channel)
}

func runTests(out io.Writer, channel chan interface{}, args *drivers.DriverConfig, driverImpl func(drivers.DriverConfig) (drivers.Driver, error)) {
Expand Down Expand Up @@ -246,6 +246,7 @@ func AddTestFlags(cmd *cobra.Command) {
cmd.Flags().MarkDeprecated("json", "please use --output instead")
cmd.Flags().VarP(&opts.Output, "output", "o", "output format for the test report (available format: text, json, junit)")
cmd.Flags().BoolVar(&opts.NoColor, "no-color", false, "no color in the output")
cmd.Flags().StringVar(&opts.JunitSuiteName, "junit-suite-name", "", "name to use for the junit test suite (defaults to 'container-structure-test.test')")

cmd.Flags().StringArrayVarP(&opts.ConfigFiles, "config", "c", []string{}, "test config files")
cmd.MarkFlagRequired("config")
Expand Down
4 changes: 2 additions & 2 deletions cmd/container-structure-test/app/cmd/test/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func Parse(fp string, args *drivers.DriverConfig, driverImpl func(drivers.Driver
return tests, nil
}

func ProcessResults(out io.Writer, format unversioned.OutputValue, c chan interface{}) error {
func ProcessResults(out io.Writer, format unversioned.OutputValue, junitSuiteName string, c chan interface{}) error {
totalPass := 0
totalFail := 0
totalDuration := time.Duration(0)
Expand Down Expand Up @@ -143,7 +143,7 @@ func ProcessResults(out io.Writer, format unversioned.OutputValue, c chan interf
// only output results here if we're in json mode
summary.Results = results
}
output.FinalResults(out, format, summary)
output.FinalResults(out, format, junitSuiteName, summary)

return err
}
Expand Down
15 changes: 8 additions & 7 deletions pkg/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ type StructureTestOptions struct {
TestReport string
ConfigFiles []string

JSON bool
Output unversioned.OutputValue
Pull bool
Save bool
Quiet bool
Force bool
NoColor bool
JSON bool
Output unversioned.OutputValue
JunitSuiteName string
Pull bool
Save bool
Quiet bool
Force bool
NoColor bool
}
11 changes: 9 additions & 2 deletions pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ import (

var bannerLength = 27 // default banner length

func getJunitSuiteName(junitSuiteName string) string {
if junitSuiteName != "" {
return junitSuiteName
}
return "container-structure-test.test"
}

func OutputResult(out io.Writer, result *types.TestResult) {
color.Default.Fprintf(out, "=== RUN: %s\n", result.Name)
if result.Pass {
Expand Down Expand Up @@ -58,7 +65,7 @@ func Banner(out io.Writer, filename string) {
color.Purple.Fprintln(out, strings.Repeat("=", bannerLength))
}

func FinalResults(out io.Writer, format types.OutputValue, result types.SummaryObject) error {
func FinalResults(out io.Writer, format types.OutputValue, junitSuiteName string, result types.SummaryObject) error {
if format == types.Json {
res, err := json.Marshal(result)
if err != nil {
Expand Down Expand Up @@ -95,7 +102,7 @@ func FinalResults(out io.Writer, format types.OutputValue, result types.SummaryO
Total: result.Total,
Duration: time.Duration.Seconds(result.Duration), // JUnit expects durations as float of seconds
TestSuite: types.JUnitTestSuite{
Name: "container-structure-test.test",
Name: getJunitSuiteName(junitSuiteName),
Results: junit_cases,
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestFinalResults(t *testing.T) {
t.Run(test.format.String(), func(t *testing.T) {
t.Parallel()

FinalResults(test.actual, test.format, result)
FinalResults(test.actual, test.format, "", result)

if strings.TrimSpace(test.actual.String()) != test.expected {
t.Errorf("expected %s but got %s", test.expected, test.actual)
Expand Down
Loading