11const assert = require ( 'assert' ) ;
22const async = require ( 'async' ) ;
3+ const {
4+ CreateBucketCommand,
5+ DeleteBucketCommand,
6+ PutBucketVersioningCommand,
7+ PutBucketReplicationCommand,
8+ DeleteBucketReplicationCommand,
9+ } = require ( '@aws-sdk/client-s3' ) ;
310
411const withV4 = require ( '../support/withV4' ) ;
512const BucketUtility = require ( '../../lib/utility/bucket-util' ) ;
613
714const bucketName = `versioning-bucket-${ Date . now ( ) } ` ;
815
9-
1016function checkError ( err , code ) {
1117 assert . notEqual ( err , null , 'Expected failure but got success' ) ;
12- assert . strictEqual ( err . code , code ) ;
18+ assert . strictEqual ( err . name , code ) ;
1319}
1420
1521function checkNoError ( err ) {
1622 assert . ifError ( err , `Expected success, got error ${ JSON . stringify ( err ) } ` ) ;
1723}
1824
1925function testVersioning ( s3 , versioningStatus , replicationStatus , removeReplication , cb ) {
20- const versioningParams = { Bucket : bucketName ,
21- VersioningConfiguration : { Status : versioningStatus } } ;
26+ const versioningParams = {
27+ Bucket : bucketName ,
28+ VersioningConfiguration : { Status : versioningStatus }
29+ } ;
2230 const replicationParams = {
2331 Bucket : bucketName ,
2432 ReplicationConfiguration : {
@@ -36,15 +44,22 @@ function testVersioning(s3, versioningStatus, replicationStatus, removeReplicati
3644 ] ,
3745 } ,
3846 } ;
47+
3948 async . waterfall ( [
40- cb => s3 . putBucketReplication ( replicationParams , e => cb ( e ) ) ,
49+ cb => s3 . send ( new PutBucketReplicationCommand ( replicationParams ) )
50+ . then ( ( ) => cb ( ) )
51+ . catch ( cb ) ,
4152 cb => {
4253 if ( removeReplication ) {
43- return s3 . deleteBucketReplication ( { Bucket : bucketName } , e => cb ( e ) ) ;
54+ return s3 . send ( new DeleteBucketReplicationCommand ( { Bucket : bucketName } ) )
55+ . then ( ( ) => cb ( ) )
56+ . catch ( cb ) ;
4457 }
4558 return process . nextTick ( ( ) => cb ( ) ) ;
4659 } ,
47- cb => s3 . putBucketVersioning ( versioningParams , e => cb ( e ) ) ,
60+ cb => s3 . send ( new PutBucketVersioningCommand ( versioningParams ) )
61+ . then ( ( ) => cb ( ) )
62+ . catch ( cb ) ,
4863 ] , cb ) ;
4964}
5065
@@ -55,17 +70,23 @@ describe('Versioning on a replication source bucket', () => {
5570
5671 beforeEach ( done => {
5772 async . waterfall ( [
58- cb => s3 . createBucket ( { Bucket : bucketName } , e => cb ( e ) ) ,
59- cb => s3 . putBucketVersioning ( {
73+ cb => s3 . send ( new CreateBucketCommand ( { Bucket : bucketName } ) )
74+ . then ( ( ) => cb ( ) )
75+ . catch ( cb ) ,
76+ cb => s3 . send ( new PutBucketVersioningCommand ( {
6077 Bucket : bucketName ,
6178 VersioningConfiguration : {
6279 Status : 'Enabled' ,
6380 } ,
64- } , err => cb ( err ) ) ,
81+ } ) )
82+ . then ( ( ) => cb ( ) )
83+ . catch ( cb ) ,
6584 ] , done ) ;
6685 } ) ;
6786
68- afterEach ( done => s3 . deleteBucket ( { Bucket : bucketName } , done ) ) ;
87+ afterEach ( async ( ) => {
88+ await s3 . send ( new DeleteBucketCommand ( { Bucket : bucketName } ) ) ;
89+ } ) ;
6990
7091 it ( 'should not be able to disable versioning if replication enabled' ,
7192 done => {
0 commit comments