From 6adc44920bd92a7d88fe6271f984f913c6ba1281 Mon Sep 17 00:00:00 2001 From: KujoMiva Date: Thu, 23 Jun 2022 10:02:34 +0800 Subject: [PATCH] fix: fix use store bucket name. getBucketLocation & getBucketInfo --- lib/bucket.js | 12 ++++++------ test/node/bucket.test.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/bucket.js b/lib/bucket.js index 1df360262..0934ab367 100644 --- a/lib/bucket.js +++ b/lib/bucket.js @@ -89,9 +89,9 @@ proto.getBucket = function getBucket() { }; proto.getBucketLocation = async function getBucketLocation(name, options) { - _checkBucketName(name); - name = name || this.getBucket(); - const params = this._bucketRequestParams('GET', name, 'location', options); + const _name = name || this.getBucket(); + _checkBucketName(_name); + const params = this._bucketRequestParams('GET', _name, 'location', options); params.successStatuses = [200]; params.xmlResponse = true; const result = await this.request(params); @@ -102,9 +102,9 @@ proto.getBucketLocation = async function getBucketLocation(name, options) { }; proto.getBucketInfo = async function getBucketInfo(name, options) { - _checkBucketName(name); - name = name || this.getBucket(); - const params = this._bucketRequestParams('GET', name, 'bucketInfo', options); + const _name = name || this.getBucket(); + _checkBucketName(_name); + const params = this._bucketRequestParams('GET', _name, 'bucketInfo', options); params.successStatuses = [200]; params.xmlResponse = true; const result = await this.request(params); diff --git a/test/node/bucket.test.js b/test/node/bucket.test.js index 37ffeb0c0..3e485f585 100644 --- a/test/node/bucket.test.js +++ b/test/node/bucket.test.js @@ -136,6 +136,17 @@ describe('test/bucket.test.js', () => { assert.equal(result.bucket.StorageClass, 'Standard'); }); + it('it should return correct bucketInfo when bucket exist by store setting', async () => { + const result = await store.getBucketInfo(); + assert.equal(result.res.status, 200); + + assert.equal(result.bucket.Location, `${bucketRegion}`); + assert.equal(result.bucket.ExtranetEndpoint, `${bucketRegion}.aliyuncs.com`); + assert.equal(result.bucket.IntranetEndpoint, `${bucketRegion}-internal.aliyuncs.com`); + assert.equal(result.bucket.AccessControlList.Grant, 'private'); + assert.equal(result.bucket.StorageClass, 'Standard'); + }); + it('it should return NoSuchBucketError when bucket not exist', async () => { await utils.throws(async () => { await store.getBucketInfo('not-exists-bucket'); @@ -149,6 +160,11 @@ describe('test/bucket.test.js', () => { assert.equal(result.location, bucketRegion); }); + it('it should return localtion this.region by store setting', async () => { + const result = await store.getBucketLocation(); + assert.equal(result.location, bucketRegion); + }); + it('it should return NoSuchBucketError when bucket not exist', async () => { await utils.throws(async () => { await store.getBucketLocation('not-exists-bucket');