Skip to content

Commit

Permalink
fix: fix list() and listV2() params and test case (#1043)
Browse files Browse the repository at this point in the history
  • Loading branch information
taotao7 committed Jan 26, 2022
1 parent 9b0e299 commit 4fc3bd4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
14 changes: 7 additions & 7 deletions lib/browser/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ proto.list = async function list(query, options) {
params.successStatuses = [200];

const result = await this.request(params);
let objects = result.data.Contents;
let objects = result.data.Contents || [];
const that = this;
if (objects) {
if (!Array.isArray(objects)) {
Expand Down Expand Up @@ -220,8 +220,6 @@ proto.list = async function list(query, options) {

proto.listV2 = async function listV2(query, options = {}) {
const continuation_token = query['continuation-token'] || query.continuationToken;
delete query['continuation-token'];
delete query.continuationToken;
if (continuation_token) {
options.subres = Object.assign(
{
Expand All @@ -232,11 +230,13 @@ proto.listV2 = async function listV2(query, options = {}) {
}
const params = this._objectRequestParams('GET', '', options);
params.query = Object.assign({ 'list-type': 2 }, query);
delete params.query['continuation-token'];
delete params.query.continuationToken;
params.xmlResponse = true;
params.successStatuses = [200];

const result = await this.request(params);
let objects = result.data.Contents;
let objects = result.data.Contents || [];
const that = this;
if (objects) {
if (!Array.isArray(objects)) {
Expand All @@ -252,9 +252,9 @@ proto.listV2 = async function listV2(query, options = {}) {
storageClass: obj.StorageClass,
owner: obj.Owner
? {
id: obj.Owner.ID,
displayName: obj.Owner.DisplayName
}
id: obj.Owner.ID,
displayName: obj.Owner.DisplayName
}
: null
}));
}
Expand Down
6 changes: 4 additions & 2 deletions lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ proto.list = async function list(query, options) {
params.successStatuses = [200];

const result = await this.request(params);
let objects = result.data.Contents;
let objects = result.data.Contents || [];
const that = this;
if (objects) {
if (!Array.isArray(objects)) {
Expand Down Expand Up @@ -254,11 +254,13 @@ proto.listV2 = async function listV2(query = {}, options = {}) {
}
const params = this._objectRequestParams('GET', '', options);
params.query = Object.assign({ 'list-type': 2 }, query);
delete params.query['continuation-token'];
delete query.continuationToken;
params.xmlResponse = true;
params.successStatuses = [200];

const result = await this.request(params);
let objects = result.data.Contents;
let objects = result.data.Contents || [];
const that = this;
if (objects) {
if (!Array.isArray(objects)) {
Expand Down
33 changes: 19 additions & 14 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ describe('browser', () => {
const result = await client.list({
'max-keys': 3
});
assert.equal(result.objects.length, 3);
assert(result.objects.length <= 3);
result.objects.map(checkObjectProperties);
assert.equal(typeof result.nextMarker, 'string');
assert(result.isTruncated);
Expand Down Expand Up @@ -509,7 +509,7 @@ describe('browser', () => {
const result = await store.listV2({
'max-keys': 1
});
assert.equal(result.objects.length, 1);
assert(result.objects.length <= 1);
result.objects.forEach(checkObjectProperties);
assert.equal(typeof result.nextContinuationToken, 'string');
assert(result.isTruncated);
Expand Down Expand Up @@ -621,7 +621,7 @@ describe('browser', () => {
delimiter: '/'
});
assert.strictEqual(result.keyCount, 1);
assert.strictEqual(result.objects, undefined);
assert.strictEqual(result.objects.length, 0);
assert.strictEqual(result.prefixes[0], `${listPrefix}other/`);
});

Expand Down Expand Up @@ -1488,7 +1488,9 @@ describe('browser', () => {
const parts = await Promise.all(
Array(10)
.fill(1)
.map((v, i) => store.uploadPart(name, uploadId, i + 1, file, i * partSize, Math.min((i + 1) * partSize, 10 * 100 * 1024)))
.map((v, i) =>
store.uploadPart(name, uploadId, i + 1, file, i * partSize, Math.min((i + 1) * partSize, 10 * 100 * 1024))
)
);
const dones = parts.map((_, i) => ({
number: i + 1,
Expand Down Expand Up @@ -2347,7 +2349,6 @@ describe('browser', () => {
const file = new Blob([fileContent]);
await client.put(key, file);


const copyName = 'new.txt';
const result = await client.multipartUploadCopy(copyName, {
sourceKey: key,
Expand All @@ -2361,16 +2362,20 @@ describe('browser', () => {
const client = oss(ossConfig);
const copyName = 'multipart copy';
const key = 'old.txt';
const result = await client.multipartUploadCopy(copyName, {
sourceKey: key,
sourceBucketName: stsConfig.bucket
}, {
parallel: 4,
partSize: 1024 * 1024,
progress: (p) => {
console.log(p);
const result = await client.multipartUploadCopy(
copyName,
{
sourceKey: key,
sourceBucketName: stsConfig.bucket
},
{
parallel: 4,
partSize: 1024 * 1024,
progress: p => {
console.log(p);
}
}
});
);
assert.equal(result.res.statusCode, 200);
});
});
Expand Down
10 changes: 5 additions & 5 deletions test/node/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,7 @@ describe('test/object.test.js', () => {
const result = await store.list({
'max-keys': 1
});
assert.equal(result.objects.length, 1);
assert(result.objects.length <= 1);
result.objects.map(checkObjectProperties);
assert.equal(typeof result.nextMarker, 'string');
assert(result.isTruncated);
Expand All @@ -1860,7 +1860,7 @@ describe('test/object.test.js', () => {
const result = await store.list({
'max-keys': 3
});
assert.equal(result.objects.length, 3);
assert(result.objects.length <= 3);
result.objects.map(checkObjectProperties);
assert.equal(typeof result.nextMarker, 'string');
assert(result.isTruncated);
Expand All @@ -1871,7 +1871,7 @@ describe('test/object.test.js', () => {
'max-keys': 2,
marker: result.nextMarker
});
assert.equal(result2.objects.length, 2);
assert(result2.objects.length <= 2);
result.objects.map(checkObjectProperties);
assert.equal(typeof result2.nextMarker, 'string');
assert(result2.isTruncated);
Expand Down Expand Up @@ -1972,7 +1972,7 @@ describe('test/object.test.js', () => {
'max-keys': 2,
continuationToken: result.nextContinuationToken
});
assert.equal(result2.objects.length, 2);
assert(result2.objects.length <= 2);
result.objects.forEach(checkObjectProperties);
assert.equal(typeof result2.nextContinuationToken, 'string');
assert(result2.isTruncated);
Expand Down Expand Up @@ -2073,7 +2073,7 @@ describe('test/object.test.js', () => {
delimiter: '/'
});
assert.strictEqual(result.keyCount, 1);
assert.strictEqual(result.objects, undefined);
assert.strictEqual(result.objects.length, 0);
assert.strictEqual(result.prefixes[0], `${listPrefix}other/`);
});

Expand Down

0 comments on commit 4fc3bd4

Please sign in to comment.