@@ -5,6 +5,7 @@ package pipeline_test
5
5
6
6
import (
7
7
"fmt"
8
+ "net/http"
8
9
"net/url"
9
10
"os"
10
11
"os/exec"
@@ -43,26 +44,6 @@ var _ = Describe("pipeline flow", func() {
43
44
cmd .Stderr = os .Stderr
44
45
Expect (cmd .Run ()).NotTo (HaveOccurred ())
45
46
})
46
-
47
- It ("should push upstream" , func () {
48
- cmd := exec .Command ("git" , "add" , "." )
49
- cmd .Stdout = os .Stdout
50
- cmd .Stderr = os .Stderr
51
- cmd .Dir = repoName
52
- Expect (cmd .Run ()).NotTo (HaveOccurred ())
53
-
54
- cmd = exec .Command ("git" , "commit" , "-m" , "first commit" )
55
- cmd .Stdout = os .Stdout
56
- cmd .Stderr = os .Stderr
57
- cmd .Dir = repoName
58
- Expect (cmd .Run ()).NotTo (HaveOccurred ())
59
-
60
- cmd = exec .Command ("git" , "push" )
61
- cmd .Stdout = os .Stdout
62
- cmd .Stderr = os .Stderr
63
- cmd .Dir = repoName
64
- Expect (cmd .Run ()).NotTo (HaveOccurred ())
65
- })
66
47
})
67
48
68
49
Context ("create a new app" , func () {
@@ -148,9 +129,172 @@ var _ = Describe("pipeline flow", func() {
148
129
_ , err := copilot .PipelineInit (appName , repoURL , "master" , []string {"test" , "prod" })
149
130
Expect (err ).NotTo (HaveOccurred ())
150
131
})
132
+
151
133
It ("should generate pipeline artifacts" , func () {
152
134
Expect (filepath .Join (repoName , "copilot" , "pipeline.yml" )).Should (BeAnExistingFile ())
153
135
Expect (filepath .Join (repoName , "copilot" , "buildspec.yml" )).Should (BeAnExistingFile ())
154
136
})
137
+
138
+ It ("should push repo changes upstream" , func () {
139
+ cmd := exec .Command ("git" , "config" , "user.email" , "e2etest@amazon.com" )
140
+ cmd .Stdout = os .Stdout
141
+ cmd .Stderr = os .Stderr
142
+ cmd .Dir = repoName
143
+ Expect (cmd .Run ()).NotTo (HaveOccurred ())
144
+
145
+ cmd = exec .Command ("git" , "config" , "user.name" , "e2etest" )
146
+ cmd .Stdout = os .Stdout
147
+ cmd .Stderr = os .Stderr
148
+ cmd .Dir = repoName
149
+ Expect (cmd .Run ()).NotTo (HaveOccurred ())
150
+
151
+ cmd = exec .Command ("git" , "add" , "." )
152
+ cmd .Stdout = os .Stdout
153
+ cmd .Stderr = os .Stderr
154
+ cmd .Dir = repoName
155
+ Expect (cmd .Run ()).NotTo (HaveOccurred ())
156
+
157
+ cmd = exec .Command ("git" , "commit" , "-m" , "first commit" )
158
+ cmd .Stdout = os .Stdout
159
+ cmd .Stderr = os .Stderr
160
+ cmd .Dir = repoName
161
+ Expect (cmd .Run ()).NotTo (HaveOccurred ())
162
+
163
+ cmd = exec .Command ("git" , "push" )
164
+ cmd .Stdout = os .Stdout
165
+ cmd .Stderr = os .Stderr
166
+ cmd .Dir = repoName
167
+ Expect (cmd .Run ()).NotTo (HaveOccurred ())
168
+ })
169
+ })
170
+
171
+ Context ("when creating the pipeline stack" , func () {
172
+ It ("should start creating the pipeline stack" , func () {
173
+ _ , err := copilot .PipelineUpdate (appName )
174
+ Expect (err ).NotTo (HaveOccurred ())
175
+ })
176
+
177
+ It ("should show pipeline details once the stack is created" , func () {
178
+ type stage struct {
179
+ Name string
180
+ Category string
181
+ }
182
+ wantedStages := []stage {
183
+ {
184
+ Name : "Source" ,
185
+ Category : "Source" ,
186
+ },
187
+ {
188
+ Name : "Build" ,
189
+ Category : "Build" ,
190
+ },
191
+ {
192
+ Name : "DeployTo-test" ,
193
+ Category : "Deploy" ,
194
+ },
195
+ {
196
+ Name : "DeployTo-prod" ,
197
+ Category : "Deploy" ,
198
+ },
199
+ }
200
+
201
+ Eventually (func () error {
202
+ out , err := copilot .PipelineShow (appName )
203
+ if err != nil {
204
+ return err
205
+ }
206
+ if out .Name == "" {
207
+ return fmt .Errorf ("pipeline name is empty: %v" , out )
208
+ }
209
+ if len (wantedStages ) != len (out .Stages ) {
210
+ return fmt .Errorf ("pipeline stages do not match: %v" , out .Stages )
211
+ }
212
+ for idx , actualStage := range out .Stages {
213
+ if wantedStages [idx ].Name != actualStage .Name {
214
+ return fmt .Errorf ("stage name %s at index %d does not match" , actualStage .Name , idx )
215
+ }
216
+ if wantedStages [idx ].Category != actualStage .Category {
217
+ return fmt .Errorf ("stage category %s at index %d does not match" , actualStage .Category , idx )
218
+ }
219
+ }
220
+ return nil
221
+ }, "600s" , "10s" ).Should (BeNil ())
222
+ })
223
+
224
+ It ("should deploy the services to both environments" , func () {
225
+ type state struct {
226
+ Name string
227
+ ActionName string
228
+ ActionStatus string
229
+ }
230
+ wantedStates := []state {
231
+ {
232
+ Name : "Source" ,
233
+ ActionName : fmt .Sprintf ("SourceCodeFor-%s" , appName ),
234
+ ActionStatus : "Succeeded" ,
235
+ },
236
+ {
237
+ Name : "Build" ,
238
+ ActionName : "Build" ,
239
+ ActionStatus : "Succeeded" ,
240
+ },
241
+ {
242
+ Name : "DeployTo-test" ,
243
+ ActionName : "CreateOrUpdate-frontend-test" ,
244
+ ActionStatus : "Succeeded" ,
245
+ },
246
+ {
247
+ Name : "DeployTo-prod" ,
248
+ ActionName : "CreateOrUpdate-frontend-prod" ,
249
+ ActionStatus : "Succeeded" ,
250
+ },
251
+ }
252
+
253
+ Eventually (func () error {
254
+ out , err := copilot .PipelineStatus (appName )
255
+ if err != nil {
256
+ return err
257
+ }
258
+ if len (wantedStates ) != len (out .States ) {
259
+ return fmt .Errorf ("len of pipeline states do not match: %v" , out .States )
260
+ }
261
+ for idx , actualState := range out .States {
262
+ if wantedStates [idx ].Name != actualState .Name {
263
+ return fmt .Errorf ("state name %s at index %d does not match" , actualState .Name , idx )
264
+ }
265
+ if len (actualState .Actions ) != 1 {
266
+ return fmt .Errorf ("no action yet for state name %s" , actualState .Name )
267
+ }
268
+ if wantedStates [idx ].ActionName != actualState .Actions [0 ].Name {
269
+ return fmt .Errorf ("action name %v for state %s does not match at index %d" , actualState .Actions [0 ], actualState .Name , idx )
270
+ }
271
+ if wantedStates [idx ].ActionStatus != actualState .Actions [0 ].Status {
272
+ return fmt .Errorf ("action status %v for state %s does not match at index %d" , actualState .Actions [0 ], actualState .Name , idx )
273
+ }
274
+ }
275
+ return nil
276
+ }, "1200s" , "15s" ).Should (BeNil ())
277
+ })
278
+ })
279
+
280
+ Context ("services should be queryable post-release" , func () {
281
+ It ("services should include a valid URL" , func () {
282
+ out , err := copilot .SvcShow (& client.SvcShowRequest {
283
+ AppName : appName ,
284
+ Name : "frontend" ,
285
+ })
286
+ Expect (err ).NotTo (HaveOccurred ())
287
+
288
+ routes := make (map [string ]string )
289
+ for _ , route := range out .Routes {
290
+ routes [route .Environment ] = route .URL
291
+ }
292
+ for _ , env := range []string {"test" , "prod" } {
293
+ Eventually (func () (int , error ) {
294
+ resp , fetchErr := http .Get (routes [env ])
295
+ return resp .StatusCode , fetchErr
296
+ }, "30s" , "1s" ).Should (Equal (200 ))
297
+ }
298
+ })
155
299
})
156
300
})
0 commit comments