@@ -68,7 +68,47 @@ func TestMemcached(t *testing.T) {
68
68
"new" ,
69
69
"memcached-operator" ).CombinedOutput ()
70
70
if err != nil {
71
- t .Fatalf ("error: %v\n Command 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\n Command Output: %s\n " , err , string (cmdOut ))
108
+ }
109
+ } else {
110
+ t .Fatalf ("error: %v\n Command Output: %s\n " , err , string (cmdOut ))
111
+ }
72
112
}
73
113
ctx .AddFinalizerFn (func () error { return os .RemoveAll (absProjectPath ) })
74
114
@@ -143,39 +183,14 @@ func TestMemcached(t *testing.T) {
143
183
if err != nil {
144
184
t .Fatalf ("could not rename test/e2e/memcached_test.go.tmpl: %v\n Command Output:\n %v" , err , string (cmdOut ))
145
185
}
186
+
146
187
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
- }
173
188
cmdOut , err = exec .Command ("dep" , "ensure" ).CombinedOutput ()
174
189
if err != nil {
175
190
t .Fatalf ("dep ensure failed: %v\n Command Output:\n %v" , err , string (cmdOut ))
176
191
}
177
192
// link local sdk to vendor if not in travis
178
- if prSlug == "" {
193
+ if prSlug , _ := os . LookupEnv ( "TRAVIS_PULL_REQUEST_SLUG" ); prSlug == "" {
179
194
os .RemoveAll ("vendor/github.com/operator-framework/operator-sdk/pkg" )
180
195
os .Symlink (filepath .Join (gopath , "src/github.com/operator-framework/operator-sdk/pkg" ),
181
196
"vendor/github.com/operator-framework/operator-sdk/pkg" )
0 commit comments