scripts/build: this CL cleans up the setup of Go environment variables

Change-Id: Ib6fdfc5c16b947e880a7881dc38f685e4723a21c
diff --git a/services/mgmt/build/impl/impl_test.go b/services/mgmt/build/impl/impl_test.go
index 65c1379..4bf9ec0 100644
--- a/services/mgmt/build/impl/impl_test.go
+++ b/services/mgmt/build/impl/impl_test.go
@@ -2,7 +2,9 @@
 
 import (
 	"os"
+	"os/exec"
 	"path/filepath"
+	"runtime"
 	"strings"
 	"testing"
 
@@ -17,13 +19,32 @@
 	rt.Init()
 }
 
-// startServer starts the build server.
-func startServer(t *testing.T) (build.Builder, func()) {
+// findGoBinary returns the path to the given Go binary.
+func findGoBinary(t *testing.T, name string) string {
 	root := os.Getenv("VEYRON_ROOT")
 	if root == "" {
 		t.Fatalf("VEYRON_ROOT is not set")
 	}
-	gobin := filepath.Join(root, "environment", "go", "bin", "go")
+	envbin := filepath.Join(root, "environment", "go", runtime.GOOS, runtime.GOARCH, "go", "bin", name)
+	if _, err := os.Stat(envbin); err == nil {
+		return envbin
+	} else if !os.IsNotExist(err) {
+		t.Fatalf("Stat(%v) failed: %v", envbin, err)
+	}
+	pathbin, err := exec.LookPath(name)
+	if err != nil {
+		if err == exec.ErrNotFound {
+			t.Fatalf("%q does not exist and %q not found in PATH", envbin, name)
+		} else {
+			t.Fatalf("LookPath(%q) failed: %v", name, err)
+		}
+	}
+	return pathbin
+}
+
+// startServer starts the build server.
+func startServer(t *testing.T) (build.Builder, func()) {
+	gobin := findGoBinary(t, "go")
 	server, err := rt.R().NewServer()
 	if err != nil {
 		t.Fatalf("NewServer() failed: %v", err)