Skip to content

Commit 2997cd1

Browse files
committed
upd: 补充单测
1 parent f53b169 commit 2997cd1

File tree

1 file changed

+53
-13
lines changed

1 file changed

+53
-13
lines changed

test/test.js

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,14 +1557,24 @@ group('sliceCopyFile()', function () {
15571557
});
15581558
});
15591559
test('CopySource() fileSize=0', function (done, assert) {
1560-
var Key = '0b.zip';
1561-
cos.sliceCopyFile({
1562-
Bucket: config.Bucket, // Bucket 格式:test-1250000000
1563-
Region: config.Region,
1564-
CopySource: config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + Key,
1565-
}, function (err, data) {
1566-
assert.ok(err);
1567-
done();
1560+
var Key = '0b.zip';
1561+
cos.putObject({
1562+
Bucket: config.Bucket,
1563+
Region: config.Region,
1564+
Key: Key,
1565+
Body: '',
1566+
Headers: {
1567+
'x-cos-meta-test': 'test'
1568+
},
1569+
}, function(err, data){
1570+
cos.sliceCopyFile({
1571+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
1572+
Region: config.Region,
1573+
CopySource: config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + Key,
1574+
}, function (err, data) {
1575+
assert.ok(err);
1576+
done();
1577+
});
15681578
});
15691579
});
15701580
test('CopySource not found', function (done, assert) {
@@ -1580,13 +1590,13 @@ group('sliceCopyFile()', function () {
15801590
});
15811591
test('复制归档文件', function (done, assert) {
15821592
var sourceKey = 'archive';
1583-
var content = Date.now().toString(36);
15841593
var targetKey = 'archive-target';
1585-
cos.putObject({
1594+
var filePath = createFileSync(path.resolve(__dirname, filename), 1024 * 1024 * 30);
1595+
cos.sliceUploadFile({
15861596
Bucket: config.Bucket,
15871597
Region: config.Region,
15881598
Key: sourceKey,
1589-
Body: content,
1599+
FilePath: filePath,
15901600
StorageClass: 'ARCHIVE',
15911601
}, function () {
15921602
cos.sliceCopyFile({
@@ -4466,7 +4476,7 @@ group('appendObject', function () {
44664476

44674477
group('downloadFile', function () {
44684478
test('downloadFile() file not found', function (done, assert) {
4469-
var Key = '101mb.zip';
4479+
var Key = '101mb.zip';
44704480
cos.downloadFile({
44714481
Bucket: config.Bucket, // Bucket 格式:test-1250000000
44724482
Region: config.Region,
@@ -4482,7 +4492,7 @@ group('downloadFile', function () {
44824492
});
44834493
});
44844494
test('downloadFile() fileSize=0', function (done, assert) {
4485-
var Key = '0b.zip';
4495+
var Key = '0b.zip';
44864496
cos.downloadFile({
44874497
Bucket: config.Bucket, // Bucket 格式:test-1250000000
44884498
Region: config.Region,
@@ -4557,6 +4567,36 @@ group('downloadFile', function () {
45574567
}
45584568
});
45594569
});
4570+
test('downloadFile() 文件续传时远端文件已修改', function (done, assert) {
4571+
var Key = '50mb.zip';
4572+
var fileSize = 1024 * 1024 * 50;
4573+
var filePath = createFileSync(path.resolve(__dirname, Key), fileSize);
4574+
cos.sliceUploadFile({
4575+
Bucket: config.Bucket,
4576+
Region: config.Region,
4577+
Key: Key,
4578+
FilePath: filePath,
4579+
TrafficLimit: 819200,
4580+
}, function (err, data) {
4581+
if (err) {
4582+
done();
4583+
} else {
4584+
cos.downloadFile({
4585+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
4586+
Region: config.Region,
4587+
Key: Key,
4588+
FilePath: './' + Key, // 本地保存路径
4589+
ChunkSize: 1024 * 1024 * 8, // 分块大小
4590+
ParallelLimit: 5, // 分块并发数
4591+
RetryTimes: 3, // 分块失败重试次数
4592+
TaskId: '123', // 可以自己生成TaskId,用于取消下载
4593+
}, function (err, data) {
4594+
assert.ok(!err);
4595+
done();
4596+
});
4597+
}
4598+
});
4599+
});
45604600
test('downloadFile() 下载归档文件', function (done, assert) {
45614601
var Key = '10mb.zip';
45624602
var fileSize = 1024 * 1024 * 10;

0 commit comments

Comments
 (0)