@@ -9,6 +9,10 @@ const MAX_DIMENSION_COUNT = 9;
9
9
10
10
const consoleSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ) ;
11
11
12
+ interface LooseObject {
13
+ [ key : string ] : string
14
+ }
15
+
12
16
describe ( 'Class: Metrics' , ( ) => {
13
17
14
18
const originalEnvironmentVariables = process . env ;
@@ -75,6 +79,39 @@ describe('Class: Metrics', () => {
75
79
expect ( e . message ) . toBe ( `Max dimension count of ${ MAX_DIMENSION_COUNT } hit` ) ;
76
80
}
77
81
} ) ;
82
+
83
+ test ( 'Additional bulk dimensions should be added correctly' , ( ) => {
84
+ const additionalDimensions : LooseObject = { 'dimension2' : 'dimension2Value' , 'dimension3' : 'dimension3Value' } ;
85
+ const metrics = new Metrics ( { namespace : 'test' } ) ;
86
+
87
+ metrics . addMetric ( 'test_name' , MetricUnits . Seconds , 10 ) ;
88
+ metrics . addDimensions ( additionalDimensions ) ;
89
+ const loggedData = metrics . serializeMetrics ( ) ;
90
+
91
+ expect ( loggedData . _aws . CloudWatchMetrics [ 0 ] . Dimensions [ 0 ] . length ) . toEqual ( 2 ) ;
92
+ Object . keys ( additionalDimensions ) . forEach ( ( key ) => {
93
+
94
+ expect ( loggedData [ key ] ) . toEqual ( additionalDimensions [ key ] ) ;
95
+ } ) ;
96
+ } ) ;
97
+
98
+ test ( 'Bulk Adding more than max dimensions should throw error' , ( ) => {
99
+ expect . assertions ( 1 ) ;
100
+ const metrics = new Metrics ( ) ;
101
+ const additionalDimensions : LooseObject = { } ;
102
+
103
+ metrics . addDimension ( `Dimension-Initial` , `Dimension-InitialValue` ) ;
104
+ for ( let x = 0 ; x < MAX_DIMENSION_COUNT ; x ++ ) {
105
+ additionalDimensions [ `dimension${ x } ` ] = `dimension${ x } Value` ;
106
+ }
107
+
108
+ try {
109
+ metrics . addDimensions ( additionalDimensions ) ;
110
+ }
111
+ catch ( e ) {
112
+ expect ( e . message ) . toBe ( `Adding ${ Object . keys ( additionalDimensions ) . length } dimensions would exceed max dimension count of ${ MAX_DIMENSION_COUNT } ` ) ;
113
+ }
114
+ } ) ;
78
115
} ) ;
79
116
80
117
describe ( 'Feature: Metadata' , ( ) => {
@@ -100,10 +137,6 @@ describe('Class: Metrics', () => {
100
137
test ( 'Adding more than max default dimensions should throw error' , ( ) => {
101
138
expect . assertions ( 1 ) ;
102
139
103
- interface LooseObject {
104
- [ key : string ] : string
105
- }
106
-
107
140
const defaultDimensions : LooseObject = { } ;
108
141
for ( let x = 0 ; x < MAX_DIMENSION_COUNT + 1 ; x ++ ) {
109
142
defaultDimensions [ `dimension-${ x } ` ] = `value-${ x } ` ;
0 commit comments