1
- import { When , Then } from '@cucumber/cucumber' ;
1
+ import { Given , When , Then } from '@cucumber/cucumber' ;
2
2
import Zenko from '../world/Zenko' ;
3
3
import { createAndRunPod , getMongoDBConfig , getZenkoVersion } from 'steps/utils/kubernetes' ;
4
4
import assert from 'assert' ;
5
- import { GetObjectCommand } from '@aws-sdk/client-s3' ;
5
+ import {
6
+ GetObjectCommand ,
7
+ DeleteBucketCommand ,
8
+ CreateBucketCommand ,
9
+ PutBucketVersioningCommand
10
+ } from '@aws-sdk/client-s3' ;
6
11
import { v4 as uuidv4 } from 'uuid' ;
7
12
import { getObject , headObject , getReplicationLocationConfig } from 'steps/utils/utils' ;
8
13
import { safeJsonParse } from 'common/utils' ;
14
+ import { replicationLockTags } from 'common/hooks' ;
9
15
10
- When ( 'I run the job to replicate existing objects with status {string}' ,
16
+ When ( 'the job to replicate existing objects with status {string} is executed ' ,
11
17
{ timeout : 600000 } ,
12
18
async function (
13
19
this : Zenko ,
@@ -83,12 +89,12 @@ When('I run the job to replicate existing objects with status {string}',
83
89
await createAndRunPod ( this , podManifest ) ;
84
90
} ) ;
85
91
86
- Then ( 'the object should eventually be replicated' ,
87
- async function ( this : Zenko ) {
92
+ Then ( 'the object should eventually {string} replicated' , { timeout : 360_000 } ,
93
+ async function ( this : Zenko , replicate : 'be' | 'fail to be' ) {
88
94
const objectName = this . getSaved < string > ( 'objectName' ) ;
89
95
const bucketSource = this . getSaved < string > ( 'bucketName' ) ;
90
96
const startTime = Date . now ( ) ;
91
- const replicationTimeoutMs = 90_000 ;
97
+ const replicationTimeoutMs = 300_000 ;
92
98
while ( Date . now ( ) - startTime < replicationTimeoutMs ) {
93
99
await new Promise ( resolve => setTimeout ( resolve , 3000 ) ) ;
94
100
@@ -105,15 +111,27 @@ Then('the object should eventually be replicated',
105
111
} > ( response . stdout || '{}' ) ;
106
112
assert ( parsed . ok ) ;
107
113
const replicationStatus = parsed . result ?. ReplicationStatus ;
108
- assert . notStrictEqual ( replicationStatus , 'FAILED' , `replication failed for object ${ objectName } ` ) ;
109
- if ( replicationStatus === 'COMPLETED' ) {
110
- return ;
114
+
115
+ if ( replicate === 'be' ) {
116
+ assert . notStrictEqual ( replicationStatus , 'FAILED' , `replication failed for object ${ objectName } ` ) ;
117
+ if ( replicationStatus === 'COMPLETED' ) {
118
+ return ;
119
+ }
120
+ } else if ( replicate === 'fail to be' ) {
121
+ assert . notStrictEqual (
122
+ replicationStatus ,
123
+ 'COMPLETED' ,
124
+ `expected replication to fail for object ${ objectName } `
125
+ ) ;
126
+ if ( replicationStatus === 'FAILED' ) {
127
+ return ;
128
+ }
111
129
}
112
130
if ( replicationStatus === 'PENDING' || replicationStatus === 'PROCESSING' ) {
113
131
continue ;
114
132
}
115
133
}
116
- assert . fail ( `Timeout: Object '${ objectName } ' was not replicated successfully until timeout` ) ;
134
+ assert . fail ( `Timeout: Object '${ objectName } ' is still pending/processing after timeout` ) ;
117
135
} ) ;
118
136
119
137
Then (
@@ -173,3 +191,41 @@ Then(
173
191
'REPLICA'
174
192
) ;
175
193
} ) ;
194
+
195
+ Given ( 'a deleted destination bucket on that location' , async function ( this : Zenko ) {
196
+ const replicationLocation = this . getSaved < string > ( 'replicationLocation' ) ;
197
+ const scenarioTags = this . getSaved < string [ ] > ( 'scenarioTags' ) || [ ] ;
198
+ const lockTag = `@Lock${ replicationLocation } ` ;
199
+ const hasTestLock = scenarioTags . includes ( lockTag ) ;
200
+ assert . strictEqual (
201
+ hasTestLock , true ,
202
+ 'This step can only be run when the tag @Lock$replicationLocation is configured'
203
+ ) ;
204
+ assert . strictEqual (
205
+ true , replicationLockTags . includes ( lockTag ) ,
206
+ `The tag ${ lockTag } must be added to the replicationLockTags array in common/hooks.ts`
207
+ ) ;
208
+
209
+ const { destinationBucket, awsS3Client } =
210
+ await getReplicationLocationConfig ( this , replicationLocation ) ;
211
+ const command = new DeleteBucketCommand ( {
212
+ Bucket : destinationBucket ,
213
+ } ) ;
214
+ await awsS3Client . send ( command ) ;
215
+ } ) ;
216
+
217
+ When ( 'the destination bucket on the location is created again' , async function ( this : Zenko ) {
218
+ const { destinationBucket, awsS3Client } =
219
+ await getReplicationLocationConfig ( this , this . getSaved < string > ( 'replicationLocation' ) ) ;
220
+ const command = new CreateBucketCommand ( {
221
+ Bucket : destinationBucket ,
222
+ } ) ;
223
+ await awsS3Client . send ( command ) ;
224
+ const versioningCommand = new PutBucketVersioningCommand ( {
225
+ Bucket : destinationBucket ,
226
+ VersioningConfiguration : {
227
+ Status : 'Enabled' ,
228
+ } ,
229
+ } ) ;
230
+ await awsS3Client . send ( versioningCommand ) ;
231
+ } ) ;
0 commit comments