Skip to content

Commit

Permalink
Fix exit error status
Browse files Browse the repository at this point in the history
  • Loading branch information
stbenjam committed Oct 1, 2024
1 parent 998d207 commit 5d21d3a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 36 deletions.
7 changes: 6 additions & 1 deletion pkg/cmd/cmdrun/runsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ func NewRunSuiteCommand(registry *extension.Registry) *cobra.Command {
return errors.Wrap(err, "couldn't filter specs")
}

return specs.Run(w)
if err := specs.Run(w); err != nil {
w.Flush()
os.Exit(1)
}

return nil
},
}
runOpts.componentFlags.BindFlags(cmd.Flags())
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/cmdrun/runtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ func NewRunTestCommand(registry *extension.Registry) *cobra.Command {
}
defer w.Flush()

return specs.Run(w)
if err := specs.Run(w); err != nil {
w.Flush()
os.Exit(1)
}

return nil
},
}
runOpts.componentFlags.BindFlags(cmd.Flags())
Expand Down
33 changes: 0 additions & 33 deletions pkg/cmd/cmdrun/util.go
Original file line number Diff line number Diff line change
@@ -1,34 +1 @@
package cmdrun

import (
"fmt"
"time"

"github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
)

func runSpec(spec *extensiontests.ExtensionTestSpec) *extensiontests.ExtensionTestResult {
startTime := time.Now()
res := spec.Run()
duration := time.Since(startTime)
endTime := startTime.Add(duration)
if res == nil {
// this shouldn't happen
panic(fmt.Sprintf("test produced no result: %s", spec.Name))
}

res.Lifecycle = spec.Lifecycle

// If the runner doesn't populate this info, we should set it
if res.StartTime == nil {
res.StartTime = &startTime
}
if res.EndTime == nil {
res.EndTime = &endTime
}
if res.Duration == 0 {
res.Duration = duration.Milliseconds()
}

return res
}
29 changes: 28 additions & 1 deletion pkg/extension/extensiontests/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package extensiontests

import (
"fmt"
"time"

"github.com/google/cel-go/cel"
"github.com/google/cel-go/checker/decls"
Expand All @@ -20,7 +21,7 @@ func (specs ExtensionTestSpecs) Run(w *ResultWriter) error {
var results ExtensionTestResults

specs.Walk(func(spec *ExtensionTestSpec) {
res := spec.Run()
res := runSpec(spec)
w.Write(res)
results = append(results, res)
})
Expand Down Expand Up @@ -135,3 +136,29 @@ func (specs ExtensionTestSpecs) UnsetTag(key string) ExtensionTestSpecs {

return specs
}

func runSpec(spec *ExtensionTestSpec) *ExtensionTestResult {
startTime := time.Now()
res := spec.Run()
duration := time.Since(startTime)
endTime := startTime.Add(duration)
if res == nil {
// this shouldn't happen
panic(fmt.Sprintf("test produced no result: %s", spec.Name))
}

res.Lifecycle = spec.Lifecycle

// If the runner doesn't populate this info, we should set it
if res.StartTime == nil {
res.StartTime = &startTime
}
if res.EndTime == nil {
res.EndTime = &endTime
}
if res.Duration == 0 {
res.Duration = duration.Milliseconds()
}

return res
}

0 comments on commit 5d21d3a

Please sign in to comment.