1 | 'use strict'
|
2 |
|
3 | const assert = require('chai').assert
|
4 | const path = require('path')
|
5 | const aws = require('aws-sdk-mock')
|
6 | aws.setSDK(path.resolve('node_modules/aws-sdk'))
|
7 | const CloudWatchLogs = require(path.join('..', 'lib', 'cloudwatch_logs'))
|
8 |
|
9 | const mockResponse = {
|
10 | createLogGroup: {
|
11 | testCreateLogGroupResponse: 'An empty object is returned in the actual API'
|
12 | },
|
13 |
|
14 | putRetentionPolicy: {
|
15 | testPutRetentionPolicyResponse: 'An empty object is returned in the actual API'
|
16 | }
|
17 | }
|
18 |
|
19 | const params = {
|
20 | FunctionName: 'node-lambda-test-function',
|
21 | retentionInDays: 14
|
22 | }
|
23 |
|
24 | var logs = null
|
25 |
|
26 |
|
27 | describe('lib/cloudwatch_logs', () => {
|
28 | before(() => {
|
29 | aws.mock('CloudWatchLogs', 'createLogGroup', (params, callback) => {
|
30 | callback(null, mockResponse.createLogGroup)
|
31 | })
|
32 | aws.mock('CloudWatchLogs', 'putRetentionPolicy', (params, callback) => {
|
33 | callback(null, mockResponse.putRetentionPolicy)
|
34 | })
|
35 |
|
36 | logs = new CloudWatchLogs(require('aws-sdk'))
|
37 | })
|
38 |
|
39 | after(() => aws.restore('CloudWatchLogs'))
|
40 |
|
41 | describe('_logGroupName', () => {
|
42 | it('correct value', () => {
|
43 | assert.equal(
|
44 | logs._logGroupName(params),
|
45 | '/aws/lambda/node-lambda-test-function'
|
46 | )
|
47 | })
|
48 | })
|
49 |
|
50 | describe('_createLogGroup', () => {
|
51 | it('using mock', () => {
|
52 | return logs._createLogGroup(params).then((data) => {
|
53 | assert.deepEqual(data, mockResponse.createLogGroup)
|
54 | })
|
55 | })
|
56 | })
|
57 |
|
58 | describe('_putRetentionPolicy', () => {
|
59 | it('using mock', () => {
|
60 | return logs._putRetentionPolicy(params).then((data) => {
|
61 | assert.deepEqual(data, mockResponse.putRetentionPolicy)
|
62 | })
|
63 | })
|
64 | })
|
65 |
|
66 | describe('setLogsRetentionPolicy', () => {
|
67 | it('using mock', () => {
|
68 | return logs.setLogsRetentionPolicy(params).then((data) => {
|
69 | assert.deepEqual(data, mockResponse.putRetentionPolicy)
|
70 | })
|
71 | })
|
72 | })
|
73 | })
|