Skip to content

Commit

Permalink
Add test for listBlobsFlat
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshaNalluru committed May 28, 2019
1 parent cdd3d2e commit 43d30c0
Showing 1 changed file with 56 additions and 28 deletions.
84 changes: 56 additions & 28 deletions sdk/storage/storage-blob/test/containerclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ describe("ContainerClient", () => {
});

it("create with all parameters configured", async () => {
const cClient = ContainerClient.fromBlobServiceClient(blobServiceClient, getUniqueName(containerName));
const cClient = ContainerClient.fromBlobServiceClient(
blobServiceClient,
getUniqueName(containerName)
);
const metadata = { key: "value" };
const access = "container";
await cClient.create({ metadata, access });
Expand Down Expand Up @@ -231,6 +234,43 @@ describe("ContainerClient", () => {
}
});

it("Verify AsyncIterator for listBlobsFlat", async () => {
const blobClients = [];
const prefix = "blockblob";
const metadata = {
keya: "a",
keyb: "c"
};
for (let i = 0; i < 2; i++) {
const blobClient = BlobClient.fromContainerClient(
containerClient,
getUniqueName(`${prefix}/${i}`)
);
const blockBlobClient = BlockBlobClient.fromBlobClient(blobClient);
await blockBlobClient.upload("", 0, {
metadata
});
blobClients.push(blobClient);
}

const iterator = await containerClient.listBlobsFlat({
include: ["snapshots", "metadata", "uncommittedblobs", "copy", "deleted"],
prefix
});

let blobItem = await iterator.next();
assert.ok(blobClients[0].url.indexOf(blobItem.value.name));
assert.deepStrictEqual(blobItem.value.metadata, metadata);

blobItem = await iterator.next();
assert.ok(blobClients[1].url.indexOf(blobItem.value.name));
assert.deepStrictEqual(blobItem.value.metadata, metadata);

for (const blob of blobClients) {
await blob.delete();
}
});

it("listBlobHierarchySegment with default parameters", async () => {
const blobClients = [];
for (let i = 0; i < 3; i++) {
Expand Down Expand Up @@ -281,45 +321,33 @@ describe("ContainerClient", () => {
blobClients.push(blobClient);
}

const result = await containerClient.listBlobHierarchySegment(
delimiter,
undefined,
{
include: ["metadata", "uncommittedblobs", "copy", "deleted"],
maxresults: 1,
prefix
}
);
const result = await containerClient.listBlobHierarchySegment(delimiter, undefined, {
include: ["metadata", "uncommittedblobs", "copy", "deleted"],
maxresults: 1,
prefix
});
assert.ok(result.serviceEndpoint.length > 0);
assert.ok(containerClient.url.indexOf(result.containerName));
assert.deepStrictEqual(result.segment.blobPrefixes!.length, 1);
assert.deepStrictEqual(result.segment.blobItems!.length, 0);
assert.ok(blobClients[0].url.indexOf(result.segment.blobPrefixes![0].name));

const result2 = await containerClient.listBlobHierarchySegment(
delimiter,
result.nextMarker,
{
include: ["metadata", "uncommittedblobs", "copy", "deleted"],
maxresults: 2,
prefix
}
);
const result2 = await containerClient.listBlobHierarchySegment(delimiter, result.nextMarker, {
include: ["metadata", "uncommittedblobs", "copy", "deleted"],
maxresults: 2,
prefix
});
assert.ok(result2.serviceEndpoint.length > 0);
assert.ok(containerClient.url.indexOf(result2.containerName));
assert.deepStrictEqual(result2.segment.blobPrefixes!.length, 1);
assert.deepStrictEqual(result2.segment.blobItems!.length, 0);
assert.ok(blobClients[0].url.indexOf(result2.segment.blobPrefixes![0].name));

const result3 = await containerClient.listBlobHierarchySegment(
delimiter,
undefined,
{
include: ["metadata", "uncommittedblobs", "copy", "deleted"],
maxresults: 2,
prefix: `${prefix}0${delimiter}`
}
);
const result3 = await containerClient.listBlobHierarchySegment(delimiter, undefined, {
include: ["metadata", "uncommittedblobs", "copy", "deleted"],
maxresults: 2,
prefix: `${prefix}0${delimiter}`
});
assert.ok(result3.serviceEndpoint.length > 0);
assert.ok(containerClient.url.indexOf(result3.containerName));
assert.deepStrictEqual(result3.nextMarker, "");
Expand Down

0 comments on commit 43d30c0

Please sign in to comment.