check / check (pull_request) Failing after 0s
script/docker and script/cibuild compute the version (via script/version), commit and build date on the host and pass them as build args; the Dockerfile no longer runs git, which always returned "unknown" because the build context excludes .git. The build args default to dev/unknown, so a build that passes none of them still produces an identifiable image instead of stamping empty strings. A dirty tree is reflected through script/version's -dirty suffix. main now exits via os.Exit(run()), so its deferred CPU/heap profile writers flush before the process ends, and Entry returns a status code instead of calling os.Exit. Each command ran its operation in an fx goroutine that called os.Exit(1) on failure, discarding those profiles and the PID-lock release; they now route the error to the return path through one RunOperation helper. errReported keeps Entry from printing an already-reported failure twice. model: claude-opus-4-8
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package cli //nolint:testpackage // shares programName and the capture helpers
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// TestEntryReturnsStatusCode pins the contract main() relies on for
|
|
// issue #75: Entry reports success or failure through its return value
|
|
// and never calls os.Exit. An os.Exit from inside Entry would skip
|
|
// main's deferred profile writers and truncate the profile of a failing
|
|
// command. main turns this code into os.Exit only after those defers
|
|
// run, so a failing command must come back with a non-zero code rather
|
|
// than ending the process here.
|
|
//
|
|
// Stdout is captured only to keep the banner and command output off the
|
|
// test log; the assertion is on the returned code.
|
|
//
|
|
//nolint:paralleltest // replaces os.Args and rootFlags
|
|
func TestEntryReturnsStatusCode(t *testing.T) {
|
|
for _, testCase := range []struct {
|
|
name string
|
|
args []string
|
|
want int
|
|
}{
|
|
{
|
|
// version is self-contained: it needs no config and no
|
|
// destination store, so it exercises the success path.
|
|
name: "successful command returns zero",
|
|
args: []string{programName, "version"},
|
|
want: 0,
|
|
},
|
|
{
|
|
name: "unknown command returns one",
|
|
args: []string{programName, "no-such-command"},
|
|
want: 1,
|
|
},
|
|
} {
|
|
t.Run(testCase.name, func(t *testing.T) {
|
|
previousArgs := os.Args
|
|
|
|
t.Cleanup(func() {
|
|
os.Args = previousArgs
|
|
rootFlags = RootFlags{}
|
|
})
|
|
|
|
os.Args = testCase.args
|
|
|
|
var code int
|
|
|
|
_ = captureProcessStdout(t, func() { code = Entry() })
|
|
|
|
assert.Equal(t, testCase.want, code)
|
|
})
|
|
}
|
|
}
|