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