Skip to content

Commit

Permalink
Fixes grafana#105
Browse files Browse the repository at this point in the history
  • Loading branch information
KOConchobhair committed Jun 17, 2024
1 parent 89ab1e4 commit 41a245c
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"globals": {
// Allow specific global types present in the k6 JS runtime natively
"ArrayBuffer": "readonly",
"Uint8Array": "readonly",
"Set": "readonly",
"console": "readonly",
Expand Down
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 mandrill.tiff"
testdata_files="bonjour.txt tschuss.txt delete.txt z-load-impact.png"

# Create the test-jslib-aws bucket
awslocal s3api create-bucket \
Expand Down
Binary file removed localstack/init/testdata/s3/mandrill.tiff
Binary file not shown.
Binary file added localstack/init/testdata/s3/z-load-impact.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@babel/plugin-transform-block-scoping": "^7.14.1",
"@babel/preset-env": "^7.4.4",
"@babel/preset-typescript": "^7.16.7",
"@types/k6": "^0.45.0",
"@types/k6": "^0.51.0",
"@types/uuid": "^3.4.0",
"@types/webpack": "^5.28.0",
"@typescript-eslint/eslint-plugin": "^6.11.0",
Expand Down
11 changes: 5 additions & 6 deletions src/internal/s3.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { bytes } from 'k6'
import { parseHTML } from 'k6/html'
import http, { RefinedResponse, ResponseType } from 'k6/http'

Expand Down Expand Up @@ -166,7 +165,7 @@ export class S3Client extends AWSClient {
*
* @param {string} bucketName - The bucket name containing the object.
* @param {string} objectKey - Key of the object to get.
* @param {string} responseType - The desired interpretation of the response body ('text' or 'binary')
* @param {string} responseType - The desired interpretation of the response body ('text' or 'binary').
* @return {S3Object} - returns the content of the fetched S3 Object.
* @throws {S3ServiceError}
* @throws {InvalidSignatureError}
Expand All @@ -191,7 +190,7 @@ export class S3Client extends AWSClient {

const res = await http.asyncRequest(method, signedRequest.url, null, {
headers: signedRequest.headers,
responseType: responseType,
responseType: responseType as ResponseType,
})
this._handle_error('GetObject', res)

Expand Down Expand Up @@ -546,7 +545,7 @@ export class S3Object {
etag: string
size: number
storageClass: StorageClass
data?: string | bytes | null
data?: string | ArrayBuffer | null

/**
* Create an S3 Object
Expand All @@ -556,15 +555,15 @@ export class S3Object {
* @param {string} etag - S3 object's etag
* @param {number} size - S3 object's size
* @param {StorageClass} storageClass - S3 object's storage class
* @param {string | bytes | null} data=null - S3 Object's data
* @param {string | ArrayBuffer | null} data=null - S3 Object's data
*/
constructor(
key: string,
lastModified: number,
etag: string,
size: number,
storageClass: StorageClass,
data?: string | bytes | null
data?: string | ArrayBuffer | null
) {
this.key = key
this.lastModified = lastModified
Expand Down
4 changes: 2 additions & 2 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const testData = {
body: 'Delete me in a test!',
},
{
key: 'mandrill.tiff',
body: open('../localstack/init/testdata/s3/mandrill.tiff', 'b'),
key: 'z-load-impact.png',
body: open('../localstack/init/testdata/s3/z-load-impact.png', 'b'),
},
],
},
Expand Down
7 changes: 4 additions & 3 deletions tests/internal/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function s3TestSuite(data) {
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')
expect(objects[3].key).to.equal('z-load-impact.png')
})

await asyncDescribe('s3.getObject', async (expect) => {
Expand Down Expand Up @@ -75,8 +75,9 @@ export async function s3TestSuite(data) {
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.data).to.be.an.instanceof(ArrayBuffer)
expect(gotBinaryObject.key).to.equal(data.s3.testObjects[3].key)
expect(gotBinaryObject.data).to.equal(data.s3.testObjects[3].body)
expect(gotBinaryObject.data.byteLength).to.equal(data.s3.testObjects[3].body.byteLength)
expect(getObjectFromNonExistingBucketError).to.not.be.undefined
expect(getObjectFromNonExistingBucketError).to.be.an.instanceOf(S3ServiceError)
expect(getNonExistingObjectError).to.not.be.undefined
Expand Down Expand Up @@ -111,7 +112,7 @@ export async function s3TestSuite(data) {

let deleteFromNonExistingBucketError
try {
await s3Client.deleteObject('non-existent-bucket', data.s3.testObjects[2].key)
await s3Client.deleteObject('non-existent-bucket', data.s3.testObject3[2].key)
} catch (error) {
deleteFromNonExistingBucketError = error
}
Expand Down

0 comments on commit 41a245c

Please sign in to comment.