@@ -26,6 +26,7 @@ import (
26
26
"os"
27
27
"os/exec"
28
28
"path/filepath"
29
+ "runtime"
29
30
"testing"
30
31
"time"
31
32
@@ -43,7 +44,8 @@ func TestCreatePlugin(t *testing.T) {
43
44
defer os .RemoveAll (tmpDir )
44
45
45
46
pluginPath := filepath .Join (tmpDir , "sample.so" )
46
- output , err := exec .Command ("go" , "build" , "-buildmode=plugin" , "-o" , pluginPath , "./testdata/sample_plugin.go" ).CombinedOutput ()
47
+ cmd := exec .Command (properGoBinaryPath (), "build" , "-buildmode=plugin" , "-o" , pluginPath , "./testdata/sample_plugin.go" )
48
+ output , err := cmd .CombinedOutput ()
47
49
if err != nil {
48
50
t .Fatalf ("Failed to compile and create shared object file %q: %v\n %s" , pluginPath , err , output )
49
51
}
@@ -79,3 +81,23 @@ counter:
79
81
t .Errorf ("Unexpected output: %s" , g )
80
82
}
81
83
}
84
+
85
+ // This helper function is necessary to ensure that we use
86
+ // the same Go binary to compile plugins as well as to run
87
+ // this test.
88
+ // Otherwise we'll run into such failed tests:
89
+ // https://travis-ci.org/census-instrumentation/opencensus-service/builds/438157975
90
+ func properGoBinaryPath () string {
91
+ goSuffix := "go"
92
+ if runtime .GOOS == "windows" {
93
+ goSuffix += ".exe"
94
+ }
95
+ // Firstly check if we are using $GOROOT/bin/go*
96
+ goBinPath := filepath .Join (runtime .GOROOT (), "bin" , goSuffix )
97
+ if _ , err := os .Stat (goBinPath ); err == nil {
98
+ return goBinPath
99
+ }
100
+ // If that has failed, now trying looking it from the environment
101
+ binPath , _ := exec .LookPath (goSuffix )
102
+ return binPath
103
+ }
0 commit comments