Skip to content

Commit

Permalink
Fix test failure (#33080)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR


### Issues associated with this PR


### Describe the problem that is addressed by this PR


### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_


### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [ ] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
  • Loading branch information
EmmaZhu authored Feb 17, 2025
1 parent 211da23 commit c3e4a5a
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ describe("Highlevel browser only", () => {
});

it("upload should work with Blob, ArrayBuffer and ArrayBufferView", async () => {
async function assertSameBlob(actualBlob: Blob | undefined, expectedBlob: Blob) {
if (!actualBlob) {
throw new Error("actualBlob is undefined");
}
assert.equal(actualBlob.size, expectedBlob.size);
const actualData = new Uint8Array(await actualBlob.arrayBuffer());
const expectedData = new Uint8Array(await expectedBlob.arrayBuffer());

const actualValues = Array.from(actualData.values());
const expectedValues = Array.from(expectedData.values());

assert.deepStrictEqual(actualValues, expectedValues);
assert.ok(arrayBufferEqual(actualData.buffer, expectedData.buffer));
}

const byteLength = 10;
const arrayBuf = new ArrayBuffer(byteLength);
const uint8Array = new Uint8Array(arrayBuf);
Expand All @@ -167,16 +182,17 @@ describe("Highlevel browser only", () => {
const uint8ArrayPartial = new Uint8Array(arrayBuf, 1, 3);
await fileClient.upload(uint8ArrayPartial);
const downloadedBlob2 = await (await fileClient.read()).contentAsBlob!;
assert.ok(arrayBufferEqual(await downloadedBlob2.arrayBuffer(), uint8ArrayPartial.buffer));
await assertSameBlob(
downloadedBlob2,
new Blob([uint8ArrayPartial], { type: "application/octet-stream" }),
);

const uint16Array = new Uint16Array(arrayBuf, 4, 2);
await fileClient.upload(uint16Array);
const downloadedBlob3 = await (await fileClient.read()).contentAsBlob!;
assert.ok(
arrayBufferEqual(
await downloadedBlob3.arrayBuffer(),
new Uint8Array(uint16Array.buffer, uint16Array.byteOffset, uint16Array.byteLength).buffer,
),
await assertSameBlob(
downloadedBlob3,
new Blob([uint16Array], { type: "application/octet-stream" }),
);
});
});

0 comments on commit c3e4a5a

Please sign in to comment.