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

fix: fix use store bucket name. getBucketLocation & getBucketInfo #1125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions lib/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions test/node/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down