Skip to content

Commit 07675d4

Browse files
livehighzhouxueyun
andcommitted
Feat/git (tencentyun#170)
* upd: 新增单测 * upd: 新增单测 * upd: 新增单测 * upd: 补充单测 * upd: 补充单测 * upd: 补充单测 * upd: 补充单测 * upd: 补充单测 * upd: 补充图片处理、存储桶配置、文档处理、文件处理nodejs sdk (merge request !3) Squash merge branch 'dev/xueyunzhou' into 'master' upd: 补充图片处理、存储桶配置、文档处理、文件处理nodejs sdk --------- Co-authored-by: zhouxueyun <[email protected]>
1 parent b54590b commit 07675d4

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed

test/test.js

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,96 @@ group('init cos', function() {
299299
});
300300
putFile(initCos, done, assert);
301301
});
302+
test('SecretKey格式错误', function(done, assert) {
303+
var initCos = new COS({
304+
SecretId: config.SecretId,
305+
SecretKey: config.SecretKey + ' ',
306+
});
307+
putFile(initCos, done, assert, false);
308+
});
309+
test('StrictSsl=false', function(done, assert) {
310+
var initCos = new COS({
311+
SecretId: config.SecretId,
312+
SecretKey: config.SecretKey,
313+
StrictSsl: false,
314+
});
315+
putFile(initCos, done, assert, true);
316+
});
317+
test('Tunnel=false', function(done, assert) {
318+
var initCos = new COS({
319+
SecretId: config.SecretId,
320+
SecretKey: config.SecretKey,
321+
Tunnel: false,
322+
});
323+
putFile(initCos, done, assert, true);
324+
});
325+
test('Timeout=6000', function(done, assert) {
326+
var initCos = new COS({
327+
SecretId: config.SecretId,
328+
SecretKey: config.SecretKey,
329+
Timeout: 6000,
330+
});
331+
putFile(initCos, done, assert, true);
332+
});
333+
test('模拟sms init', function(done, assert) {
334+
var Credentials = {
335+
secretId: config.SecretId,
336+
secretKey: config.SecretKey,
337+
};
338+
var initCos = new COS({ Credentials });
339+
setTimeout(() => {
340+
Credentials.secretId = '123456';
341+
Credentials.secretKey = 'abcdefg';
342+
}, 1000);
343+
putFile(initCos, done, assert, true);
344+
});
345+
test('getAuthorization error tmpSecretId', function(done, assert) {
346+
var initCos = new COS({
347+
getAuthorization: function (options, callback) {
348+
callback({
349+
tmpSecretId: config.SecretId,
350+
TmpSecretKey: config.SecretKey,
351+
});
352+
}
353+
});
354+
putFile(initCos, done, assert, false);
355+
});
356+
test('getAuthorization error tmpSecretKey', function(done, assert) {
357+
var initCos = new COS({
358+
getAuthorization: function (options, callback) {
359+
callback({
360+
TmpSecretId: config.SecretId,
361+
tmpSecretKey: config.SecretKey,
362+
});
363+
}
364+
});
365+
putFile(initCos, done, assert, false);
366+
});
367+
test('getAuthorization error', function(done, assert) {
368+
var initCos = new COS({
369+
getAuthorization: function (options, callback) {
370+
callback({
371+
TmpSecretId: config.SecretId,
372+
TmpSecretKey: config.SecretKey,
373+
});
374+
}
375+
});
376+
putFile(initCos, done, assert, false);
377+
});
378+
test('getAuthorization', function(done, assert) {
379+
var initCos = new COS({
380+
getAuthorization: function (options, callback) {
381+
var AuthData = cos.getAuth({
382+
Method: 'put',
383+
Key: '1.txt'
384+
});
385+
callback({
386+
Authorization: AuthData
387+
});
388+
}
389+
});
390+
putFile(initCos, done, assert);
391+
});
302392
});
303393

304394
group('getService()', function () {
@@ -4764,6 +4854,22 @@ group('downloadFile', function () {
47644854
done();
47654855
});
47664856
});
4857+
test('downloadFile() fileSize=0', function (done, assert) {
4858+
var Key = '0b.zip';
4859+
cos.downloadFile({
4860+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
4861+
Region: config.Region,
4862+
Key: Key,
4863+
FilePath: './' + Key, // 本地保存路径
4864+
ChunkSize: 1024 * 1024 * 8, // 分块大小
4865+
ParallelLimit: 5, // 分块并发数
4866+
RetryTimes: 3, // 分块失败重试次数
4867+
TaskId: '123', // 可以自己生成TaskId,用于取消下载
4868+
}, function (err, data) {
4869+
assert.ok(err);
4870+
done();
4871+
});
4872+
});
47674873
test('downloadFile() 小文件简单下载', function (done, assert) {
47684874
var Key = '1mb.zip';
47694875
var fileSize = 1024 * 1024 * 3;
@@ -4856,6 +4962,36 @@ group('downloadFile', function () {
48564962
}
48574963
});
48584964
});
4965+
test('downloadFile() 文件续传时远端文件已修改', function (done, assert) {
4966+
var Key = '50mb.zip';
4967+
var fileSize = 1024 * 1024 * 50;
4968+
var filePath = createFileSync(path.resolve(__dirname, Key), fileSize);
4969+
cos.sliceUploadFile({
4970+
Bucket: config.Bucket,
4971+
Region: config.Region,
4972+
Key: Key,
4973+
FilePath: filePath,
4974+
TrafficLimit: 819200,
4975+
}, function (err, data) {
4976+
if (err) {
4977+
done();
4978+
} else {
4979+
cos.downloadFile({
4980+
Bucket: config.Bucket, // Bucket 格式:test-1250000000
4981+
Region: config.Region,
4982+
Key: Key,
4983+
FilePath: './' + Key, // 本地保存路径
4984+
ChunkSize: 1024 * 1024 * 8, // 分块大小
4985+
ParallelLimit: 5, // 分块并发数
4986+
RetryTimes: 3, // 分块失败重试次数
4987+
TaskId: '123', // 可以自己生成TaskId,用于取消下载
4988+
}, function (err, data) {
4989+
assert.ok(!err);
4990+
done();
4991+
});
4992+
}
4993+
});
4994+
});
48594995
test('downloadFile() 下载归档文件', function (done, assert) {
48604996
var Key = '10mb.zip';
48614997
var fileSize = 1024 * 1024 * 10;

0 commit comments

Comments
 (0)