-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtencentMetrics.test.js
80 lines (67 loc) · 2.41 KB
/
tencentMetrics.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
const fs = require('fs')
const os = require('os')
const sinon = require('sinon')
const TencentProvider = require('../provider/tencentProvider')
const Serverless = require('../test/serverless')
const TencentMetrics = require('./tencentMetrics')
describe('TencentMetrics', () => {
let serverless
let options
let tencentMetrics
let readFileSyncStub
let homedirStub
beforeEach(() => {
serverless = new Serverless()
options = {
stage: 'dev',
region: 'ap-guangzhou',
function: 'test'
}
readFileSyncStub = sinon.stub(fs, 'readFileSync').returns(`[default]
tencent_secret_key = PYR4a0HSZ******eVvHRe
tencent_secret_id = AKIDoM*****mxsfOirI
tencent_appid = 12561*****`)
homedirStub = sinon.stub(os, 'homedir').returns('/root')
serverless.setProvider('tencent', new TencentProvider(serverless, options))
tencentMetrics = new TencentMetrics(serverless, options)
})
afterEach(() => {
fs.readFileSync.restore()
os.homedir.restore()
})
describe('#constructor()', () => {
it('should set the serverless instance', () => {
tencentMetrics.serverless.should.equal(serverless)
})
it('should set options if provided', () => {
tencentMetrics.options.should.equal(options)
})
it('should make the provider accessible', () => {
tencentMetrics.provider.should.to.be.an.instanceof(TencentProvider)
})
describe('hooks', () => {
let validateStub
let setDefaultsStub
let tencentMetricsStub
beforeEach(() => {
validateStub = sinon.stub(tencentMetrics, 'validate').returns(Promise.resolve())
setDefaultsStub = sinon.stub(tencentMetrics, 'setDefaults').returns(Promise.resolve())
tencentMetricsStub = sinon.stub(tencentMetrics, 'metrics').returns(Promise.resolve())
})
afterEach(() => {
tencentMetrics.validate.restore()
tencentMetrics.setDefaults.restore()
tencentMetrics.metrics.restore()
})
it('should run "before:metrics:metrics" promise chain', () =>
tencentMetrics.hooks['before:metrics:metrics']().then(() => {
validateStub.calledOnce.should.equal(true)
setDefaultsStub.calledAfter(validateStub).should.equal(true)
}))
it('should run "metrics:metrics" promise chain', () =>
tencentMetrics.hooks['metrics:metrics']().then(() => {
tencentMetricsStub.calledOnce.should.equal(true)
}))
})
})
})