-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.test.ts
105 lines (92 loc) · 3.01 KB
/
index.test.ts
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
import { test } from 'tap'
import _ from 'lodash'
import type { Template } from 'cloudform-types'
import type Resource from 'cloudform-types/types/resource'
import { handler } from '../index'
import _template from './event.json'
const template = _template as Template
const event = { fragment: template, requestId: 'test' }
test('macro returns success', async t => {
const result = await handler(event)
t.equal(result.status, 'success')
t.end()
})
test('macro uses topicArn if specified', async t => {
const topicArn = 'arn:aws:sns:eu-west-1:123456789123:TestTopic'
const eventWithTopic = {
...event,
fragment: {
...event.fragment,
Metadata: {
...event.fragment.Metadata,
slicWatch: {
...event.fragment.Metadata?.slicWatch,
alarmActionsConfig: {
alarmActions: [topicArn],
okActions: [topicArn]
}
}
}
}
}
const result = await handler(eventWithTopic)
t.equal(result.status, 'success')
t.notOk(result.errorMessage)
t.same(result?.fragment?.Resources?.slicWatchLambdaDurationAlarmHelloLambdaFunction?.Properties?.AlarmActions, [topicArn])
t.end()
})
test('Macro skips SLIC Watch if top-level enabled==false', async t => {
const testevent = _.cloneDeep(event)
testevent.fragment.Metadata = { slicWatch: { enabled: false } }
const output = await handler(testevent)
t.equal(output.status, 'success')
t.equal(output.fragment, testevent.fragment)
t.end()
})
test('Macro adds dashboard and alarms if no function configuration is provided', async t => {
const functionResource: Resource = {
...event.fragment.Resources?.HelloLambdaFunction,
Metadata: {}
} as unknown as Resource
const testEvent = {
...event,
fragment: {
...event.fragment,
Resources: {
...event.fragment.Resources,
HelloLambdaFunction: functionResource
}
}
}
const compiledTemplate = (await handler(testEvent)).fragment
t.same(compiledTemplate?.Resources?.Properties, template.Resources?.Properties)
t.end()
})
test('Macro execution fails if an invalid SLIC Watch config is provided', async t => {
const testevent = _.cloneDeep(event)
testevent.fragment.Metadata = { slicWatch: { topicArrrrn: 'pirateTopic' } }
const result = await handler(testevent)
t.equal(result.status, 'fail')
t.ok(result.errorMessage)
t.end()
})
test('Macro execution succeeds with no slicWatch config', t => {
const testevent = _.cloneDeep(event)
delete testevent.fragment.Metadata?.slicWatch
handler(testevent)
t.end()
})
test('Macro execution succeeds if no SNS Topic is provided', t => {
const testevent = _.cloneDeep(event)
delete testevent.fragment.Metadata?.slicWatch.topicArn
delete testevent.fragment.Metadata?.slicWatch.alarmActionsConfig
handler(testevent)
t.end()
})
test('Macro succeeds with no custom section', async t => {
const testevent = _.cloneDeep(event)
delete testevent.fragment.Metadata
const result = await handler(testevent)
t.equal(result.status, 'success')
t.end()
})