@@ -64,11 +64,55 @@ func TestMemcached(t *testing.T) {
64
64
}
65
65
66
66
t .Log ("Creating new operator project" )
67
+ var solveFailed bool
67
68
cmdOut , err := exec .Command ("operator-sdk" ,
68
69
"new" ,
69
70
"memcached-operator" ).CombinedOutput ()
70
71
if err != nil {
71
- t .Fatalf ("error: %v\n Command Output: %s\n " , err , string (cmdOut ))
72
+ // HACK: dep cannot resolve non-master branches as the base branch for PR's,
73
+ // 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.
76
+ // A permanent solution can be implemented once the following is merged:
77
+ // https://github.com/golang/dep/pull/1658
78
+ 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
+ }
108
+ }
109
+ cmdOut , err = exec .Command ("dep" , "ensure" ).CombinedOutput ()
110
+ if err != nil {
111
+ t .Fatalf ("error: %v\n Command Output: %s\n " , err , string (cmdOut ))
112
+ }
113
+ } else {
114
+ t .Fatalf ("error: %v\n Command Output: %s\n " , err , string (cmdOut ))
115
+ }
72
116
}
73
117
ctx .AddFinalizerFn (func () error { return os .RemoveAll (absProjectPath ) })
74
118
@@ -143,9 +187,10 @@ func TestMemcached(t *testing.T) {
143
187
if err != nil {
144
188
t .Fatalf ("could not rename test/e2e/memcached_test.go.tmpl: %v\n Command Output:\n %v" , err , string (cmdOut ))
145
189
}
190
+
146
191
t .Log ("Pulling new dependencies with dep ensure" )
147
192
prSlug , ok := os .LookupEnv ("TRAVIS_PULL_REQUEST_SLUG" )
148
- if ok && prSlug != "" {
193
+ if ! solveFailed && ok && prSlug != "" {
149
194
prSha , ok := os .LookupEnv ("TRAVIS_PULL_REQUEST_SHA" )
150
195
if ok && prSha != "" {
151
196
gopkg , err := ioutil .ReadFile ("Gopkg.toml" )
0 commit comments