1- import { When , Then } from '@cucumber/cucumber' ;
1+ import { Given , When , Then } from '@cucumber/cucumber' ;
22import Zenko from '../world/Zenko' ;
33import { createAndRunPod , getMongoDBConfig , getZenkoVersion } from 'steps/utils/kubernetes' ;
44import 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' ;
611import { v4 as uuidv4 } from 'uuid' ;
712import { getObject , headObject , getReplicationLocationConfig } from 'steps/utils/utils' ;
813import { safeJsonParse } from 'common/utils' ;
914
10- When ( 'I run the job to replicate existing objects with status {string}' ,
15+ When ( 'we run the job to replicate existing objects with status {string}' ,
1116 { timeout : 600000 } ,
1217 async function (
1318 this : Zenko ,
@@ -83,12 +88,12 @@ When('I run the job to replicate existing objects with status {string}',
8388 await createAndRunPod ( this , podManifest ) ;
8489 } ) ;
8590
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' ) {
8893 const objectName = this . getSaved < string > ( 'objectName' ) ;
8994 const bucketSource = this . getSaved < string > ( 'bucketName' ) ;
9095 const startTime = Date . now ( ) ;
91- const replicationTimeoutMs = 90_000 ;
96+ const replicationTimeoutMs = 300_000 ;
9297 while ( Date . now ( ) - startTime < replicationTimeoutMs ) {
9398 await new Promise ( resolve => setTimeout ( resolve , 3000 ) ) ;
9499
@@ -105,15 +110,27 @@ Then('the object should eventually be replicated',
105110 } > ( response . stdout || '{}' ) ;
106111 assert ( parsed . ok ) ;
107112 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+ }
111128 }
112129 if ( replicationStatus === 'PENDING' || replicationStatus === 'PROCESSING' ) {
113130 continue ;
114131 }
115132 }
116- assert . fail ( `Timeout: Object '${ objectName } ' was not replicated successfully until timeout` ) ;
133+ assert . fail ( `Timeout: Object '${ objectName } ' is still pending/processing after timeout` ) ;
117134 } ) ;
118135
119136Then (
@@ -173,3 +190,28 @@ Then(
173190 'REPLICA'
174191 ) ;
175192 } ) ;
193+
194+ Given ( 'a deleted destination bucket on that location' , async function ( this : Zenko ) {
195+ const { destinationBucket, awsS3Client } =
196+ await getReplicationLocationConfig ( this , this . getSaved < string > ( 'replicationLocation' ) ) ;
197+ const command = new DeleteBucketCommand ( {
198+ Bucket : destinationBucket ,
199+ } ) ;
200+ await awsS3Client . send ( command ) ;
201+ } ) ;
202+
203+ When ( 'the destination bucket on the location is created again' , async function ( this : Zenko ) {
204+ const { destinationBucket, awsS3Client } =
205+ await getReplicationLocationConfig ( this , this . getSaved < string > ( 'replicationLocation' ) ) ;
206+ const command = new CreateBucketCommand ( {
207+ Bucket : destinationBucket ,
208+ } ) ;
209+ await awsS3Client . send ( command ) ;
210+ const versioningCommand = new PutBucketVersioningCommand ( {
211+ Bucket : destinationBucket ,
212+ VersioningConfiguration : {
213+ Status : 'Enabled' ,
214+ } ,
215+ } ) ;
216+ await awsS3Client . send ( versioningCommand ) ;
217+ } ) ;
0 commit comments