Skip to content

Commit

Permalink
chore: fix bucket test and ignore sdk test snapshots (#6430)
Browse files Browse the repository at this point in the history
Test passed locally with `-t tf-aws`. Addressing https://github.com/winglang/wing/actions/runs/8980157087/job/24677053144

This unifies the error message across targets

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
  • Loading branch information
MarkMcCulloh authored May 7, 2024
1 parent 4c8fc8d commit b1d0127
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions examples/tests/sdk_tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**.snap.md
4 changes: 2 additions & 2 deletions examples/tests/sdk_tests/bucket/get.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ test "get range of an object" {

expect.equal(b.get("test2.txt", startByte: 0, endByte: 3), "𠮷");

assertThrows("Unable to read object (key=test2.txt range=[0,2])", () => {
assertThrows("The encoded data was not valid for encoding utf-8", () => {
b.get("test2.txt", startByte: 0, endByte: 2);
});
});
}

test "get empty object" {
Expand Down
18 changes: 13 additions & 5 deletions libs/wingsdk/src/shared-gcp/bucket.inflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,22 @@ export class BucketClient implements IBucketClient {
}

public async get(key: string, options?: BucketGetOptions): Promise<string> {
const body = await this.bucket
.file(key)
.download({ start: options?.startByte, end: options?.endByte })
.catch((e) => {
throw new Error(
`Failed to get object (key=${key}): ${(e as Error).stack})}`
);
});

try {
const body = await this.bucket
.file(key)
.download({ start: options?.startByte, end: options?.endByte });
return new TextDecoder("utf8", { fatal: true }).decode(body[0]);
} catch (error) {
} catch (e) {
throw new Error(
`Failed to get object. (key=${key}) ${(error as Error).stack}`
`Object content could not be read as text (key=${key}): ${
(e as Error).stack
})}`
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions libs/wingsdk/src/target-sim/bucket.inflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ export class Bucket implements IBucketClient, ISimulatorResourceInstance {

try {
return new TextDecoder("utf8", { fatal: true }).decode(buffer);
} catch {
const start = options?.startByte ?? -1;
const end = options?.endByte ?? -1;
} catch (e) {
throw new Error(
`Unable to read object (key=${key} range=[${start},${end}]).`
`Object content could not be read as text (key=${key}): ${
(e as Error).stack
})}`
);
}
},
Expand Down
3 changes: 1 addition & 2 deletions libs/wingsdk/test/shared-gcp/bucket.inflight.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ test("get a non-existent object from the bucket", async () => {
const storage = new MockStorage();

const client = new BucketClient(BUCKET_NAME, storage as any);

await expect(() => client.get(NON_EXISTENT_KEY)).rejects.toThrowError(
`Failed to get object. (key=${NON_EXISTENT_KEY})`
/Failed to get object \(key=NON_EXISTENT_KEY\)/
);
});

Expand Down

0 comments on commit b1d0127

Please sign in to comment.