Skip to content

Commit

Permalink
storage: support other storage classes
Browse files Browse the repository at this point in the history
  • Loading branch information
y33zhang authored and stephenplusplus committed Oct 19, 2016
1 parent fb13f28 commit 59fdf53
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 22 deletions.
20 changes: 12 additions & 8 deletions packages/storage/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,19 @@ Storage.prototype.channel = function(id, resourceId) {
* [Bucket Naming Guidelines](https://cloud.google.com/storage/docs/bucketnaming.html#requirements).
*
* @resource [Buckets: insert API Documentation]{@link https://cloud.google.com/storage/docs/json_api/v1/buckets/insert}
* @resource [Durable Reduced Availability]{@link https://cloud.google.com/storage/docs/durable-reduced-availability}
* @resource [Nearline]{@link https://cloud.google.com/storage/docs/nearline}
* @resource [Storage Classes]{@link https://cloud.google.com/storage/docs/storage-classes}
*
* @throws {Error} If a name is not provided.
*
* @param {string} name - Name of the bucket to create.
* @param {object=} metadata - Metadata to set for the bucket.
* @param {boolean=} metadata.dra - Specify the storage class as
* [Durable Reduced Availability](https://goo.gl/26lthK).
* @param {boolean=} metadata.nearline - Specify the storage class as
* [Nearline](https://goo.gl/sN5wNh).
* @param {boolean} metadata.coldline - Specify the storage class as Coldline.
* @param {boolean} metadata.dra - Specify the storage class as Durable Reduced
* Availability.
* @param {boolean} metadata.multiRegional - Specify the storage class as
* Multi-Regional.
* @param {boolean} metadata.nearline - Specify the storage class as Nearline.
* @param {boolean} metadata.regional - Specify the storage class as Regional.
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request
* @param {module:storage/bucket} callback.bucket - The newly created Bucket.
Expand All @@ -219,7 +220,7 @@ Storage.prototype.channel = function(id, resourceId) {
* //-
* var metadata = {
* location: 'US-CENTRAL1',
* dra: true
* regional: true
* };
*
* gcs.createBucket('new-bucket', metadata, callback);
Expand Down Expand Up @@ -260,8 +261,11 @@ Storage.prototype.createBucket = function(name, metadata, callback) {
});

var storageClasses = {
coldline: 'COLDLINE',
dra: 'DURABLE_REDUCED_AVAILABILITY',
nearline: 'NEARLINE'
multiRegional: 'MULTI_REGIONAL',
nearline: 'NEARLINE',
regional: 'REGIONAL'
};

Object.keys(storageClasses).forEach(function(storageClass) {
Expand Down
61 changes: 47 additions & 14 deletions packages/storage/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,54 @@ describe('Storage', function() {
});
});

it('should expand the Nearline option', function(done) {
storage.request = function(reqOpts) {
assert.strictEqual(reqOpts.json.storageClass, 'NEARLINE');
done();
};
storage.createBucket(BUCKET_NAME, { nearline: true }, function() {});
});
describe('storage classes', function() {
it('should expand metadata.coldline', function(done) {
storage.request = function(reqOpts) {
assert.strictEqual(reqOpts.json.storageClass, 'COLDLINE');
done();
};

storage.createBucket(BUCKET_NAME, { coldline: true }, assert.ifError);
});

it('should expand the Durable Reduced Availability option', function(done) {
storage.request = function(reqOpts) {
var body = reqOpts.json;
assert.strictEqual(body.storageClass, 'DURABLE_REDUCED_AVAILABILITY');
done();
};
storage.createBucket(BUCKET_NAME, { dra: true }, function() {});
it('should expand metadata.dra', function(done) {
storage.request = function(reqOpts) {
var body = reqOpts.json;
assert.strictEqual(body.storageClass, 'DURABLE_REDUCED_AVAILABILITY');
done();
};

storage.createBucket(BUCKET_NAME, { dra: true }, assert.ifError);
});

it('should expand metadata.multiRegional', function(done) {
storage.request = function(reqOpts) {
assert.strictEqual(reqOpts.json.storageClass, 'MULTI_REGIONAL');
done();
};

storage.createBucket(BUCKET_NAME, {
multiRegional: true
}, assert.ifError);
});

it('should expand metadata.nearline', function(done) {
storage.request = function(reqOpts) {
assert.strictEqual(reqOpts.json.storageClass, 'NEARLINE');
done();
};

storage.createBucket(BUCKET_NAME, { nearline: true }, assert.ifError);
});

it('should expand metadata.regional', function(done) {
storage.request = function(reqOpts) {
assert.strictEqual(reqOpts.json.storageClass, 'REGIONAL');
done();
};

storage.createBucket(BUCKET_NAME, { regional: true }, assert.ifError);
});
});
});

Expand Down

0 comments on commit 59fdf53

Please sign in to comment.