@@ -14,10 +14,12 @@ import { Construct } from "constructs";
14
14
15
15
import {
16
16
AddAlarmProps ,
17
+ AlarmActionStrategyProps ,
17
18
AlarmFactory ,
18
19
AlarmFactoryDefaults ,
19
20
AlarmNamingInput ,
20
21
CompositeAlarmOperator ,
22
+ IAlarmActionStrategy ,
21
23
IAlarmNamingStrategy ,
22
24
MetricFactoryDefaults ,
23
25
MetricStatistic ,
@@ -32,6 +34,16 @@ const construct = new Construct(stack, "SampleConstruct");
32
34
const snsAction = new SnsAlarmActionStrategy ( {
33
35
onAlarmTopic : new Topic ( stack , "Dummy2" ) ,
34
36
} ) ;
37
+
38
+ class SampleAlarmActionStrategy implements IAlarmActionStrategy {
39
+ readonly prop = "Sample" ;
40
+
41
+ addAlarmActions ( _props : AlarmActionStrategyProps ) : void {
42
+ // No-op
43
+ }
44
+ }
45
+ const sampleAction = new SampleAlarmActionStrategy ( ) ;
46
+
35
47
const globalMetricDefaults : MetricFactoryDefaults = {
36
48
namespace : "DummyNamespace" ,
37
49
} ;
@@ -722,11 +734,18 @@ test("addAlarm: custom alarm naming strategy", () => {
722
734
const disambiguator = "Critical" ;
723
735
const stack = new Stack ( ) ;
724
736
const customNamingStrategy : IAlarmNamingStrategy = {
725
- getName : ( props : AlarmNamingInput ) => `${ alarmName } -${ props . disambiguator } ` ,
737
+ getName : ( props : AlarmNamingInput ) =>
738
+ `${ alarmName } -${ props . disambiguator } -${
739
+ ( props . action as SampleAlarmActionStrategy ) . prop
740
+ } `,
726
741
getWidgetLabel : ( props : AlarmNamingInput ) =>
727
- `${ alarmLabel } -${ props . disambiguator } ` ,
742
+ `${ alarmLabel } -${ props . disambiguator } -${
743
+ ( props . action as SampleAlarmActionStrategy ) . prop
744
+ } `,
728
745
getDedupeString : ( props : AlarmNamingInput ) =>
729
- `${ alarmDedupe } -${ props . disambiguator } ` ,
746
+ `${ alarmDedupe } -${ props . disambiguator } -${
747
+ ( props . action as SampleAlarmActionStrategy ) . prop
748
+ } `,
730
749
} ;
731
750
const factory = new AlarmFactory ( stack , {
732
751
globalMetricDefaults,
@@ -736,13 +755,15 @@ test("addAlarm: custom alarm naming strategy", () => {
736
755
} ,
737
756
localAlarmNamePrefix : "prefix" ,
738
757
} ) ;
758
+ const action = sampleAction ;
739
759
const alarm = factory . addAlarm ( metric , {
740
760
...props ,
741
761
disambiguator,
762
+ actionOverride : action ,
742
763
} ) ;
743
- expect ( alarm . alarmName ) . toBe ( `${ alarmName } -${ disambiguator } ` ) ;
744
- expect ( alarm . alarmLabel ) . toBe ( `${ alarmLabel } -${ disambiguator } ` ) ;
745
- expect ( alarm . dedupeString ) . toBe ( `${ alarmDedupe } -${ disambiguator } ` ) ;
764
+ expect ( alarm . alarmName ) . toBe ( `${ alarmName } -${ disambiguator } -Sample ` ) ;
765
+ expect ( alarm . alarmLabel ) . toBe ( `${ alarmLabel } -${ disambiguator } -Sample ` ) ;
766
+ expect ( alarm . dedupeString ) . toBe ( `${ alarmDedupe } -${ disambiguator } -Sample ` ) ;
746
767
} ) ;
747
768
748
769
test ( "addAlarm: custom metric adjuster, applies it and DefaultMetricAdjuster after it" , ( ) => {
0 commit comments