Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: support other storage classes #1728

Merged
merged 1 commit into from
Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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