Skip to content

Commit 06807f2

Browse files
committed
test/e2e/memcached_test.go: fix dep ensure solve issue
1 parent cfcf476 commit 06807f2

File tree

1 file changed

+42
-27
lines changed

1 file changed

+42
-27
lines changed

test/e2e/memcached_test.go

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,51 @@ 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+
// A permanent solution can be implemented once the following is merged:
75+
// https://github.com/golang/dep/pull/1658
76+
solveFailRe := regexp.MustCompile(`(?m)^[ \t]*Solving failure:.+github\.com/operator-framework/operator-sdk.+:$`)
77+
if !solveFailRe.Match(cmdOut) {
78+
t.Fatalf("error: %v\nCommand Output: %s\n", err, string(cmdOut))
79+
}
7280
}
7381
ctx.AddFinalizerFn(func() error { return os.RemoveAll(absProjectPath) })
7482

7583
os.Chdir("memcached-operator")
84+
prSlug, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SLUG")
85+
if ok && prSlug != "" {
86+
prSha, ok := os.LookupEnv("TRAVIS_PULL_REQUEST_SHA")
87+
if ok && prSha != "" {
88+
gopkg, err := ioutil.ReadFile("Gopkg.toml")
89+
if err != nil {
90+
t.Fatal(err)
91+
}
92+
// Match against the '#osdk_branch_annotation' used for version substitution
93+
// and comment out the current branch.
94+
branchRe := regexp.MustCompile("([ ]+)(.+#osdk_branch_annotation)")
95+
gopkg = branchRe.ReplaceAll(gopkg, []byte("$1# $2"))
96+
// Plug in the fork to test against so `dep ensure` can resolve dependencies
97+
// correctly.
98+
gopkgString := string(gopkg)
99+
gopkgLoc := strings.LastIndex(gopkgString, "\n name = \"github.com/operator-framework/operator-sdk\"\n")
100+
gopkgString = gopkgString[:gopkgLoc] + "\n source = \"https://github.com/" + prSlug + "\"\n revision = \"" + prSha + "\"\n" + gopkgString[gopkgLoc+1:]
101+
err = ioutil.WriteFile("Gopkg.toml", []byte(gopkgString), filemode)
102+
if err != nil {
103+
t.Fatalf("failed to write updated Gopkg.toml: %v", err)
104+
}
105+
106+
t.Logf("Gopkg.toml: %v", gopkgString)
107+
} else {
108+
t.Fatal("could not find sha of PR")
109+
}
110+
}
111+
cmdOut, err = exec.Command("dep", "ensure").CombinedOutput()
112+
if err != nil {
113+
t.Fatalf("error: %v\nCommand Output: %s\n", err, string(cmdOut))
114+
}
115+
76116
cmdOut, err = exec.Command("operator-sdk",
77117
"add",
78118
"api",
@@ -143,33 +183,8 @@ 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))

0 commit comments

Comments
 (0)