@@ -68,11 +68,51 @@ 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
+ // 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\n Command Output: %s\n " , err , string (cmdOut ))
79
+ }
72
80
}
73
81
ctx .AddFinalizerFn (func () error { return os .RemoveAll (absProjectPath ) })
74
82
75
83
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\n Command Output: %s\n " , err , string (cmdOut ))
114
+ }
115
+
76
116
cmdOut , err = exec .Command ("operator-sdk" ,
77
117
"add" ,
78
118
"api" ,
@@ -143,33 +183,8 @@ 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 ))
0 commit comments