1
1
package revision_test
2
2
3
3
import (
4
- "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier"
4
+ "fmt"
5
+ "strings"
5
6
"testing"
6
7
"time"
7
8
9
+ "github.com/runatlantis/atlantis/server/neptune/workflows/internal/notifier"
10
+
8
11
"github.com/google/uuid"
9
12
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/github"
10
13
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/terraform"
@@ -13,6 +16,7 @@ import (
13
16
"github.com/runatlantis/atlantis/server/neptune/workflows/internal/deploy/revision/queue"
14
17
terraformWorkflow "github.com/runatlantis/atlantis/server/neptune/workflows/internal/deploy/terraform"
15
18
"github.com/stretchr/testify/assert"
19
+ "go.temporal.io/sdk/temporal"
16
20
"go.temporal.io/sdk/testsuite"
17
21
"go.temporal.io/sdk/workflow"
18
22
)
@@ -23,8 +27,11 @@ type testCheckRunClient struct {
23
27
}
24
28
25
29
func (t * testCheckRunClient ) CreateOrUpdate (ctx workflow.Context , deploymentID string , request notifier.GithubCheckRunRequest ) (int64 , error ) {
26
- assert .Equal (t .expectedT , t .expectedRequest , request )
27
-
30
+ ok := assert .Equal (t .expectedT , t .expectedRequest , request )
31
+ if ! ok {
32
+ return 1 , temporal .NewApplicationError ("failing workflow" , "myType" )
33
+ // t.expectedT.Exit("CreateOrUpdate had unexpected request")
34
+ }
28
35
return 1 , nil
29
36
}
30
37
@@ -49,6 +56,21 @@ func (q *testQueue) SetLockForMergedItems(ctx workflow.Context, state queue.Lock
49
56
q .Lock = state
50
57
}
51
58
59
+ func (q * testQueue ) IsEmpty () bool {
60
+ return q .Queue == nil || len (q .Queue ) == 0
61
+ }
62
+
63
+ func (q * testQueue ) GetQueuedRevisionsSummary () string {
64
+ var revisions []string
65
+ if q .IsEmpty () {
66
+ return "No other revisions ahead In queue."
67
+ }
68
+ for _ , deploy := range q .Scan () {
69
+ revisions = append (revisions , deploy .Commit .Revision )
70
+ }
71
+ return fmt .Sprintf ("Revisions in queue: %s" , strings .Join (revisions , ", " ))
72
+ }
73
+
52
74
type testWorker struct {
53
75
Current queue.CurrentDeployment
54
76
}
@@ -137,10 +159,11 @@ func TestEnqueue(t *testing.T) {
137
159
env .ExecuteWorkflow (testWorkflow , req {
138
160
ID : id ,
139
161
ExpectedRequest : notifier.GithubCheckRunRequest {
140
- Title : "atlantis/deploy: root" ,
141
- Sha : rev ,
142
- Repo : github.Repo {Name : "nish" },
143
- State : github .CheckRunQueued ,
162
+ Title : "atlantis/deploy: root" ,
163
+ Sha : rev ,
164
+ Repo : github.Repo {Name : "nish" },
165
+ State : github .CheckRunQueued ,
166
+ Summary : "This deploy is queued and will be processed as soon as possible.\n No other revisions ahead In queue." ,
144
167
},
145
168
ExpectedT : t ,
146
169
})
@@ -197,10 +220,11 @@ func TestEnqueue_ManualTrigger(t *testing.T) {
197
220
env .ExecuteWorkflow (testWorkflow , req {
198
221
ID : id ,
199
222
ExpectedRequest : notifier.GithubCheckRunRequest {
200
- Title : "atlantis/deploy: root" ,
201
- Sha : rev ,
202
- Repo : github.Repo {Name : "nish" },
203
- State : github .CheckRunQueued ,
223
+ Title : "atlantis/deploy: root" ,
224
+ Sha : rev ,
225
+ Repo : github.Repo {Name : "nish" },
226
+ State : github .CheckRunQueued ,
227
+ Summary : "This deploy is queued and will be processed as soon as possible.\n No other revisions ahead In queue." ,
204
228
},
205
229
ExpectedT : t ,
206
230
})
@@ -263,10 +287,11 @@ func TestEnqueue_ManualTrigger_QueueAlreadyLocked(t *testing.T) {
263
287
Revision : "123334444555" ,
264
288
},
265
289
ExpectedRequest : notifier.GithubCheckRunRequest {
266
- Title : "atlantis/deploy: root" ,
267
- Sha : rev ,
268
- Repo : github.Repo {Name : "nish" },
269
- State : github .CheckRunQueued ,
290
+ Title : "atlantis/deploy: root" ,
291
+ Sha : rev ,
292
+ Repo : github.Repo {Name : "nish" },
293
+ State : github .CheckRunQueued ,
294
+ Summary : "This deploy is queued and will be processed as soon as possible.\n No other revisions ahead In queue." ,
270
295
},
271
296
ExpectedT : t ,
272
297
})
@@ -321,8 +346,22 @@ func TestEnqueue_MergeTrigger_QueueAlreadyLocked(t *testing.T) {
321
346
322
347
id := uuid .Must (uuid .NewUUID ())
323
348
349
+ deploymentInfo := terraformWorkflow.DeploymentInfo {
350
+ Commit : github.Commit {
351
+ Revision : "123334444555" ,
352
+ Branch : "locking-branch" ,
353
+ },
354
+ CheckRunID : 0 ,
355
+ Root : terraform.Root {Name : "root" , TriggerInfo : terraform.TriggerInfo {
356
+ Type : terraform .MergeTrigger ,
357
+ }, Trigger : terraform .MergeTrigger },
358
+ ID : id ,
359
+ Repo : github.Repo {Name : "nish" },
360
+ }
361
+
324
362
env .ExecuteWorkflow (testWorkflow , req {
325
- ID : id ,
363
+ ID : id ,
364
+ InitialElements : []terraformWorkflow.DeploymentInfo {deploymentInfo },
326
365
Lock : queue.LockState {
327
366
// ensure that the lock gets updated
328
367
Status : queue .LockedStatus ,
@@ -332,7 +371,7 @@ func TestEnqueue_MergeTrigger_QueueAlreadyLocked(t *testing.T) {
332
371
Title : "atlantis/deploy: root" ,
333
372
Sha : rev ,
334
373
Repo : github.Repo {Name : "nish" },
335
- Summary : "This deploy is locked from a manual deployment for revision [123334444555](https://github.com//nish/commit/123334444555). Unlock to proceed." ,
374
+ Summary : "This deploy is locked from a manual deployment for revision [123334444555](https://github.com//nish/commit/123334444555). Unlock to proceed.\n Revisions in queue: 12333444455 " ,
336
375
Actions : []github.CheckRunAction {github .CreateUnlockAction ()},
337
376
State : github .CheckRunActionRequired ,
338
377
},
@@ -346,6 +385,7 @@ func TestEnqueue_MergeTrigger_QueueAlreadyLocked(t *testing.T) {
346
385
assert .NoError (t , err )
347
386
348
387
assert .Equal (t , []terraformWorkflow.DeploymentInfo {
388
+ deploymentInfo ,
349
389
{
350
390
Commit : github.Commit {
351
391
Revision : rev ,
0 commit comments