Skip to content

Commit

Permalink
repro
Browse files Browse the repository at this point in the history
  • Loading branch information
ljian3377 committed Oct 31, 2020
1 parent acb2510 commit 097a676
Showing 1 changed file with 63 additions and 1 deletion.
64 changes: 63 additions & 1 deletion sdk/storage/storage-blob/test/blobbatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
getGenericCredential,
getTokenCredential,
SimpleTokenCredential,
recorderEnvSetup
recorderEnvSetup,
getTokenBSU
} from "./utils";
import { record, Recorder } from "@azure/test-utils-recorder";
import { BlobBatch } from "../src";
Expand Down Expand Up @@ -672,4 +673,65 @@ describe("BlobBatch", () => {
}
assert.ok(exceptionCaught);
});

it.only("BlobBatch should work with token auth", async function () {
recorder.skip(
undefined,
"UUID is randomly generated within the SDK and used in the HTTP request and cannot be preserved."
);

// Try to get BlobServiceClient object with TokenCredential
// when ACCOUNT_TOKEN environment variable is set
let blobServiceClientWithToken: BlobServiceClient | undefined;
try {
blobServiceClientWithToken = getTokenBSU();
} catch {}
// Requires bearer token for this case which cannot be generated in the runtime
// Make sure this case passed in sanity test
if (blobServiceClientWithToken === undefined) {
this.skip();
}

blobBatchClient = blobServiceClientWithToken.getBlobBatchClient();
const credential = blobServiceClientWithToken?.credential;
containerName = recorder.getUniqueName("container");
containerClient = blobServiceClientWithToken.getContainerClient(containerName);
await containerClient.create();

for (let i = 0; i < blockBlobCount - 1; i++) {
let tmpBlobName = `blob${i}`;
let tmpBlockBlobClient = containerClient.getBlockBlobClient(tmpBlobName);
blockBlobClients[i] = tmpBlockBlobClient;
}

let specialBlobName = `å ä ö`;
let tmpBlockBlobClient = containerClient.getBlockBlobClient(specialBlobName);
blockBlobClients[blockBlobCount - 1] = tmpBlockBlobClient;

// Upload blobs.
for (let i = 0; i < blockBlobCount; i++) {
await blockBlobClients[i].upload(content, content.length);
}

// Assemble batch delete request.
let batchDeleteRequest = new BlobBatch();
for (let i = 0; i < blockBlobCount; i++) {
await batchDeleteRequest.deleteBlob(blockBlobClients[i].url, credential, {});
}

// Submit batch request and verify response.
const resp = await blobBatchClient.submitBatch(batchDeleteRequest, {});
assert.equal(resp.subResponses.length, blockBlobCount);
assert.equal(resp.subResponsesSucceededCount, blockBlobCount);
assert.equal(resp.subResponsesFailedCount, 0);

for (let i = 0; i < blockBlobCount; i++) {
assert.equal(resp.subResponses[i].errorCode, undefined);
assert.equal(resp.subResponses[i].status, 202);
assert.ok(resp.subResponses[i].statusMessage != "");
assert.ok(resp.subResponses[i].headers.contains("x-ms-request-id"));
assert.equal(resp.subResponses[i]._request.url, blockBlobClients[i].url);
}
});

});

0 comments on commit 097a676

Please sign in to comment.