|
| 1 | +import { Stack } from "aws-cdk-lib"; |
| 2 | +import { Template } from "aws-cdk-lib/assertions"; |
| 3 | +import { Alarm, Metric } from "aws-cdk-lib/aws-cloudwatch"; |
| 4 | +import { Function, InlineCode, Runtime } from "aws-cdk-lib/aws-lambda"; |
| 5 | + |
| 6 | +import { LambdaAlarmActionStrategy } from "../../../../lib"; |
| 7 | + |
| 8 | +test("snapshot test: Lambda function", () => { |
| 9 | + const stack = new Stack(); |
| 10 | + const onAlarmFunction = new Function(stack, "alarmLambda", { |
| 11 | + functionName: "DummyLambda", |
| 12 | + runtime: Runtime.NODEJS_18_X, |
| 13 | + code: InlineCode.fromInline("{}"), |
| 14 | + handler: "Dummy::handler", |
| 15 | + }); |
| 16 | + const alarm = new Alarm(stack, "DummyAlarm", { |
| 17 | + evaluationPeriods: 1, |
| 18 | + threshold: 0, |
| 19 | + metric: new Metric({ namespace: "Dummy", metricName: "Dummy" }), |
| 20 | + }); |
| 21 | + const action = new LambdaAlarmActionStrategy(onAlarmFunction); |
| 22 | + action.addAlarmActions({ alarm, action }); |
| 23 | + |
| 24 | + expect(Template.fromStack(stack)).toMatchSnapshot(); |
| 25 | +}); |
| 26 | + |
| 27 | +test("snapshot test: Lambda alias", () => { |
| 28 | + const stack = new Stack(); |
| 29 | + const onAlarmFunction = new Function(stack, "alarmLambda", { |
| 30 | + functionName: "DummyLambda", |
| 31 | + runtime: Runtime.NODEJS_18_X, |
| 32 | + code: InlineCode.fromInline("{}"), |
| 33 | + handler: "Dummy::handler", |
| 34 | + }); |
| 35 | + const alias = onAlarmFunction.addAlias("aliasName"); |
| 36 | + const alarm = new Alarm(stack, "DummyAlarm", { |
| 37 | + evaluationPeriods: 1, |
| 38 | + threshold: 0, |
| 39 | + metric: new Metric({ namespace: "Dummy", metricName: "Dummy" }), |
| 40 | + }); |
| 41 | + const action = new LambdaAlarmActionStrategy(alias); |
| 42 | + action.addAlarmActions({ alarm, action }); |
| 43 | + |
| 44 | + expect(Template.fromStack(stack)).toMatchSnapshot(); |
| 45 | +}); |
| 46 | + |
| 47 | +test("snapshot test: Lambda version", () => { |
| 48 | + const stack = new Stack(); |
| 49 | + const onAlarmFunction = new Function(stack, "alarmLambda", { |
| 50 | + functionName: "DummyLambda", |
| 51 | + runtime: Runtime.NODEJS_18_X, |
| 52 | + code: InlineCode.fromInline("{}"), |
| 53 | + handler: "Dummy::handler", |
| 54 | + }); |
| 55 | + const version = onAlarmFunction.currentVersion; |
| 56 | + const alarm = new Alarm(stack, "DummyAlarm", { |
| 57 | + evaluationPeriods: 1, |
| 58 | + threshold: 0, |
| 59 | + metric: new Metric({ namespace: "Dummy", metricName: "Dummy" }), |
| 60 | + }); |
| 61 | + const action = new LambdaAlarmActionStrategy(version); |
| 62 | + action.addAlarmActions({ alarm, action }); |
| 63 | + |
| 64 | + expect(Template.fromStack(stack)).toMatchSnapshot(); |
| 65 | +}); |
0 commit comments