refactor(#154): extract baseSubprocessArgs helper in main_test.go subprocess tests #155

Merged
aweiker merged 1 commits from issue-154 into main 2026-05-15 21:28:42 +00:00
+10
View File
@@ -903,12 +903,17 @@ func TestMainSubprocess_InvalidRepo(t *testing.T) {
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
args := baseSubprocessArgs() args := baseSubprocessArgs()
// Replace the canonical --repo value with an invalid one. // Replace the canonical --repo value with an invalid one.
found := false
for i, a := range args { for i, a := range args {
if a == "--repo" && i+1 < len(args) { if a == "--repo" && i+1 < len(args) {
args[i+1] = "invalidrepo" args[i+1] = "invalidrepo"
found = true
break break
} }
} }
if !found {
t.Fatal("baseSubprocessArgs() does not contain --repo; test is broken")
}
os.Args = args os.Args = args
main() main()
return return
2
@@ -930,12 +935,17 @@ func TestMainSubprocess_InvalidPRNumber(t *testing.T) {
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
args := baseSubprocessArgs() args := baseSubprocessArgs()
// Replace the canonical --pr value with a non-numeric string. // Replace the canonical --pr value with a non-numeric string.
found := false
for i, a := range args { for i, a := range args {
if a == "--pr" && i+1 < len(args) { if a == "--pr" && i+1 < len(args) {
args[i+1] = "notanumber" args[i+1] = "notanumber"
found = true
break break
} }
} }
if !found {
t.Fatal("baseSubprocessArgs() does not contain --pr; test is broken")
}
os.Args = args os.Args = args
main() main()
return return
1