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 some test error and variable #1030

Merged
merged 10 commits into from
Jan 17, 2022
1 change: 1 addition & 0 deletions test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ config.sts = {
};

config.metaSyncTime = env.ONCI ? '30s' : '1000ms';
config.timeout = '120s';
33 changes: 17 additions & 16 deletions test/node/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const utils = require('./utils');
const oss = require('../..');
const config = require('../config').oss;
const ms = require('humanize-ms');
const { metaSyncTime } = require('../config');
const { metaSyncTime, timeout } = require('../config');

// only run on travis ci

Expand All @@ -27,13 +27,14 @@ describe('test/bucket.test.js', () => {
bucket = bucket.substring(0, bucket.length - 1);
bucketRegion = defaultRegion;

const result = await store.putBucket(bucket, { timeout: process.env.ONCI ? 60000 : 10000 });
const result = await store.putBucket(bucket, { timeout });
assert.equal(result.bucket, bucket);
assert.equal(result.res.status, 200);
});
after(async () => {
await utils.cleanBucket(store, bucket);
});
// restore object will have cache
// after(async () => {
// await utils.cleanBucket(store, bucket);
// });

describe('setBucket()', () => {
it('should check bucket name', async () => {
Expand Down Expand Up @@ -65,11 +66,11 @@ describe('test/bucket.test.js', () => {
// just for archive bucket test
archvieBucket = `ali-oss-archive-bucket-${prefix.replace(/[/.]/g, '-')}`;
archvieBucket = archvieBucket.substring(0, archvieBucket.length - 1);
await store.putBucket(archvieBucket, { StorageClass: 'Archive', timeout: 120000 });
await store.putBucket(archvieBucket, { StorageClass: 'Archive', timeout });
});

it('should create a new bucket', async () => {
const result1 = await store.putBucket(name, { timeout: 120000 });
const result1 = await store.putBucket(name, { timeout });
assert.equal(result1.bucket, name);
assert.equal(result1.res.status, 200);
});
Expand All @@ -79,7 +80,7 @@ describe('test/bucket.test.js', () => {
const result2 = await store.listBuckets(
{},
{
timeout: 120000
timeout
}
);
const { buckets } = result2;
Expand Down Expand Up @@ -223,7 +224,7 @@ describe('test/bucket.test.js', () => {
'max-keys': 20
},
{
timeout: 120000
timeout
}
);

Expand Down Expand Up @@ -419,12 +420,12 @@ describe('test/bucket.test.js', () => {

describe('putBucketReferer(), getBucketReferer(), deleteBucketReferer()', () => {
it('should create, get and delete the referer', async () => {
const putresult = await store.putBucketReferer(bucket, true, ['http://npm.taobao.org'], { timeout: 120000 });
const putresult = await store.putBucketReferer(bucket, true, ['http://npm.taobao.org'], { timeout });
assert.equal(putresult.res.status, 200);

// put again will be fine
const referers = ['http://npm.taobao.org', 'https://npm.taobao.org', 'http://cnpmjs.org'];
const putReferer = await store.putBucketReferer(bucket, false, referers, { timeout: 120000 });
const putReferer = await store.putBucketReferer(bucket, false, referers, { timeout });
assert.equal(putReferer.res.status, 200);

await utils.sleep(ms(metaSyncTime));
Expand All @@ -444,7 +445,7 @@ describe('test/bucket.test.js', () => {
describe('putBucketCORS(), getBucketCORS(), deleteBucketCORS()', () => {
afterEach(async () => {
// delete it
const result = await store.deleteBucketCORS(bucket, { timeout: 120000 });
const result = await store.deleteBucketCORS(bucket, { timeout });
assert.equal(result.res.status, 204);
});

Expand All @@ -461,7 +462,7 @@ describe('test/bucket.test.js', () => {
const putResult = await store.putBucketCORS(bucket, rules);
assert.equal(putResult.res.status, 200);

const getResult = await store.getBucketCORS(bucket, { timeout: 120000 });
const getResult = await store.getBucketCORS(bucket, { timeout });
assert.equal(getResult.res.status, 200);
assert.deepEqual(getResult.rules, [
{
Expand All @@ -479,15 +480,15 @@ describe('test/bucket.test.js', () => {
{
allowedOrigin: '*',
allowedMethod: 'GET',
timeout: 120000
timeout
}
];
const putCorsResult1 = await store.putBucketCORS(bucket, rules1);
assert.equal(putCorsResult1.res.status, 200);

await utils.sleep(ms(metaSyncTime));

const getCorsResult1 = await store.getBucketCORS(bucket, { timeout: 120000 });
const getCorsResult1 = await store.getBucketCORS(bucket, { timeout });
assert.equal(getCorsResult1.res.status, 200);
assert.deepEqual(getCorsResult1.rules, [
{
Expand All @@ -507,7 +508,7 @@ describe('test/bucket.test.js', () => {

await utils.sleep(ms(metaSyncTime));

const getCorsResult2 = await store.getBucketCORS(bucket, { timeout: 120000 });
const getCorsResult2 = await store.getBucketCORS(bucket, { timeout });
assert.equal(getCorsResult2.res.status, 200);
assert.deepEqual(getCorsResult2.rules, [
{
Expand Down
21 changes: 8 additions & 13 deletions test/node/bucket_worm.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

const assert = require('assert');
const utils = require('./utils');
const oss = require('../..');
const config = require('../config').oss;
const timeout = require('../config').timeout;

describe('test/bucket_worm.test.js', () => {
const { prefix } = utils;
Expand All @@ -16,15 +16,15 @@ describe('test/bucket_worm.test.js', () => {
bucket = `ali-oss-test-worm-bucket-worm-${prefix.replace(/[/.]/g, '-')}`;
bucket = bucket.substring(0, bucket.length - 1);

const result = await store.putBucket(bucket, {
timeout: process.env.ONCI ? 60000 : 10000 });
const result = await store.putBucket(bucket, { timeout });
assert.equal(result.bucket, bucket);
assert.equal(result.res.status, 200);
});

after(async () => {
await utils.cleanAllBucket(store);
});
// github CI will remove buckets
// restore object will have cache
// after(async () => {
// await utils.cleanBucket(store, bucket);
// });
describe('worm()', () => {
describe('initiateBucketWorm()', () => {
it('should init bucket worm', async () => {
Expand Down Expand Up @@ -68,11 +68,7 @@ describe('test/bucket_worm.test.js', () => {
it('should extend bucket worm', async () => {
try {
const { wormId, days } = await store.getBucketWorm(bucket);
await store.extendBucketWorm(
bucket,
wormId,
(days * 1 + 1).toString()
);
await store.extendBucketWorm(bucket, wormId, (days * 1 + 1).toString());
const result = await store.getBucketWorm(bucket);
assert(result.days - days === 1);
} catch (error) {
Expand All @@ -81,5 +77,4 @@ describe('test/bucket_worm.test.js', () => {
});
});
});

});
13 changes: 8 additions & 5 deletions test/node/bukcet_worm.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

const assert = require('assert');
const utils = require('./utils');
const oss = require('../..');
const config = require('../config').oss;
const { timeout } = require('../config');

describe('test/bucket.test.js', () => {
const { prefix } = utils;
Expand All @@ -16,14 +16,17 @@ describe('test/bucket.test.js', () => {
bucket = `ali-oss-test-worm2-bucket-${prefix.replace(/[/.]/g, '-')}`;
bucket = bucket.substring(0, bucket.length - 1);

const result = await store.putBucket(bucket, { timeout: process.env.ONCI ? 60000 : 10000 });
const result = await store.putBucket(bucket, { timeout });
assert.equal(result.bucket, bucket);
assert.equal(result.res.status, 200);
});

after(async () => {
await utils.cleanAllBucket(store);
});
// github CI will remove buckets
// restore object will have cache
// after(async () => {
// await utils.cleanBucket(store, bucket);
// });

describe('worm()', () => {
describe('initiateBucketWorm()', () => {
it('should init bucket worm', async () => {
Expand Down
29 changes: 26 additions & 3 deletions test/node/cleanAllBucket.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
const utils = require('./utils');
const config = require('../config').oss;
const oss = require('../..');
const OSS = require('../..');

const store = oss(config);
utils.cleanAllBucket(store);
const store = OSS(config);

store.listBuckets().then(r => {
const bucketList = [];
r.buckets.forEach(i => {
if (i.name.indexOf('ali-oss') === 0) {
bucketList.push({
bucket: i.name,
region: i.region
});
}
});

for (const bucketListItem of bucketList) {
const client = new OSS({
...store.options,
bucket: bucketListItem.bucket,
region: bucketListItem.region
});
utils.cleanBucket(client, bucketListItem.bucket).catch(e => {
console.log('bucket name =======>', bucketListItem.bucket);
console.log('error:====>', e);
});
}
});
1 change: 1 addition & 0 deletions test/node/multiversion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ describe('test/multiversion.test.js', () => {
it('should copy latest object with versionId `null` when the bucket is suspended', async () => {
const target = `${name.replace('file.js', 'file-target-suspended.js')}`;
const suspendedRes = await store.putBucketVersioning(bucket, suspended);
await utils.sleep(ms(metaSyncTime));
assert.strictEqual(suspendedRes.res.status, 200);
try {
const result = await store.copy(target, name, {
Expand Down
3 changes: 2 additions & 1 deletion test/node/rtmp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('test/rtmp.test.js', () => {
let conf;
before(async () => {
store = oss(config);
bucket = `ali-oss-test-bucket-${prefix.replace(/[/.]/g, '-')}`;
bucket = `ali-oss-test-bucket-rtmp-${prefix.replace(/[/.]/g, '-')}`;
bucket = bucket.substring(0, bucket.length - 1);
store.useBucket(bucket);

Expand All @@ -46,6 +46,7 @@ describe('test/rtmp.test.js', () => {
};
});

// github CI will remove buckets
after(async () => {
await utils.cleanBucket(store, bucket);
});
Expand Down