Skip to content

Commit 4e49fba

Browse files
authored
test/e2e/memcached_test.go: fix travis on master (#529)
On master, TRAVIS_PULL_REQUEST_SLUG is still set, but to "". This breaks dep if it is run after a dependency change occurs, which happens once we add the test directory. To fix this, we check if TRAVIS_PULL_REQUEST_SLUG is "" and we also only run `dep ensure` once after all the files are up to date instead of once before and once after.
1 parent 02c057f commit 4e49fba

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

test/e2e/memcached_test.go

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,6 @@ func TestMemcached(t *testing.T) {
6969
ctx.AddFinalizerFn(func() error { return os.RemoveAll(path.Join(gopath, "/src/github.com/example-inc/memcached-operator")) })
7070

7171
os.Chdir("memcached-operator")
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-
9672
handlerFile, err := os.Create("pkg/stub/handler.go")
9773
if err != nil {
9874
t.Fatal(err)
@@ -145,6 +121,28 @@ func TestMemcached(t *testing.T) {
145121
t.Fatalf("could not rename test/e2e/memcached_test.go.tmpl: %v\nCommand Output:\n%v", err, string(cmdOut))
146122
}
147123
t.Log("Pulling new dependencies with dep ensure")
124+
prSlug, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SLUG")
125+
if ok && prSlug != "" {
126+
prSha, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SHA")
127+
if ok && prSha != "" {
128+
gopkg, err := ioutil.ReadFile("Gopkg.toml")
129+
if err != nil {
130+
t.Fatal(err)
131+
}
132+
// TODO: make this match more complete in case we add another repo tracking master
133+
gopkg = bytes.Replace(gopkg, []byte("branch = \"master\""), []byte("# branch = \"master\""), -1)
134+
gopkgString := string(gopkg)
135+
gopkgLoc := strings.LastIndex(gopkgString, "\n name = \"github.com/operator-framework/operator-sdk\"\n")
136+
gopkgString = gopkgString[:gopkgLoc] + "\n source = \"https://github.com/" + prSlug + "\"\n revision = \"" + prSha + "\"\n" + gopkgString[gopkgLoc+1:]
137+
err = ioutil.WriteFile("Gopkg.toml", []byte(gopkgString), os.FileMode(filemode))
138+
if err != nil {
139+
t.Fatalf("failed to write updated Gopkg.toml: %v", err)
140+
}
141+
t.Logf("Gopkg.toml: %v", gopkgString)
142+
} else {
143+
t.Fatal("could not find sha of PR")
144+
}
145+
}
148146
cmdOut, err = exec.Command("dep", "ensure").CombinedOutput()
149147
if err != nil {
150148
t.Fatalf("dep ensure failed: %v\nCommand Output:\n%v", err, string(cmdOut))

0 commit comments

Comments
 (0)