ks3
Version:
本代码库为`金山云存储KS3`服务.主要提供`KS3 nodejs SDK`和`命令行工具`.
176 lines (160 loc) • 4.18 kB
JavaScript
var KS3 = require('..');
var should = require('should');
var pkg = require('../package.json')
var { ak, sk, endpoint } = require('./config')
describe('KS3 instantiation', function() {
it('require ak and sk、endpoint', function() {
true && (function() {
var client = new KS3();
}).should.throw ('require ak and sk、endpoint. visit: http://ks3.ksyun.com/doc/api/index.html. ak=AccessKeyID,sk=AccessKeySecret')
});
it('should not require bucketName',function(){
true && (function() {
var client = new KS3({
ak,sk,
endpoint,
});
}).should.not.throw ()
})
it('use Uppercase camel-case should return true', function () {
true && (function () {
new KS3({
AK: ak,
SK: sk,
Endpoint: endpoint,
Internal: true,
Secure: true,
DomainMode: true,
BucketName: 'liubo-test'
})
}).should.not.throw()
})
// 自定义域名的判断需要对请求的uri进行对比
// it('should equal with endpoint if domainMode value true', function () {
// const host = 'ksyuncs.com'
// var client = new KS3({
// ak,
// sk,
// endpoint: host,
// domainMode: true
// })
// should.equal(client.endpoint, host)
// })
it('should compatible old version', function () {
(function () {
new KS3(ak, sk, '', 'BEIJING')
}).should.not.throw()
})
// it('should check region if not in map', function () {
// (function() {
// new KS3(ak, sk, '', 'beijing')
// }).should.throw('region is not legal, please check params')
// })
it('should get https endpoint', function () {
var client = new KS3({
ak,
sk,
endpoint,
secure: true
})
should.equal(client.endpoint, `${endpoint}`)
})
it('should get internal address', function () {
var client = new KS3({
ak,
sk,
endpoint,
internal: true
})
var internalEndpoint = ''
if (endpoint) {
const prefix = endpoint.substring(0, endpoint.indexOf('.'))
const suffix = endpoint.substring(endpoint.indexOf('.'))
internalEndpoint = `${prefix}-internal${suffix}`
}
should.equal(client.endpoint, internalEndpoint)
})
it('should get secure internal address', function () {
var client = new KS3({
ak,
sk,
endpoint,
internal: true,
secure: true
})
var internalEndpoint = ''
if (endpoint) {
const prefix = endpoint.substring(0, endpoint.indexOf('.'))
const suffix = endpoint.substring(endpoint.indexOf('.'))
internalEndpoint = `https://${prefix}-internal${suffix}`
}
should.equal('https://' + client.endpoint, internalEndpoint)
})
it('should return domainMode url if set internal、secure、domainMode all true', function () {
var client = new KS3({
ak,
sk,
endpoint,
internal: true,
secure: true,
domainMode: true
})
should.equal(client.endpoint, endpoint)
})
it ('should support cname if domainMode is true', function () {
(function() {
new KS3({
ak,
sk,
endpoint: 'xxx.website',
domainMode: true
})
}).should.not.throw()
})
it ('should not support cname if domainMode is false', function () {
(function() {
new KS3({
ak,
sk,
endpoint: 'xxx.website',
domainMode: false
})
}).should.throw()
})
var timeout = 1888
var client = new KS3({
ak,
sk,
endpoint: 'ks3-cn-beijing-internal.ksyuncs.com',
timeout
})
it('should has request property', function () {
client.should.have.properties('request');
})
});
describe('KS3 init', function() {
var client = new KS3({ak,sk,endpoint});
it('should have these api: service,bucket,object', function() {
client.should.have.property('service');
client.should.have.property('bucket');
client.should.have.property('object');
});
});
describe('KS3 config', function() {
var client = new KS3({ak,sk,endpoint});
it('should change the default config in config.js', function() {
var testCfg = {
dataType : 'json',
ua : 'TEST_KS3_NodeJS'
};
var defaultCfg = {
dataType : 'xml',
ua : `KS3_NodeJS/${pkg.version}`
}
client.config(testCfg);
var config = require('./../config');
config.dataType.should.equal('json');
config.ua.should.equal(`KS3_NodeJS/${pkg.version} TEST_KS3_NodeJS`);
client.config(defaultCfg);
});
});