@@ -22,6 +22,7 @@ import (
22
22
"os"
23
23
"os/exec"
24
24
"path"
25
+ "strings"
25
26
"testing"
26
27
"time"
27
28
@@ -68,9 +69,30 @@ func TestMemcached(t *testing.T) {
68
69
ctx .AddFinalizerFn (func () error { return os .RemoveAll (path .Join (gopath , "/src/github.com/example-inc/memcached-operator" )) })
69
70
70
71
os .Chdir ("memcached-operator" )
71
- os .RemoveAll ("vendor/github.com/operator-framework/operator-sdk/pkg" )
72
- os .Symlink (path .Join (gopath , "/src/github.com/operator-framework/operator-sdk/pkg" ),
73
- "vendor/github.com/operator-framework/operator-sdk/pkg" )
72
+
73
+ prSlug , ok := os .LookupEnv ("TRAVIS_PULL_REQUEST_SLUG" )
74
+ if ok {
75
+ prSha , ok := os .LookupEnv ("TRAVIS_PULL_REQUEST_SHA" )
76
+ if ok {
77
+ gopkg , err := ioutil .ReadFile ("Gopkg.toml" )
78
+ if err != nil {
79
+ t .Fatal (err )
80
+ }
81
+ // TODO: make this match more complete in case we add another repo tracking master
82
+ gopkg = bytes .Replace (gopkg , []byte ("branch = \" master\" " ), []byte ("# branch = \" master\" " ), - 1 )
83
+ gopkgString := string (gopkg )
84
+ gopkgLoc := strings .LastIndex (gopkgString , "\n name = \" github.com/operator-framework/operator-sdk\" \n " )
85
+ gopkgString = gopkgString [:gopkgLoc ] + "\n source = \" https://github.com/" + prSlug + "\" \n revision = \" " + prSha + "\" \n " + gopkgString [gopkgLoc + 1 :]
86
+ err = ioutil .WriteFile ("Gopkg.toml" , []byte (gopkgString ), os .FileMode (filemode ))
87
+ cmdOut , err = exec .Command ("dep" , "ensure" ).CombinedOutput ()
88
+ if err != nil {
89
+ t .Fatalf ("dep ensure after gopkg replace failed: %v\n Command Output: %s\n Gopkg Contents: %s" , err , cmdOut , gopkgString )
90
+ }
91
+ } else {
92
+ t .Fatal ("could not find sha of PR" )
93
+ }
94
+ }
95
+
74
96
handlerFile , err := os .Create ("pkg/stub/handler.go" )
75
97
if err != nil {
76
98
t .Fatal (err )
0 commit comments