Skip to content

Commit 62df2cd

Browse files
committed
Replace an older pipelines test JUnit report when a flag is invalid
1 parent 1aecf2b commit 62df2cd

5 files changed

Lines changed: 64 additions & 34 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="1234" tests="1" failures="0" errors="1" skipped="0">
4+
<testcase name="pipelines test">
5+
<error message="unsupported pytest argument &#34;-x&#34;: only -k and -m are supported">unsupported pytest argument &#34;-x&#34;: only -k and -m are supported</error>
6+
</testcase>
7+
</testsuite>
8+
</testsuites>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="1234" tests="1" failures="0" errors="1" skipped="0">
4+
<testcase name="pipelines test">
5+
<error message="--junit-xml cannot be used with --no-wait because no results are available when the command returns">--junit-xml cannot be used with --no-wait because no results are available when the command returns</error>
6+
</testcase>
7+
</testsuite>
8+
</testsuites>

‎acceptance/pipelines/test/arguments/output.txt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ Error: --resume "5678' OR '1'='1" is not an update ID; pass the update ID that p
9797
>>> musterr [CLI] pipelines test --pipeline-id 1234 --resume
9898
Error: --resume "" is not an update ID; pass the update ID that pipelines test printed
9999

100-
>>> musterr [CLI] pipelines test --pipeline-id 1234 --no-wait --junit-xml report.xml
100+
>>> musterr [CLI] pipelines test --pipeline-id 1234 --no-wait --junit-xml out.no-wait.xml
101101
Error: --junit-xml cannot be used with --no-wait because no results are available when the command returns
102102

103+
=== An invalid flag replaces an older report
104+
>>> musterr [CLI] pipelines test --pipeline-id 1234 --pytest-arg=-x --junit-xml out.flag-error.xml
105+
Error: unsupported pytest argument "-x": only -k and -m are supported
106+
103107
=== JSON output is not supported
104108
>>> musterr [CLI] pipelines test --pipeline-id 1234 -o json
105109
Error: --output json is not supported by pipelines test

‎acceptance/pipelines/test/arguments/script‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ trace musterr $CLI pipelines test --pipeline-id 1234 --resume 5678 --no-wait
2121
trace musterr $CLI pipelines test --pipeline-id 1234 --no-wait --timeout 10m
2222
trace musterr $CLI pipelines test --pipeline-id 1234 --resume "5678' OR '1'='1"
2323
trace musterr $CLI pipelines test --pipeline-id 1234 --resume ""
24-
trace musterr $CLI pipelines test --pipeline-id 1234 --no-wait --junit-xml report.xml
24+
trace musterr $CLI pipelines test --pipeline-id 1234 --no-wait --junit-xml out.no-wait.xml
25+
26+
title "An invalid flag replaces an older report"
27+
echo '<testsuites><testsuite name="1234" tests="1"><testcase name="test_old"></testcase></testsuite></testsuites>' > out.flag-error.xml
28+
trace musterr $CLI pipelines test --pipeline-id 1234 --pytest-arg=-x --junit-xml out.flag-error.xml
2529

2630
title "JSON output is not supported"
2731
trace musterr $CLI pipelines test --pipeline-id 1234 -o json

‎cmd/pipelines/test.go‎

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -569,49 +569,55 @@ names the cause.`,
569569
cmd.SetFlagErrorFunc(testFlagErrorFunc)
570570

571571
cmd.RunE = func(cmd *cobra.Command, args []string) error {
572-
if cmd.ArgsLenAtDash() >= 0 {
573-
return errors.New("the -- separator is not supported: " + pytestArgHint)
574-
}
575-
if root.OutputType(cmd) != flags.OutputText {
576-
return fmt.Errorf("--output %s is not supported by pipelines test", root.OutputType(cmd))
577-
}
578-
if err := validatePytestArgs(pytestArgs); err != nil {
579-
return err
580-
}
581-
if timeout < 0 {
582-
return errors.New("--timeout must not be negative")
583-
}
584-
if noWait && timeout > 0 {
585-
return errors.New("--timeout cannot be used with --no-wait")
586-
}
587-
if noWait && junitPath != "" {
588-
return errors.New("--junit-xml cannot be used with --no-wait because no results are available when the command returns")
589-
}
590572
// An empty --resume, such as from an unset shell variable, must not start a new run.
591573
resume := cmd.Flags().Changed("resume")
592-
if resume {
593-
selectionCount := len(args)
594-
if pipelineID == "" {
595-
selectionCount = max(len(args)-1, 0)
574+
checkFlags := func() error {
575+
if cmd.ArgsLenAtDash() >= 0 {
576+
return errors.New("the -- separator is not supported: " + pytestArgHint)
596577
}
597-
switch {
598-
case noWait:
599-
return errors.New("--resume cannot be used with --no-wait")
600-
case len(pytestArgs) > 0:
601-
return errors.New("--resume cannot be used with --pytest-arg")
602-
case selectionCount > 0:
603-
return errors.New("--resume cannot be used with test selections")
578+
if root.OutputType(cmd) != flags.OutputText {
579+
return fmt.Errorf("--output %s is not supported by pipelines test", root.OutputType(cmd))
604580
}
605-
if _, err := uuid.Parse(resumeUpdateID); err != nil {
606-
return fmt.Errorf("--resume %q is not an update ID; pass the update ID that pipelines test printed", resumeUpdateID)
581+
if err := validatePytestArgs(pytestArgs); err != nil {
582+
return err
607583
}
584+
if timeout < 0 {
585+
return errors.New("--timeout must not be negative")
586+
}
587+
if noWait && timeout > 0 {
588+
return errors.New("--timeout cannot be used with --no-wait")
589+
}
590+
if noWait && junitPath != "" {
591+
return errors.New("--junit-xml cannot be used with --no-wait because no results are available when the command returns")
592+
}
593+
if resume {
594+
selectionCount := len(args)
595+
if pipelineID == "" {
596+
selectionCount = max(len(args)-1, 0)
597+
}
598+
switch {
599+
case noWait:
600+
return errors.New("--resume cannot be used with --no-wait")
601+
case len(pytestArgs) > 0:
602+
return errors.New("--resume cannot be used with --pytest-arg")
603+
case selectionCount > 0:
604+
return errors.New("--resume cannot be used with test selections")
605+
}
606+
if _, err := uuid.Parse(resumeUpdateID); err != nil {
607+
return fmt.Errorf("--resume %q is not an update ID; pass the update ID that pipelines test printed", resumeUpdateID)
608+
}
609+
}
610+
return nil
608611
}
609612

610-
// From here on, every exit writes the report, so that an older report never survives.
613+
// Every exit writes the report, so that an older report never survives.
611614
report := &testReport{path: junitPath, out: cmd.OutOrStdout(), suiteName: pipelineID}
612615
if report.suiteName == "" && len(args) > 0 {
613616
report.suiteName = args[0]
614617
}
618+
if err := checkFlags(); err != nil {
619+
return report.failed(cmd.Context(), err)
620+
}
615621

616622
var target testTarget
617623
var err error

0 commit comments

Comments
 (0)