Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
KOConchobhair committed Jun 7, 2024
1 parent b3d705c commit 31d8f3c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion localstack/init/ready.d/s3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ BUCKET="test-jslib-aws"
# The localstack exposes its init script in the `/etc/localstack/init` folder.
# For convinience we've setup a `testdata` folder in the same directory.
testdata_folder="/etc/localstack/init/testdata/s3"
testdata_files="bonjour.txt tschuss.txt delete.txt"
testdata_files="bonjour.txt tschuss.txt delete.txt mandrill.tiff"

# Create the test-jslib-aws bucket
awslocal s3api create-bucket \
Expand Down
Binary file added localstack/init/testdata/s3/mandrill.tiff
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const testData = {
key: 'delete.txt',
body: 'Delete me in a test!',
},
{
key: 'mandrill.tiff',
body: open('../localstack/init/testdata/s3/mandrill.tiff', 'b'),
},
],
},

Expand Down
12 changes: 11 additions & 1 deletion tests/internal/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ export async function s3TestSuite(data) {

// Assert
expect(objects).to.be.an('array')
expect(objects).to.have.lengthOf(3)
expect(objects).to.have.lengthOf(4)
expect(objects[0].key).to.equal('bonjour.txt')
expect(objects[1].key).to.equal('delete.txt')
expect(objects[2].key).to.equal('tschuss.txt')
expect(objects[3].key).to.equal('mandrill.tiff')
})

await asyncDescribe('s3.getObject', async (expect) => {
Expand All @@ -46,6 +47,12 @@ export async function s3TestSuite(data) {
data.s3.testObjects[1].key
)

const gotBinaryObject = await s3Client.getObject(
data.s3.testBucketName,
data.s3.testObjects[3].key,
'binary'
)

let getObjectFromNonExistingBucketError
try {
await s3Client.getObject('non-existent-bucket', data.s3.testObjects[0].key)
Expand All @@ -67,6 +74,9 @@ export async function s3TestSuite(data) {
expect(gotSecondObject).to.be.an('object')
expect(gotSecondObject.key).to.equal(data.s3.testObjects[1].key)
expect(gotSecondObject.data).to.equal(data.s3.testObjects[1].body)
expect(gotBinaryObject).to.be.an('object')
expect(gotBinaryObject.key).to.equal(data.s3.testObjects[3].key)
expect(gotBinaryObject.data).to.equal(data.s3.testObjects[3].body)
expect(getObjectFromNonExistingBucketError).to.not.be.undefined
expect(getObjectFromNonExistingBucketError).to.be.an.instanceOf(S3ServiceError)
expect(getNonExistingObjectError).to.not.be.undefined
Expand Down

0 comments on commit 31d8f3c

Please sign in to comment.