|
| 1 | +import { assertEquals } from "../test_deps.ts"; |
| 2 | +import { S3Bucket } from "./bucket.ts"; |
| 3 | + |
| 4 | +const bucket: S3Bucket = Object.create(S3Bucket.prototype) |
| 5 | + |
| 6 | +Deno.test("[response parsing]", async (t) => { |
| 7 | + await t.step("parseListObjectResponseXml", async (t) => { |
| 8 | + await t.step("commonPrefixes", () => { |
| 9 | + // https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#API_ListObjectsV2_Example_8 |
| 10 | + const xml = `<?xml version='1.0' encoding='utf-8' ?> |
| 11 | + <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> |
| 12 | + <Name>example-bucket</Name> |
| 13 | + <Prefix>photos/2006/</Prefix> |
| 14 | + <Marker></Marker> |
| 15 | + <MaxKeys>1000</MaxKeys> |
| 16 | + <Delimiter>/</Delimiter> |
| 17 | + <IsTruncated>false</IsTruncated> |
| 18 | + <CommonPrefixes> |
| 19 | + <Prefix>photos/2006/February/</Prefix> |
| 20 | + </CommonPrefixes> |
| 21 | + <CommonPrefixes> |
| 22 | + <Prefix>photos/2006/January/</Prefix> |
| 23 | + </CommonPrefixes> |
| 24 | + </ListBucketResult>`; |
| 25 | + |
| 26 | + assertEquals(bucket["parseListObjectResponseXml"](xml).commonPrefixes, [ |
| 27 | + { prefix: "photos/2006/February/" }, |
| 28 | + { prefix: "photos/2006/January/" }, |
| 29 | + ]); |
| 30 | + }); |
| 31 | + |
| 32 | + await t.step("commonPrefixes with entity escapes", () => { |
| 33 | + const xml = `<?xml version='1.0' encoding='utf-8' ?> |
| 34 | + <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> |
| 35 | + <Name>example-bucket</Name> |
| 36 | + <Prefix>photos/2006/</Prefix> |
| 37 | + <Marker></Marker> |
| 38 | + <MaxKeys>1000</MaxKeys> |
| 39 | + <Delimiter>/</Delimiter> |
| 40 | + <IsTruncated>false</IsTruncated> |
| 41 | + <CommonPrefixes> |
| 42 | + <Prefix>photos/2006/a&b/</Prefix> |
| 43 | + </CommonPrefixes> |
| 44 | + </ListBucketResult>`; |
| 45 | + |
| 46 | + assertEquals(bucket["parseListObjectResponseXml"](xml).commonPrefixes, [ |
| 47 | + { prefix: "photos/2006/a&b/" }, |
| 48 | + ]); |
| 49 | + }); |
| 50 | + }); |
| 51 | +}); |
0 commit comments