Skip to content

Commit ceeeb9f

Browse files
committed
fix test cases
1 parent 198a197 commit ceeeb9f

File tree

4 files changed

+52
-28
lines changed

4 files changed

+52
-28
lines changed

test/form_up.test.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ before(function () {
2727
});
2828

2929
after(function () {
30-
return Promise.all([
31-
fs.promises.unlink(testFilePath1),
32-
fs.promises.unlink(testFilePath2)
33-
])
34-
.catch(err => {
35-
console.log('Form upload test. Unlink files failed', err);
36-
});
30+
return Promise.all(
31+
[
32+
testFilePath1,
33+
testFilePath2
34+
].map(p => new Promise(resolve => {
35+
fs.unlink(p, err => {
36+
if (err) {
37+
console.log(`unlink ${p} failed`, err);
38+
}
39+
resolve();
40+
});
41+
}))
42+
);
3743
});
3844

3945
describe('test form up', function () {

test/resume_up.test.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,18 @@ before(function () {
6767
});
6868

6969
after(function () {
70-
return fs.promises.unlink(testFilePath)
71-
.catch(err => {
72-
console.log('Resume upload test. Unlink files failed', err);
73-
});
70+
return Promise.all(
71+
[
72+
testFilePath
73+
].map(p => new Promise(resolve => {
74+
fs.unlink(p, err => {
75+
if (err) {
76+
console.log(`unlink ${p} failed`, err);
77+
}
78+
resolve();
79+
});
80+
}))
81+
);
7482
});
7583

7684
// file to upload
@@ -250,7 +258,7 @@ describe('test resume up', function () {
250258
if (mimeType !== undefined) {
251259
putExtra.mimeType = mimeType;
252260
}
253-
const key = 'storage_putFile_test' + Math.floor(Math.random() * 1000);
261+
const key = 'storage_putFile_test' + Math.floor(Math.random() * 100000);
254262

255263
const promises = doAndWrapResultPromises(callback =>
256264
resumeUploader.putFile(
@@ -325,7 +333,7 @@ describe('test resume up', function () {
325333
putExtra.mimeType = mimeType;
326334
}
327335

328-
const key = 'storage_putStream_test' + Math.floor(Math.random() * 1000);
336+
const key = 'storage_putStream_test' + Math.floor(Math.random() * 100000);
329337

330338
const streamSize = 9 * 1024 * 1024;
331339
const {
@@ -397,12 +405,16 @@ describe('test resume up', function () {
397405

398406
const filepathListToDelete = [];
399407
after(function () {
400-
return Promise.all(filepathListToDelete.map(p =>
401-
fs.promises.unlink(p)
402-
.catch(() => {
403-
// pass
404-
})
405-
));
408+
return Promise.all(
409+
filepathListToDelete.map(p => new Promise(resolve => {
410+
fs.unlink(p, err => {
411+
if (err) {
412+
console.log(`unlink ${p} failed`, err);
413+
}
414+
resolve();
415+
});
416+
}))
417+
);
406418
});
407419

408420
testParams.forEach(testParam => {
@@ -425,7 +437,7 @@ describe('test resume up', function () {
425437
}
426438

427439
it(`test resume up#putStream resume; ${msg}`, function () {
428-
const key = 'storage_putStream_resume_test' + Math.floor(Math.random() * 1000);
440+
const key = 'storage_putStream_resume_test' + Math.floor(Math.random() * 100000);
429441

430442
const putExtra = new qiniu.resume_up.PutExtra();
431443
putExtra.resumeRecordFile = path.join(os.tmpdir(), key + '.resume.json');

test/rs.test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,8 @@ describe('test start bucket manager', function () {
522522

523523
// 空间生命周期
524524
describe('test lifeRule', function () {
525-
const ruleName = 'test_rule_name' + Math.floor(Math.random() * 1000);
525+
const ruleName = 'test_rule_name' + Math.floor(Math.random() * 100000);
526+
const randomPrefix = 'test' + Math.floor(Math.random() * 100000);
526527

527528
function testGet (expectItem, otherRespInfo) {
528529
return bucketManager.getBucketLifecycleRule(bucketName)
@@ -554,7 +555,7 @@ describe('test start bucket manager', function () {
554555
it('test lifeRule put', function () {
555556
const options = {
556557
name: ruleName,
557-
prefix: 'test',
558+
prefix: randomPrefix,
558559
to_line_after_days: 30,
559560
to_archive_ir_after_days: 35,
560561
to_archive_after_days: 40,
@@ -570,7 +571,7 @@ describe('test start bucket manager', function () {
570571
should.equal(resp.statusCode, 200, JSON.stringify(resp));
571572
return testGet(
572573
{
573-
prefix: 'test',
574+
prefix: randomPrefix,
574575
to_line_after_days: 30,
575576
to_archive_ir_after_days: 35,
576577
to_archive_after_days: 40,
@@ -590,9 +591,10 @@ describe('test start bucket manager', function () {
590591
});
591592

592593
it('test lifeRule update', function () {
594+
const expectedPrefix = `update_${randomPrefix}`;
593595
const options = {
594596
name: ruleName,
595-
prefix: 'update_prefix',
597+
prefix: expectedPrefix,
596598
to_line_after_days: 30,
597599
to_archive_ir_after_days: 40,
598600
to_archive_after_days: 50,
@@ -608,7 +610,7 @@ describe('test start bucket manager', function () {
608610
should.equal(resp.statusCode, 200, JSON.stringify(resp));
609611
return testGet(
610612
{
611-
prefix: 'update_prefix',
613+
prefix: expectedPrefix,
612614
to_line_after_days: 30,
613615
to_archive_ir_after_days: 40,
614616
to_archive_after_days: 50,
@@ -734,7 +736,7 @@ describe('test start bucket manager', function () {
734736
});
735737

736738
describe('test events', function () {
737-
const eventName = 'event_test' + Math.floor(Math.random() * 1000);
739+
const eventName = 'event_test' + Math.floor(Math.random() * 100000);
738740

739741
before(function () {
740742
return bucketManager.deleteBucketEvent(
@@ -1028,8 +1030,8 @@ describe('test start bucket manager', function () {
10281030
describe('test bucketQuota', function () {
10291031
it('test putBucketQuota', function () {
10301032
const options = {
1031-
size: 10,
1032-
count: 10
1033+
size: 5 * Math.pow(1024, 3), // 5GB
1034+
count: 1000
10331035
};
10341036

10351037
const promises = doAndWrapResultPromises(callback =>

test/rtc.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ before(function (done) {
1515

1616
// eslint-disable-next-line no-undef
1717
describe('test rtc credentials', function () {
18+
this.timeout(10000);
1819
var accessKey = proc.env.QINIU_ACCESS_KEY;
1920
var secretKey = proc.env.QINIU_SECRET_KEY;
2021

@@ -51,6 +52,7 @@ describe('test rtc credentials', function () {
5152
describe('test update app', function () {
5253
// eslint-disable-next-line no-undef
5354
it('update app', function (done) {
55+
should.ok(appId, 'appId not found. May create failed');
5456
appData.title = 'testtitle2';
5557
qiniu.app.updateApp(appId, appData, credentials, function (err, res) {
5658
should.not.exist(err);
@@ -65,6 +67,7 @@ describe('test rtc credentials', function () {
6567
describe('test get app', function () {
6668
// eslint-disable-next-line no-undef
6769
it('get app', function (done) {
70+
should.ok(appId, 'appId not found. May create failed');
6871
qiniu.app.getApp(appId, credentials, function (err, res) {
6972
should.not.exist(err);
7073
assert.strictEqual(res.title, 'testtitle2');
@@ -78,6 +81,7 @@ describe('test rtc credentials', function () {
7881
describe('test delete app', function () {
7982
// eslint-disable-next-line no-undef
8083
it('delete app', function (done) {
84+
should.ok(appId, 'appId not found. May create failed');
8185
qiniu.app.deleteApp(appId, credentials, function (err) {
8286
should.not.exist(err);
8387
done();

0 commit comments

Comments
 (0)