Separate Go discovery configuration from diagnostics
This commit is contained in:
@@ -47,6 +47,18 @@ func runGoPreparationFixture() int {
|
||||
return 11
|
||||
}
|
||||
switch os.Getenv("RELEASEKIT_GO_FIXTURE_MODE") {
|
||||
case "discovery":
|
||||
settings := make(map[string]string)
|
||||
for _, key := range os.Args[3:] {
|
||||
settings[key] = os.Getenv(key)
|
||||
}
|
||||
settings["GOHOSTOS"] = runtime.GOOS
|
||||
settings["GOHOSTARCH"] = runtime.GOARCH
|
||||
fmt.Fprintln(os.Stderr, "fixture discovery diagnostic")
|
||||
if err := json.NewEncoder(os.Stdout).Encode(settings); err != nil {
|
||||
return 12
|
||||
}
|
||||
return 0
|
||||
case "fail":
|
||||
fmt.Fprintln(os.Stderr, "fixture dependency failure")
|
||||
return 23
|
||||
@@ -59,6 +71,30 @@ func runGoPreparationFixture() int {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoveryAcceptsDiagnosticsWithValidConfiguration(t *testing.T) {
|
||||
repository, _ := installGoPreparationFixture(t)
|
||||
t.Setenv("RELEASEKIT_GO_FIXTURE_MODE", "discovery")
|
||||
cache := filepath.Join(t.TempDir(), "cache")
|
||||
t.Setenv("GOCACHE", cache)
|
||||
tool, err := New(context.Background(), repository)
|
||||
if err != nil {
|
||||
t.Fatalf("New() rejected successful discovery: %v", err)
|
||||
}
|
||||
if tool.HostTarget() != (Target{OS: runtime.GOOS, Arch: runtime.GOARCH}) || tool.settings["GOCACHE"] != cache {
|
||||
t.Fatalf("discovered host=%v cache=%q", tool.HostTarget(), tool.settings["GOCACHE"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoveryPreservesFailureDiagnosticsAndCause(t *testing.T) {
|
||||
repository, _ := installGoPreparationFixture(t)
|
||||
t.Setenv("RELEASEKIT_GO_FIXTURE_MODE", "fail")
|
||||
_, err := New(context.Background(), repository)
|
||||
var exitError *exec.ExitError
|
||||
if !errors.As(err, &exitError) || exitError.ExitCode() != 23 || !strings.Contains(err.Error(), "fixture dependency failure") {
|
||||
t.Fatalf("New() error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func mustGetwd() string {
|
||||
directory, err := os.Getwd()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user