-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathcloudwatch_logs.js
76 lines (64 loc) · 1.89 KB
/
cloudwatch_logs.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
'use strict'
let assert
import('chai').then(chai => {
assert = chai.assert
})
const path = require('path')
const aws = require('aws-sdk-mock')
aws.setSDK(path.resolve('node_modules/aws-sdk'))
const CloudWatchLogs = require(path.join('..', 'lib', 'cloudwatch_logs'))
const mockResponse = {
createLogGroup: {
testCreateLogGroupResponse: 'An empty object is returned in the actual API'
},
putRetentionPolicy: {
testPutRetentionPolicyResponse: 'An empty object is returned in the actual API'
}
}
const params = {
FunctionName: 'node-lambda-test-function',
retentionInDays: 14
}
let logs = null
/* global before, after, describe, it */
describe('lib/cloudwatch_logs', () => {
before(() => {
aws.mock('CloudWatchLogs', 'createLogGroup', (params, callback) => {
callback(null, mockResponse.createLogGroup)
})
aws.mock('CloudWatchLogs', 'putRetentionPolicy', (params, callback) => {
callback(null, mockResponse.putRetentionPolicy)
})
logs = new CloudWatchLogs(require('aws-sdk'))
})
after(() => aws.restore('CloudWatchLogs'))
describe('_logGroupName', () => {
it('correct value', () => {
assert.equal(
logs._logGroupName(params),
'/aws/lambda/node-lambda-test-function'
)
})
})
describe('_createLogGroup', () => {
it('using mock', () => {
return logs._createLogGroup(params).then((data) => {
assert.deepEqual(data, mockResponse.createLogGroup)
})
})
})
describe('_putRetentionPolicy', () => {
it('using mock', () => {
return logs._putRetentionPolicy(params).then((data) => {
assert.deepEqual(data, mockResponse.putRetentionPolicy)
})
})
})
describe('setLogsRetentionPolicy', () => {
it('using mock', () => {
return logs.setLogsRetentionPolicy(params).then((data) => {
assert.deepEqual(data, mockResponse.putRetentionPolicy)
})
})
})
})