Skip to content

Commit af65f1f

Browse files
route integration helper before test runner
Run helper subprocesses from an init path before Go test filtering can interfere, and capture the PowerShell installer negative-test exit code without failing the parent step early.
1 parent 34beb6d commit af65f1f

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,12 @@ jobs:
200200
& (Join-Path $installDir 'agora.exe') --help *> $null
201201
202202
Set-Content -Path (Join-Path $downloadDir 'checksums.txt') -Value ('0' * 64 + " $archive")
203+
$previousNativePreference = $PSNativeCommandUseErrorActionPreference
204+
$PSNativeCommandUseErrorActionPreference = $false
203205
pwsh -NoProfile -ExecutionPolicy Bypass -File ./install.ps1 -InstallDir $badInstallDir
204-
if ($LASTEXITCODE -eq 0) {
206+
$badExitCode = $LASTEXITCODE
207+
$PSNativeCommandUseErrorActionPreference = $previousNativePreference
208+
if ($badExitCode -eq 0) {
205209
throw 'Expected checksum verification to fail with a non-zero exit code.'
206210
}
207211
} finally {

internal/cli/integration_test.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ type cliRunOptions struct {
5151
onStderr func(string) bool
5252
}
5353

54+
func init() {
55+
if os.Getenv("GO_WANT_CLI_HELPER_PROCESS") == "1" {
56+
runCLIHelperProcess()
57+
}
58+
}
59+
5460
// TestCLIHelperProcess is the in-process re-entry point used by runCLI.
5561
// When invoked with GO_WANT_CLI_HELPER_PROCESS=1, it builds a fresh *App
5662
// and runs Execute() with the args passed through GO_CLI_HELPER_ARGS_JSON;
@@ -59,11 +65,24 @@ func TestCLIHelperProcess(t *testing.T) {
5965
if os.Getenv("GO_WANT_CLI_HELPER_PROCESS") != "1" {
6066
return
6167
}
62-
cliArgs := helperCLIArgs(t)
68+
cliArgs := helperCLIArgs()
69+
if len(cliArgs) == 0 {
70+
fmt.Fprintln(os.Stderr, "TestCLIHelperProcess: missing CLI args (GO_CLI_HELPER_ARGS_JSON was empty and no -- fallback args were present)")
71+
os.Exit(64)
72+
}
73+
executeCLIHelper(cliArgs)
74+
}
75+
76+
func runCLIHelperProcess() {
77+
cliArgs := helperCLIArgs()
6378
if len(cliArgs) == 0 {
6479
fmt.Fprintln(os.Stderr, "TestCLIHelperProcess: missing CLI args (GO_CLI_HELPER_ARGS_JSON was empty and no -- fallback args were present)")
6580
os.Exit(64)
6681
}
82+
executeCLIHelper(cliArgs)
83+
}
84+
85+
func executeCLIHelper(cliArgs []string) {
6786
originalArgs := os.Args
6887
defer func() { os.Args = originalArgs }()
6988
os.Args = append([]string{"agora"}, cliArgs...)
@@ -91,12 +110,12 @@ func TestCLIHelperProcess(t *testing.T) {
91110
os.Exit(0)
92111
}
93112

94-
func helperCLIArgs(t *testing.T) []string {
95-
t.Helper()
113+
func helperCLIArgs() []string {
96114
if raw := os.Getenv("GO_CLI_HELPER_ARGS_JSON"); raw != "" {
97115
var args []string
98116
if err := json.Unmarshal([]byte(raw), &args); err != nil {
99-
t.Fatalf("invalid GO_CLI_HELPER_ARGS_JSON: %v", err)
117+
fmt.Fprintf(os.Stderr, "TestCLIHelperProcess: invalid GO_CLI_HELPER_ARGS_JSON: %v\n", err)
118+
os.Exit(64)
100119
}
101120
return args
102121
}
@@ -116,7 +135,7 @@ func helperCLIArgs(t *testing.T) []string {
116135
// URL the moment we see it).
117136
func runCLI(t *testing.T, args []string, options cliRunOptions) cliResult {
118137
t.Helper()
119-
cmd := exec.Command(os.Args[0], "-test.run=TestCLIHelperProcess")
138+
cmd := exec.Command(os.Args[0])
120139
if options.workdir != "" {
121140
cmd.Dir = options.workdir
122141
}

0 commit comments

Comments
 (0)