Skip to content

Commit 622339f

Browse files
committed
test/e2e/memcached_test.go: fix dep ensure solve issue
1 parent c8fcffd commit 622339f

File tree

1 file changed

+43
-28
lines changed

1 file changed

+43
-28
lines changed

test/e2e/memcached_test.go

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,47 @@ func TestMemcached(t *testing.T) {
6868
"new",
6969
"memcached-operator").CombinedOutput()
7070
if err != nil {
71-
t.Fatalf("error: %v\nCommand Output: %s\n", err, string(cmdOut))
71+
// HACK: dep cannot resolve non-master branches as the base branch for PR's,
72+
// so running `dep ensure` will fail when first running
73+
// `operator-sdk new ...`. For now we can ignore the first solve failure,
74+
// and run `dep ensure` again.
75+
// A permanent solution can be implemented once the following is merged:
76+
// https://github.com/golang/dep/pull/1658
77+
solveFailRe := regexp.MustCompile(`(?m)^[ \t]*Solving failure:.+github\.com/operator-framework/operator-sdk.+:$`)
78+
if solveFailRe.Match(cmdOut) {
79+
prSlug, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SLUG")
80+
if ok && prSlug != "" {
81+
prSha, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SHA")
82+
if ok && prSha != "" {
83+
gopkg, err := ioutil.ReadFile("Gopkg.toml")
84+
if err != nil {
85+
t.Fatal(err)
86+
}
87+
// Match against the '#osdk_branch_annotation' used for version substitution
88+
// and comment out the current branch.
89+
branchRe := regexp.MustCompile("([ ]+)(.+#osdk_branch_annotation)")
90+
gopkg = branchRe.ReplaceAll(gopkg, []byte("$1# $2"))
91+
// Plug in the fork to test against so `dep ensure` can resolve dependencies
92+
// correctly.
93+
gopkgString := string(gopkg)
94+
gopkgLoc := strings.LastIndex(gopkgString, "\n name = \"github.com/operator-framework/operator-sdk\"\n")
95+
gopkgString = gopkgString[:gopkgLoc] + "\n source = \"https://github.com/" + prSlug + "\"\n revision = \"" + prSha + "\"\n" + gopkgString[gopkgLoc+1:]
96+
err = ioutil.WriteFile("Gopkg.toml", []byte(gopkgString), filemode)
97+
if err != nil {
98+
t.Fatalf("failed to write updated Gopkg.toml: %v", err)
99+
}
100+
t.Logf("Gopkg.toml: %v", gopkgString)
101+
} else {
102+
t.Fatal("could not find sha of PR")
103+
}
104+
}
105+
cmdOut, err = exec.Command("dep", "ensure").CombinedOutput()
106+
if err != nil {
107+
t.Fatalf("error: %v\nCommand Output: %s\n", err, string(cmdOut))
108+
}
109+
} else {
110+
t.Fatalf("error: %v\nCommand Output: %s\n", err, string(cmdOut))
111+
}
72112
}
73113
ctx.AddFinalizerFn(func() error { return os.RemoveAll(absProjectPath) })
74114

@@ -143,39 +183,14 @@ func TestMemcached(t *testing.T) {
143183
if err != nil {
144184
t.Fatalf("could not rename test/e2e/memcached_test.go.tmpl: %v\nCommand Output:\n%v", err, string(cmdOut))
145185
}
186+
146187
t.Log("Pulling new dependencies with dep ensure")
147-
prSlug, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SLUG")
148-
if ok && prSlug != "" {
149-
prSha, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SHA")
150-
if ok && prSha != "" {
151-
gopkg, err := ioutil.ReadFile("Gopkg.toml")
152-
if err != nil {
153-
t.Fatal(err)
154-
}
155-
// Match against the '#osdk_branch_annotation' used for version substitution
156-
// and comment out the current branch.
157-
branchRe := regexp.MustCompile("([ ]+)(.+#osdk_branch_annotation)")
158-
gopkg = branchRe.ReplaceAll(gopkg, []byte("$1# $2"))
159-
// Plug in the fork to test against so `dep ensure` can resolve dependencies
160-
// correctly.
161-
gopkgString := string(gopkg)
162-
gopkgLoc := strings.LastIndex(gopkgString, "\n name = \"github.com/operator-framework/operator-sdk\"\n")
163-
gopkgString = gopkgString[:gopkgLoc] + "\n source = \"https://github.com/" + prSlug + "\"\n revision = \"" + prSha + "\"\n" + gopkgString[gopkgLoc+1:]
164-
err = ioutil.WriteFile("Gopkg.toml", []byte(gopkgString), filemode)
165-
if err != nil {
166-
t.Fatalf("failed to write updated Gopkg.toml: %v", err)
167-
}
168-
t.Logf("Gopkg.toml: %v", gopkgString)
169-
} else {
170-
t.Fatal("could not find sha of PR")
171-
}
172-
}
173188
cmdOut, err = exec.Command("dep", "ensure").CombinedOutput()
174189
if err != nil {
175190
t.Fatalf("dep ensure failed: %v\nCommand Output:\n%v", err, string(cmdOut))
176191
}
177192
// link local sdk to vendor if not in travis
178-
if prSlug == "" {
193+
if prSlug, _ := os.LookupEnv("TRAVIS_PULL_REQUEST_SLUG"); prSlug == "" {
179194
os.RemoveAll("vendor/github.com/operator-framework/operator-sdk/pkg")
180195
os.Symlink(filepath.Join(gopath, "src/github.com/operator-framework/operator-sdk/pkg"),
181196
"vendor/github.com/operator-framework/operator-sdk/pkg")

0 commit comments

Comments
 (0)