Skip to content

Commit

Permalink
fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lihsai0 committed Mar 4, 2024
1 parent 198a197 commit 769f266
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 26 deletions.
20 changes: 13 additions & 7 deletions test/form_up.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ before(function () {
});

after(function () {
return Promise.all([
fs.promises.unlink(testFilePath1),
fs.promises.unlink(testFilePath2)
])
.catch(err => {
console.log('Form upload test. Unlink files failed', err);
});
return Promise.all(
[
testFilePath1,
testFilePath2
].map(p => new Promise(resolve => {
fs.unlink(p, err => {
if (err) {
console.log(`unlink ${p} failed`, err);
}
resolve();
});
}))
);
});

describe('test form up', function () {
Expand Down
38 changes: 25 additions & 13 deletions test/resume_up.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,18 @@ before(function () {
});

after(function () {
return fs.promises.unlink(testFilePath)
.catch(err => {
console.log('Resume upload test. Unlink files failed', err);
});
return Promise.all(
[
testFilePath
].map(p => new Promise(resolve => {
fs.unlink(p, err => {
if (err) {
console.log(`unlink ${p} failed`, err);
}
resolve();
});
}))
);
});

// file to upload
Expand Down Expand Up @@ -250,7 +258,7 @@ describe('test resume up', function () {
if (mimeType !== undefined) {
putExtra.mimeType = mimeType;
}
const key = 'storage_putFile_test' + Math.floor(Math.random() * 1000);
const key = 'storage_putFile_test' + Math.floor(Math.random() * 100000);

const promises = doAndWrapResultPromises(callback =>
resumeUploader.putFile(
Expand Down Expand Up @@ -325,7 +333,7 @@ describe('test resume up', function () {
putExtra.mimeType = mimeType;
}

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

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

const filepathListToDelete = [];
after(function () {
return Promise.all(filepathListToDelete.map(p =>
fs.promises.unlink(p)
.catch(() => {
// pass
})
));
return Promise.all(
filepathListToDelete.map(p => new Promise(resolve => {
fs.unlink(p, err => {
if (err) {
console.log(`unlink ${p} failed`, err);
}
resolve();
});
}))
);
});

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

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

const putExtra = new qiniu.resume_up.PutExtra();
putExtra.resumeRecordFile = path.join(os.tmpdir(), key + '.resume.json');
Expand Down
14 changes: 8 additions & 6 deletions test/rs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,8 @@ describe('test start bucket manager', function () {

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

function testGet (expectItem, otherRespInfo) {
return bucketManager.getBucketLifecycleRule(bucketName)
Expand Down Expand Up @@ -554,7 +555,7 @@ describe('test start bucket manager', function () {
it('test lifeRule put', function () {
const options = {
name: ruleName,
prefix: 'test',
prefix: randomPrefix,
to_line_after_days: 30,
to_archive_ir_after_days: 35,
to_archive_after_days: 40,
Expand All @@ -570,7 +571,7 @@ describe('test start bucket manager', function () {
should.equal(resp.statusCode, 200, JSON.stringify(resp));
return testGet(
{
prefix: 'test',
prefix: randomPrefix,
to_line_after_days: 30,
to_archive_ir_after_days: 35,
to_archive_after_days: 40,
Expand All @@ -590,9 +591,10 @@ describe('test start bucket manager', function () {
});

it('test lifeRule update', function () {
const expectedPrefix = `update_${randomPrefix}`;
const options = {
name: ruleName,
prefix: 'update_prefix',
prefix: expectedPrefix,
to_line_after_days: 30,
to_archive_ir_after_days: 40,
to_archive_after_days: 50,
Expand All @@ -608,7 +610,7 @@ describe('test start bucket manager', function () {
should.equal(resp.statusCode, 200, JSON.stringify(resp));
return testGet(
{
prefix: 'update_prefix',
prefix: expectedPrefix,
to_line_after_days: 30,
to_archive_ir_after_days: 40,
to_archive_after_days: 50,
Expand Down Expand Up @@ -734,7 +736,7 @@ describe('test start bucket manager', function () {
});

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

before(function () {
return bucketManager.deleteBucketEvent(
Expand Down
3 changes: 3 additions & 0 deletions test/rtc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('test rtc credentials', function () {
describe('test update app', function () {
// eslint-disable-next-line no-undef
it('update app', function (done) {
should.ok(appId, 'appId not found. May create failed');
appData.title = 'testtitle2';
qiniu.app.updateApp(appId, appData, credentials, function (err, res) {
should.not.exist(err);
Expand All @@ -65,6 +66,7 @@ describe('test rtc credentials', function () {
describe('test get app', function () {
// eslint-disable-next-line no-undef
it('get app', function (done) {
should.ok(appId, 'appId not found. May create failed');
qiniu.app.getApp(appId, credentials, function (err, res) {
should.not.exist(err);
assert.strictEqual(res.title, 'testtitle2');
Expand All @@ -78,6 +80,7 @@ describe('test rtc credentials', function () {
describe('test delete app', function () {
// eslint-disable-next-line no-undef
it('delete app', function (done) {
should.ok(appId, 'appId not found. May create failed');
qiniu.app.deleteApp(appId, credentials, function (err) {
should.not.exist(err);
done();
Expand Down

0 comments on commit 769f266

Please sign in to comment.