Skip to content

Commit c3e4a5a

Browse files
authored
Fix test failure (#33080)
### 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)
1 parent 211da23 commit c3e4a5a

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

Diff for: sdk/storage/storage-file-datalake/test/browser/highlevel.browser.spec.ts

+22-6
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ describe("Highlevel browser only", () => {
148148
});
149149

150150
it("upload should work with Blob, ArrayBuffer and ArrayBufferView", async () => {
151+
async function assertSameBlob(actualBlob: Blob | undefined, expectedBlob: Blob) {
152+
if (!actualBlob) {
153+
throw new Error("actualBlob is undefined");
154+
}
155+
assert.equal(actualBlob.size, expectedBlob.size);
156+
const actualData = new Uint8Array(await actualBlob.arrayBuffer());
157+
const expectedData = new Uint8Array(await expectedBlob.arrayBuffer());
158+
159+
const actualValues = Array.from(actualData.values());
160+
const expectedValues = Array.from(expectedData.values());
161+
162+
assert.deepStrictEqual(actualValues, expectedValues);
163+
assert.ok(arrayBufferEqual(actualData.buffer, expectedData.buffer));
164+
}
165+
151166
const byteLength = 10;
152167
const arrayBuf = new ArrayBuffer(byteLength);
153168
const uint8Array = new Uint8Array(arrayBuf);
@@ -167,16 +182,17 @@ describe("Highlevel browser only", () => {
167182
const uint8ArrayPartial = new Uint8Array(arrayBuf, 1, 3);
168183
await fileClient.upload(uint8ArrayPartial);
169184
const downloadedBlob2 = await (await fileClient.read()).contentAsBlob!;
170-
assert.ok(arrayBufferEqual(await downloadedBlob2.arrayBuffer(), uint8ArrayPartial.buffer));
185+
await assertSameBlob(
186+
downloadedBlob2,
187+
new Blob([uint8ArrayPartial], { type: "application/octet-stream" }),
188+
);
171189

172190
const uint16Array = new Uint16Array(arrayBuf, 4, 2);
173191
await fileClient.upload(uint16Array);
174192
const downloadedBlob3 = await (await fileClient.read()).contentAsBlob!;
175-
assert.ok(
176-
arrayBufferEqual(
177-
await downloadedBlob3.arrayBuffer(),
178-
new Uint8Array(uint16Array.buffer, uint16Array.byteOffset, uint16Array.byteLength).buffer,
179-
),
193+
await assertSameBlob(
194+
downloadedBlob3,
195+
new Blob([uint16Array], { type: "application/octet-stream" }),
180196
);
181197
});
182198
});

0 commit comments

Comments
 (0)