ks3
Version:
本代码库为`金山云存储KS3`服务.主要提供`KS3 nodejs SDK`和`命令行工具`.
127 lines (122 loc) • 4.43 kB
JavaScript
var KS3 = require('..')
var should = require('should')
var util = require("../lib/util")
var path = require('path')
var xml2json = util.xml2json;
require('should-http')
/**
* 测试bucket retention
*/
const { ak, sk } = require('./config')
describe('API bucket', function () {
var bucketName = 'test-sdk-' + +new Date()
var client = new KS3(ak, sk, bucketName)
var acl = 'public-read'
var key = 'word.txt'
before(function (done) {
client.bucket.put(
{
Bucket: bucketName,
ACL: acl,
},
function (err, data, res) {
should.not.exist(err)
res.should.have.status(200)
client.object.put(
{
Key: key,
FilePath: path.join(__dirname, './assets/' + key),
ACL: acl,
},
function (err, data, res) {
should.not.exist(err)
done()
}
)
}
)
})
describe('bucket retention', function () {
it('set bucket retention require retention', function () {
;(function () {
client.bucket.putBucketRetention(function () {})
}).should.throw()
})
it('set bucket retention', function (done) {
client.bucket.putBucketRetention(
{
Status: 'Enabled',
Days: 3,
},
function (err, data, res) {
should.not.exist(err)
res.should.have.status(200)
done()
}
)
})
this.timeout(300002)
it('list bucket retention', function (done) {
setTimeout(() => {
it('delete object', function (done) {
client.object.del(
{
Key: key,
},
function (err, data, res) {
console.log(res.statusCode)
should.not.exist(err)
res.should.have.status(204)
done()
}
)
})
this.timeout(3000)
client.bucket.listBucketRetention(function (err, data, res) {
should.not.exist(err);
res.should.have.status(200);
let result = xml2json.parser(data);
let RetentionId = result.ListRetentionResult.Contents.RetentionId;
let Key = result.ListRetentionResult.Contents.Name;
client.object.recoverObject(
{
RetentionId,
Key,
Overwrite: true,
},
function (err, data, res) {
should.not.exist(err);
res.should.have.status(200);
client.object.clearObject(
{
RetentionId,
Key,
},
function (err, data, res) {
console.log('==========> statusCode:', res.statusCode)
should.not.exist(err);
res.should.have.status(200);
done();
}
);
}
);
});
}, 300000); // 等待300秒后再执行
})
})
after(function (done) {
client.bucket.del(function(err, data, res) {
should.not.exist(err);
res.should.have.status(204); // 删除bucket,成功的状态码为204
done();
})
})
})
function outputCurrentTime() {
const now = new Date();
const hours = now.getHours().toString().padStart(2, '0');
const minutes = now.getMinutes().toString().padStart(2, '0');
const seconds = now.getSeconds().toString().padStart(2, '0');
return `${hours}:${minutes}:${seconds}`;
}