Skip to content

Commit

Permalink
Deduplicate bucket creation logic
Browse files Browse the repository at this point in the history
Issue: ZENKO-4889
  • Loading branch information
williamlardier committed Sep 24, 2024
1 parent 59a887a commit d679dad
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions tests/ctst/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,36 +101,31 @@ Given('an account', async function (this: Zenko) {
await this.createAccount();
});

Given('a {string} bucket with dot', async function (this: Zenko, versioning: string) {
this.resetCommand();
const preName = this.getSaved<string>('accountName') ||
this.parameters.AccountName || Constants.ACCOUNT_NAME;
const bucketName = `${preName}.${Constants.BUCKET_NAME_TEST}${Utils.randomString()}`.toLocaleLowerCase();
this.addToSaved('bucketName', bucketName);
this.addCommandParameter({ bucket: bucketName });
await S3.createBucket(this.getCommandParameters());
this.addToSaved('bucketVersioning', versioning);
async function createBucket(world: Zenko, versioning: string, bucketName: string) {
world.resetCommand();
world.addToSaved('bucketName', bucketName);
world.addCommandParameter({ bucket: bucketName });
await S3.createBucket(world.getCommandParameters());
world.addToSaved('bucketVersioning', versioning);
if (versioning !== 'Non versioned') {
const versioningConfiguration = versioning === 'Versioned' ? 'Enabled' : 'Suspended';
this.addCommandParameter({ versioningConfiguration: `Status=${versioningConfiguration}` });
await S3.putBucketVersioning(this.getCommandParameters());
world.addCommandParameter({ versioningConfiguration: `Status=${versioningConfiguration}` });
await S3.putBucketVersioning(world.getCommandParameters());
}
}

Given('a {string} bucket with dot', async function (this: Zenko, versioning: string) {
const preName = this.getSaved<string>('accountName') ||
this.parameters.AccountName || Constants.ACCOUNT_NAME;
await createBucket(this, versioning,
`${preName}.${Constants.BUCKET_NAME_TEST}${Utils.randomString()}`.toLocaleLowerCase());
});

Given('a {string} bucket', async function (this: Zenko, versioning: string) {
this.resetCommand();
const preName = this.getSaved<string>('accountName') ||
this.parameters.AccountName || Constants.ACCOUNT_NAME;
const bucketName = `${preName}${Constants.BUCKET_NAME_TEST}${Utils.randomString()}`.toLocaleLowerCase();
this.addToSaved('bucketName', bucketName);
this.addCommandParameter({ bucket: bucketName });
await S3.createBucket(this.getCommandParameters());
this.addToSaved('bucketVersioning', versioning);
if (versioning !== 'Non versioned') {
const versioningConfiguration = versioning === 'Versioned' ? 'Enabled' : 'Suspended';
this.addCommandParameter({ versioningConfiguration: `Status=${versioningConfiguration}` });
await S3.putBucketVersioning(this.getCommandParameters());
}
await createBucket(this, versioning,
`${preName}${Constants.BUCKET_NAME_TEST}${Utils.randomString()}`.toLocaleLowerCase());
});

Given('an existing bucket {string} {string} versioning, {string} ObjectLock {string} retention mode', async function
Expand Down

0 comments on commit d679dad

Please sign in to comment.