From ed9d825552addde42b846d6e5bcd6eddaa19b7f0 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 12 May 2021 11:55:11 -0700 Subject: [PATCH] tstest/integration: fix integration test on linux/386 Apparently can't use GOBIN with GOARCH. Signed-off-by: Brad Fitzpatrick --- tstest/integration/integration_test.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tstest/integration/integration_test.go b/tstest/integration/integration_test.go index 3b1eecfec..2f472fb31 100644 --- a/tstest/integration/integration_test.go +++ b/tstest/integration/integration_test.go @@ -20,6 +20,7 @@ import ( "net/http/httptest" "os" "os/exec" + "path" "path/filepath" "regexp" "runtime" @@ -412,11 +413,24 @@ func build(t testing.TB, outDir string, targets ...string) { goBin := findGo(t) cmd := exec.Command(goBin, "install") cmd.Args = append(cmd.Args, targets...) - cmd.Env = append(os.Environ(), "GOBIN="+outDir) + cmd.Env = append(os.Environ(), "GOARCH="+runtime.GOARCH, "GOBIN="+outDir) errOut, err := cmd.CombinedOutput() - if err != nil { - t.Fatalf("failed to build %v with %v: %v, %s", targets, goBin, err, errOut) + if err == nil { + return } + if strings.Contains(string(errOut), "when GOBIN is set") { + // Fallback slow path for cross-compiled binaries. + for _, target := range targets { + outFile := filepath.Join(outDir, path.Base(target)+exe()) + cmd := exec.Command(goBin, "build", "-o", outFile, target) + cmd.Env = append(os.Environ(), "GOARCH="+runtime.GOARCH) + if errOut, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("failed to build %v with %v: %v, %s", target, goBin, err, errOut) + } + } + return + } + t.Fatalf("failed to build %v with %v: %v, %s", targets, goBin, err, errOut) } // logCatcher is a minimal logcatcher for the logtail upload client.