Centralize Go validation and build environments

This commit is contained in:
2026-10-06 16:38:15 +00:00
parent 12e866a94a
commit 08093124af
15 changed files with 637 additions and 129 deletions

View File

@@ -58,6 +58,24 @@ func TestRunPreservesExitError(t *testing.T) {
}
}
func TestRunCanRemoveInheritedEnvironment(t *testing.T) {
t.Setenv("RELEASEKIT_PROCESS_INHERITED", "inherited")
var stdout bytes.Buffer
err := Run(context.Background(), Invocation{
Args: []string{helperExecutable(t), "-test.run=TestProcessHelper", "--", "argument", "success"},
Env: map[string]string{"RELEASEKIT_PROCESS_HELPER": "1"},
UnsetEnv: []string{"RELEASEKIT_PROCESS_INHERITED"},
Stdout: &stdout,
})
if err != nil {
t.Fatal(err)
}
want := fmt.Sprintf("%s|argument||", mustGetwd(t))
if stdout.String() != want {
t.Fatalf("stdout = %q, want %q", stdout.String(), want)
}
}
func TestRunReportsMissingExecutable(t *testing.T) {
err := Run(context.Background(), Invocation{Args: []string{"releasekit-command-that-does-not-exist"}})
if err == nil || !strings.Contains(err.Error(), "releasekit-command-that-does-not-exist") {
@@ -143,3 +161,12 @@ func helperExecutable(t *testing.T) string {
}
return executable
}
func mustGetwd(t *testing.T) string {
t.Helper()
workdir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
return workdir
}