-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Theodo-UK/feature/s3-assertion-bucket-exists
Add S3 assertion toExist(bucketName)
- Loading branch information
Showing
2 changed files
with
53 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { AWSClient } from "../../helpers/general"; | ||
|
||
export default { | ||
async toExistAsS3Bucket(bucketName) { | ||
const s3 = new AWSClient.S3(); | ||
const params = { | ||
Bucket: bucketName, | ||
}; | ||
|
||
let testResult; | ||
try { | ||
await s3.headBucket(params).promise(); | ||
testResult = { | ||
message: () => `expected S3 bucket to exist with name ${bucketName}`, | ||
pass: true, | ||
}; | ||
} catch (error) { | ||
if (error.statusCode === 404) { | ||
testResult = { | ||
message: () => | ||
`expected S3 bucket to exist with name ${bucketName} - not found`, | ||
pass: false, | ||
}; | ||
} else { | ||
throw error; | ||
} | ||
} | ||
|
||
return testResult; | ||
}, | ||
}; |