-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathcdn.test.js
115 lines (104 loc) · 4.23 KB
/
cdn.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const qiniu = require('../index.js');
const should = require('should');
const proc = require('process');
const console = require('console');
// eslint-disable-next-line no-undef
before(function (done) {
if (!process.env.QINIU_ACCESS_KEY || !process.env.QINIU_SECRET_KEY || !process.env.QINIU_TEST_BUCKET || !process.env.QINIU_TEST_DOMAIN) {
console.log('should run command `source test-env.sh` first\n');
process.exit(0);
}
done();
});
// eslint-disable-next-line no-undef
describe('test start cdn', function () {
this.timeout(0);
var accessKey = proc.env.QINIU_ACCESS_KEY;
var secretKey = proc.env.QINIU_SECRET_KEY;
var domain = proc.env.QINIU_TEST_DOMAIN;
var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
var cdnManager = new qiniu.cdn.CdnManager(mac);
it('test getCdnLogList', function (done) {
var day = (new Date()).toISOString().substring(0, 10);
cdnManager.getCdnLogList([domain], day,
function (err, respBody, respInfo) {
console.log(respBody, respInfo);
should.not.exist(err);
respBody.should.have.keys('code', 'data');
done();
});
});
it('test getFluxData', function (done) {
var today = new Date();
var endDay = today.toISOString().substring(0, 10);
today.setDate(today.getDate() - 30);
var startDay = today.toISOString().substring(0, 10);
cdnManager.getFluxData(startDay, endDay, '5hour', [domain],
function (err, respBody, respInfo) {
console.log(respBody, respInfo);
should.not.exist(err);
respBody.should.have.keys('code', 'data');
done();
});
});
it('test getBandwidthData', function (done) {
var today = new Date();
var endDay = today.toISOString().substring(0, 10);
today.setDate(today.getDate() - 30);
var startDay = today.toISOString().substring(0, 10);
cdnManager.getBandwidthData(startDay, endDay, '5hour', [domain],
function (err, respBody, respInfo) {
console.log(respBody, respInfo);
should.not.exist(err);
respBody.should.have.keys('code', 'data');
done();
});
});
it('test prefetchUrls', function (done) {
var urls = ['http://' + domain + '/qiniu.mp4'];
cdnManager.prefetchUrls(urls,
function (err, respBody, respInfo) {
console.log(respBody, respInfo);
should.not.exist(err);
respBody.should.have.keys('code', 'taskIds', 'requestId');
done();
});
});
it('test refreshUrls', function (done) {
var urls = ['http://' + domain + '/qiniu.mp4'];
cdnManager.refreshUrls(urls,
function (err, respBody, respInfo) {
console.log(respBody, respInfo);
should.not.exist(err);
respBody.should.have.keys('code', 'taskIds', 'requestId');
done();
});
});
it('test refreshDirs', function (done) {
var dirs = ['http://' + domain + '/'];
cdnManager.refreshDirs(dirs,
function (err, respBody, respInfo) {
console.log(respBody, respInfo);
should.not.exist(err);
respBody.should.have.keys('code', 'taskIds', 'requestId');
done();
});
});
it('test refreshUrlsAndDirs', function (done) {
var urls = ['http://' + domain + '/qiniu.mp4'];
var dirs = ['http://' + domain + '/'];
cdnManager.refreshUrlsAndDirs(urls, dirs,
function (err, respBody, respInfo) {
console.log(respBody, respInfo);
should.not.exist(err);
respBody.should.have.keys('code', 'taskIds', 'requestId');
done();
});
});
it('test createTimestampAntiLeechUrl', function (done) {
var host = 'http://' + domain;
var url = cdnManager.createTimestampAntiLeechUrl(host, 'qiniu.mp4', 'aa=23', 'encryptKey', 20);
should.equal(url, host + '/qiniu.mp4?aa=23&sign=1a530a8baafe126145f49cb738a50c09&t=14');
done();
});
});