@@ -64,59 +64,55 @@ func TestMemcached(t *testing.T) {
64
64
}
65
65
66
66
t .Log ("Creating new operator project" )
67
- var solveFailed bool
68
67
cmdOut , err := exec .Command ("operator-sdk" ,
69
68
"new" ,
70
69
"memcached-operator" ).CombinedOutput ()
71
70
if err != nil {
72
71
// HACK: dep cannot resolve non-master branches as the base branch for PR's,
73
72
// so running `dep ensure` will fail when first running
74
- // `operator-sdk new ...`. For now we can ignore the first solve failure,
75
- // and run `dep ensure` again.
73
+ // `operator-sdk new ...`. For now we can ignore the first solve failure.
76
74
// A permanent solution can be implemented once the following is merged:
77
75
// https://github.com/golang/dep/pull/1658
78
76
solveFailRe := regexp .MustCompile (`(?m)^[ \t]*Solving failure:.+github\.com/operator-framework/operator-sdk.+:$` )
79
- if solveFailRe .Match (cmdOut ) {
80
- prSlug , ok := os .LookupEnv ("TRAVIS_PULL_REQUEST_SLUG" )
81
- if ok && prSlug != "" {
82
- prSha , ok := os .LookupEnv ("TRAVIS_PULL_REQUEST_SHA" )
83
- if ok && prSha != "" {
84
- os .Chdir ("memcached-operator" )
85
- gopkg , err := ioutil .ReadFile ("Gopkg.toml" )
86
- if err != nil {
87
- t .Fatal (err )
88
- }
89
- // Match against the '#osdk_branch_annotation' used for version substitution
90
- // and comment out the current branch.
91
- branchRe := regexp .MustCompile ("([ ]+)(.+#osdk_branch_annotation)" )
92
- gopkg = branchRe .ReplaceAll (gopkg , []byte ("$1# $2" ))
93
- // Plug in the fork to test against so `dep ensure` can resolve dependencies
94
- // correctly.
95
- gopkgString := string (gopkg )
96
- gopkgLoc := strings .LastIndex (gopkgString , "\n name = \" github.com/operator-framework/operator-sdk\" \n " )
97
- gopkgString = gopkgString [:gopkgLoc ] + "\n source = \" https://github.com/" + prSlug + "\" \n revision = \" " + prSha + "\" \n " + gopkgString [gopkgLoc + 1 :]
98
- err = ioutil .WriteFile ("Gopkg.toml" , []byte (gopkgString ), filemode )
99
- if err != nil {
100
- t .Fatalf ("failed to write updated Gopkg.toml: %v" , err )
101
- }
102
-
103
- solveFailed = true
104
- t .Logf ("Gopkg.toml: %v" , gopkgString )
105
- } else {
106
- t .Fatal ("could not find sha of PR" )
107
- }
77
+ if ! solveFailRe .Match (cmdOut ) {
78
+ t .Fatalf ("error: %v\n Command Output: %s\n " , err , string (cmdOut ))
79
+ }
80
+ }
81
+ ctx .AddFinalizerFn (func () error { return os .RemoveAll (absProjectPath ) })
82
+
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 )
108
91
}
109
- cmdOut , err = exec .Command ("dep" , "ensure" ).CombinedOutput ()
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 )
110
102
if err != nil {
111
- t .Fatalf ("error: %v \n Command Output : %s \n " , err , string ( cmdOut ) )
103
+ t .Fatalf ("failed to write updated Gopkg.toml : %v " , err )
112
104
}
105
+
106
+ t .Logf ("Gopkg.toml: %v" , gopkgString )
113
107
} else {
114
- t .Fatalf ( "error: %v \n Command Output: %s \n " , err , string ( cmdOut ) )
108
+ t .Fatal ( "could not find sha of PR" )
115
109
}
116
110
}
117
- ctx .AddFinalizerFn (func () error { return os .RemoveAll (absProjectPath ) })
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
+ }
118
115
119
- os .Chdir ("memcached-operator" )
120
116
cmdOut , err = exec .Command ("operator-sdk" ,
121
117
"add" ,
122
118
"api" ,
@@ -189,32 +185,6 @@ func TestMemcached(t *testing.T) {
189
185
}
190
186
191
187
t .Log ("Pulling new dependencies with dep ensure" )
192
- prSlug , ok := os .LookupEnv ("TRAVIS_PULL_REQUEST_SLUG" )
193
- if ! solveFailed && ok && prSlug != "" {
194
- prSha , ok := os .LookupEnv ("TRAVIS_PULL_REQUEST_SHA" )
195
- if ok && prSha != "" {
196
- gopkg , err := ioutil .ReadFile ("Gopkg.toml" )
197
- if err != nil {
198
- t .Fatal (err )
199
- }
200
- // Match against the '#osdk_branch_annotation' used for version substitution
201
- // and comment out the current branch.
202
- branchRe := regexp .MustCompile ("([ ]+)(.+#osdk_branch_annotation)" )
203
- gopkg = branchRe .ReplaceAll (gopkg , []byte ("$1# $2" ))
204
- // Plug in the fork to test against so `dep ensure` can resolve dependencies
205
- // correctly.
206
- gopkgString := string (gopkg )
207
- gopkgLoc := strings .LastIndex (gopkgString , "\n name = \" github.com/operator-framework/operator-sdk\" \n " )
208
- gopkgString = gopkgString [:gopkgLoc ] + "\n source = \" https://github.com/" + prSlug + "\" \n revision = \" " + prSha + "\" \n " + gopkgString [gopkgLoc + 1 :]
209
- err = ioutil .WriteFile ("Gopkg.toml" , []byte (gopkgString ), filemode )
210
- if err != nil {
211
- t .Fatalf ("failed to write updated Gopkg.toml: %v" , err )
212
- }
213
- t .Logf ("Gopkg.toml: %v" , gopkgString )
214
- } else {
215
- t .Fatal ("could not find sha of PR" )
216
- }
217
- }
218
188
cmdOut , err = exec .Command ("dep" , "ensure" ).CombinedOutput ()
219
189
if err != nil {
220
190
t .Fatalf ("dep ensure failed: %v\n Command Output:\n %v" , err , string (cmdOut ))
0 commit comments