edge/pkg/module/blob/testdata/blob.js

79 lines
2.0 KiB
JavaScript

var ctx = context.new();
var buckets = blob.listBuckets(ctx);
if (!buckets || buckets.length === 0) {
throw new Error("buckets should not be empty");
}
var size = blob.getBucketSize(ctx, blob.DEFAULT_BUCKET);
if (size !== 0) {
throw new Error("bucket size: expected '0', got '"+size+"'");
}
var newBucket = "mybucket"
var blobId = "foo"
var data = (new Date()).toString();
blob.writeBlob(ctx, newBucket, blobId, data)
buckets = blob.listBuckets(ctx);
if (buckets.length !== 2) {
throw new Error("buckets.length: expected '2', got '"+buckets.length+"'");
}
size = blob.getBucketSize(ctx, newBucket);
if (size !== data.length) {
throw new Error("bucket size: expected '"+data.length+"', got '"+size+"'");
}
var blobInfos = blob.listBlobs(ctx, newBucket);
if (blobInfos.length !== 1) {
throw new Error("blobInfos.length: expected '1', got '"+blobInfos.length+"'");
}
if (blobInfos[0].id != blobId) {
throw new Error("blobInfos[0].id: expected '"+blobId+"', got '"+blobInfos[0].id+"'");
}
if (blobInfos[0].contentType != "text/plain; charset=utf-8") {
throw new Error("blobInfos[0].contentType: expected 'text/plain; charset=utf-8', got '"+blobInfos[0].contentType+"'");
}
if (blobInfos[0].size != data.length) {
throw new Error("blobInfos[0].size: expected '"+data.length+"', got '"+blobInfos[0].size+"'");
}
var readData = blob.readBlob(ctx, newBucket, blobId)
if (!readData) {
throw new Error("readData should not be nil");
}
var buckets = blob.listBuckets(ctx);
if (!buckets || buckets.length !== 2) {
throw new Error("buckets.length should be 2");
}
blob.deleteBlob(ctx, newBucket, blobId)
blobInfos = blob.listBlobs(ctx, newBucket);
console.log(blobInfos);
if (blobInfos.length !== 0) {
throw new Error("blobInfos.length: expected '0', got '"+blobInfos.length+"'");
}
blob.deleteBucket(ctx, newBucket)
buckets = blob.listBuckets(ctx);
if (buckets.length !== 1) {
throw new Error("buckets.length: expected '1', got '"+buckets.length+"'");
}