Skip to content

Commit d233444

Browse files
authored
test/e2e/memcached_test.go: fix dep issues in travis (#525)
* test/e2e/memcached_test.go: fix dep issues in travis
1 parent 7f00ede commit d233444

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

test/e2e/memcached_test.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"os"
2323
"os/exec"
2424
"path"
25+
"strings"
2526
"testing"
2627
"time"
2728

@@ -68,9 +69,30 @@ func TestMemcached(t *testing.T) {
6869
ctx.AddFinalizerFn(func() error { return os.RemoveAll(path.Join(gopath, "/src/github.com/example-inc/memcached-operator")) })
6970

7071
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\nCommand Output: %s\nGopkg Contents: %s", err, cmdOut, gopkgString)
90+
}
91+
} else {
92+
t.Fatal("could not find sha of PR")
93+
}
94+
}
95+
7496
handlerFile, err := os.Create("pkg/stub/handler.go")
7597
if err != nil {
7698
t.Fatal(err)

0 commit comments

Comments
 (0)