Skip to content

Commit

Permalink
upd: 补充单测
Browse files Browse the repository at this point in the history
  • Loading branch information
livehigh committed Apr 19, 2023
1 parent 8a4d29d commit 210fcc6
Showing 1 changed file with 88 additions and 8 deletions.
96 changes: 88 additions & 8 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ group('putObject(),cancelTask()', function () {
assert(info);
done();
})
});
});
});

group('task 队列', function () {
Expand Down Expand Up @@ -820,9 +820,9 @@ group('headBucket()', function () {
});
});

test('headBucket() not exist', function (done, assert) {
test('headBucket() bucket not exist', function (done, assert) {
cos.headBucket({
Bucket: config.Bucket + Date.now().toString(36),
Bucket: Date.now().toString(36) + config.Bucket,
Region: config.Region
}, function (err, data) {
assert.ok(err, 'bucket 不存在');
Expand All @@ -832,7 +832,7 @@ group('headBucket()', function () {

test('deleteBucket()', function (done, assert) {
cos.deleteBucket({
Bucket: config.Bucket + Date.now().toString(36),
Bucket: Date.now().toString(36) + config.Bucket,
Region: config.Region
}, function (err, data) {
assert.ok(err, 'deleteBucket 不存在');
Expand Down Expand Up @@ -1139,6 +1139,43 @@ group('getObject(),getObjectStream()', function () {
});
});
});
test('getObject() stream2', function (done, assert) {
var key = '1.txt';
var objectContent = Buffer.from([]);
var outputStream = new Writable({
write: function (chunk, encoding, callback) {
objectContent = Buffer.concat([objectContent, chunk]);
callback();
}
});
var content = Date.now().toString(36);
cos.putObject({
Bucket: config.Bucket,
Region: config.Region,
Key: key,
Body: Buffer.from(content)
}, function (err, data) {
cos.getObject({
Bucket: config.Bucket,
Region: config.Region,
Key: key,
Output: './1.txt'
}, function (err, data) {
if (err) throw err;
objectContent = objectContent.toString();
assert.ok(data.headers['content-length'] === '' + content.length);
assert.ok(objectContent === content);
cos.headObject({
Bucket: config.Bucket,
Region: config.Region,
Key: key
}, function (err, data) {
assert.ok(!err);
done();
});
});
});
});
test('getObjectStream', function (done, assert) {
var content = Date.now().toString();
var key = '1.json';
Expand Down Expand Up @@ -1199,7 +1236,7 @@ group('deleteObject() 404', function () {
cos.deleteObject({
Bucket: config.Bucket,
Region: config.Region,
Key: Date.now().toString(36),
Key: '123' + Date.now().toString(36),
}, function (err, data) {
assert.ok(data.statusCode === 404);
done();
Expand Down Expand Up @@ -1413,7 +1450,7 @@ group('sliceCopyFile()', function () {
Bucket: config.Bucket,
Region: config.Region,
Key: Key,
CopySource: 'www.qq.com/1.txt',
CopySource: 'www.123.com/1.txt',
}, function (err, data) {
assert.ok(err);
done();
Expand Down Expand Up @@ -2468,7 +2505,16 @@ group('BucketWebsite', function () {
assert.ok(err);
done();
});
});
});
test('putBucketWebsite() bucket not exist', function (done, assert) {
cos.putBucketWebsite({
Bucket: config.Bucket,
Region: config.Region,
}, function (err, data) {
assert.ok(err);
done();
});
});
test('putBucketWebsite(),getBucketWebsite()', function (done, assert) {
cos.putBucketWebsite({
Bucket: config.Bucket,
Expand Down Expand Up @@ -3261,6 +3307,16 @@ group('BucketInventory', function () {
});
});
});
test('deleteBucketInventory() bucket not exist', function (done, assert) {
cos.deleteBucketInventory({
Bucket: Date.now().toString(36) + config.Bucket,
Region: config.Region,
Id: InventoryConfiguration.Id
}, function (err, data) {
assert.ok(err);
done();
});
});
});

group('Content-Type: false Bug', function () {
Expand Down Expand Up @@ -3455,6 +3511,19 @@ group('ObjectTagging', function () {
}, 1000);
});
});
test('putObjectTagging() object not exist', function (done, assert) {
cos.putObjectTagging({
Bucket: config.Bucket,
Region: config.Region,
Key: Date.now().toString(36) + key,
Tagging: {
Tags: Tags
},
}, function (err, data) {
assert.ok(err);
done();
});
});
test('getObjectTagging() object not exist', function (done, assert) {
cos.getObjectTagging({
Bucket: config.Bucket,
Expand Down Expand Up @@ -3870,7 +3939,6 @@ group('BucketReplication', function () {
Status: 'Suspended'
}
}, function (err, data) {
assert.ok(!err);
setTimeout(function () {
cos.getBucketReplication({
Bucket: config.Bucket,
Expand All @@ -3882,6 +3950,18 @@ group('BucketReplication', function () {
}, 2000);
});
});
test('deleteBucketReplication() bucket not exist', function (done, assert) {
cos.deleteBucketReplication({
Bucket: Date.now().toString(36) + config.Bucket, // Bucket 格式:test-1250000000
Region: config.Region,
VersioningConfiguration: {
Status: 'Suspended'
}
}, function (err, data) {
assert.ok(err);
done();
});
});
});

group('putBucketVersioning(),getBucketVersioning()', function () {
Expand Down

0 comments on commit 210fcc6

Please sign in to comment.