@datadog/datadog-ci 0.17.6-alpha → 0.17.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/LICENSE-3rdparty.csv +1 -0
  2. package/dist/commands/dependencies/__tests__/helpers/context.d.ts +12 -0
  3. package/dist/commands/dependencies/__tests__/helpers/stream.d.ts +2 -0
  4. package/dist/commands/dependencies/__tests__/helpers/upload.run.d.ts +13 -0
  5. package/dist/commands/dependencies/__tests__/upload.test.d.ts +1 -0
  6. package/dist/commands/dependencies/api.d.ts +2 -0
  7. package/dist/commands/dependencies/index.d.ts +1 -0
  8. package/dist/commands/dependencies/interfaces.d.ts +10 -0
  9. package/dist/commands/dependencies/renderer.d.ts +13 -0
  10. package/dist/commands/dependencies/upload.d.ts +16 -0
  11. package/dist/commands/dsyms/__tests__/upload.test.d.ts +1 -0
  12. package/dist/commands/dsyms/__tests__/utils.test.d.ts +1 -0
  13. package/dist/commands/dsyms/index.d.ts +1 -0
  14. package/dist/commands/dsyms/interfaces.d.ts +7 -0
  15. package/dist/commands/dsyms/renderer.d.ts +9 -0
  16. package/dist/commands/dsyms/upload.d.ts +11 -0
  17. package/dist/commands/dsyms/utils.d.ts +9 -0
  18. package/dist/commands/git-metadata/__tests__/git.test.d.ts +1 -0
  19. package/dist/commands/{commit → git-metadata}/__tests__/git.test.js +0 -0
  20. package/dist/commands/git-metadata/__tests__/upload.test.d.ts +1 -0
  21. package/dist/commands/{commit → git-metadata}/__tests__/upload.test.js +1 -1
  22. package/dist/commands/git-metadata/api.d.ts +3 -0
  23. package/dist/commands/{commit → git-metadata}/api.js +0 -0
  24. package/dist/commands/git-metadata/git.d.ts +8 -0
  25. package/dist/commands/{commit → git-metadata}/git.js +0 -0
  26. package/dist/commands/git-metadata/index.d.ts +1 -0
  27. package/dist/commands/{commit → git-metadata}/index.js +0 -0
  28. package/dist/commands/git-metadata/interfaces.d.ts +9 -0
  29. package/dist/commands/{commit → git-metadata}/interfaces.js +0 -0
  30. package/dist/commands/git-metadata/renderer.d.ts +8 -0
  31. package/dist/commands/{commit → git-metadata}/renderer.js +5 -8
  32. package/dist/commands/git-metadata/upload.d.ts +12 -0
  33. package/dist/commands/{commit → git-metadata}/upload.js +8 -3
  34. package/dist/commands/junit/__tests__/api.test.d.ts +1 -0
  35. package/dist/commands/junit/__tests__/upload.test.d.ts +1 -0
  36. package/dist/commands/junit/api.d.ts +8 -0
  37. package/dist/commands/junit/index.d.ts +1 -0
  38. package/dist/commands/junit/interfaces.d.ts +12 -0
  39. package/dist/commands/junit/renderer.d.ts +8 -0
  40. package/dist/commands/junit/upload.d.ts +15 -0
  41. package/dist/commands/junit/upload.js +8 -25
  42. package/dist/commands/junit/utils.d.ts +1 -0
  43. package/dist/commands/lambda/__tests__/fixtures.d.ts +42 -0
  44. package/dist/commands/lambda/__tests__/fixtures.js +73 -0
  45. package/dist/commands/lambda/__tests__/functions/commons.test.d.ts +1 -0
  46. package/dist/commands/lambda/__tests__/functions/commons.test.js +171 -0
  47. package/dist/commands/lambda/__tests__/functions/instrument.test.d.ts +1 -0
  48. package/dist/commands/lambda/__tests__/{function.test.js → functions/instrument.test.js} +355 -417
  49. package/dist/commands/lambda/__tests__/functions/uninstrument.test.d.ts +1 -0
  50. package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +298 -0
  51. package/dist/commands/lambda/__tests__/instrument.test.d.ts +1 -0
  52. package/dist/commands/lambda/__tests__/instrument.test.js +270 -163
  53. package/dist/commands/lambda/__tests__/loggroup.test.d.ts +1 -0
  54. package/dist/commands/lambda/__tests__/loggroup.test.js +98 -34
  55. package/dist/commands/lambda/__tests__/tags.test.d.ts +1 -0
  56. package/dist/commands/lambda/__tests__/tags.test.js +107 -31
  57. package/dist/commands/lambda/__tests__/uninstrument.test.d.ts +1 -0
  58. package/dist/commands/lambda/__tests__/uninstrument.test.js +223 -0
  59. package/dist/commands/lambda/constants.d.ts +44 -0
  60. package/dist/commands/lambda/constants.js +2 -1
  61. package/dist/commands/lambda/functions/commons.d.ts +71 -0
  62. package/dist/commands/lambda/functions/commons.js +170 -0
  63. package/dist/commands/lambda/functions/instrument.d.ts +16 -0
  64. package/dist/commands/lambda/{function.js → functions/instrument.js} +42 -102
  65. package/dist/commands/lambda/functions/uninstrument.d.ts +6 -0
  66. package/dist/commands/lambda/functions/uninstrument.js +110 -0
  67. package/dist/commands/lambda/index.d.ts +1 -0
  68. package/dist/commands/lambda/index.js +2 -1
  69. package/dist/commands/lambda/instrument.d.ts +29 -0
  70. package/dist/commands/lambda/instrument.js +85 -40
  71. package/dist/commands/lambda/interfaces.d.ts +70 -0
  72. package/dist/commands/lambda/loggroup.d.ts +14 -0
  73. package/dist/commands/lambda/loggroup.js +27 -4
  74. package/dist/commands/lambda/tags.d.ts +6 -0
  75. package/dist/commands/lambda/tags.js +19 -3
  76. package/dist/commands/lambda/uninstrument.d.ts +11 -0
  77. package/dist/commands/lambda/uninstrument.js +127 -0
  78. package/dist/commands/sourcemaps/__tests__/git.test.d.ts +1 -0
  79. package/dist/commands/sourcemaps/__tests__/upload.test.d.ts +1 -0
  80. package/dist/commands/sourcemaps/__tests__/utils.test.d.ts +1 -0
  81. package/dist/commands/sourcemaps/git.d.ts +20 -0
  82. package/dist/commands/sourcemaps/index.d.ts +1 -0
  83. package/dist/commands/sourcemaps/interfaces.d.ts +15 -0
  84. package/dist/commands/sourcemaps/renderer.d.ts +12 -0
  85. package/dist/commands/sourcemaps/upload.d.ts +25 -0
  86. package/dist/commands/sourcemaps/utils.d.ts +3 -0
  87. package/dist/commands/sourcemaps/validation.d.ts +6 -0
  88. package/dist/commands/synthetics/__tests__/api.test.d.ts +1 -0
  89. package/dist/commands/synthetics/__tests__/cli.test.d.ts +1 -0
  90. package/dist/commands/synthetics/__tests__/cli.test.js +232 -0
  91. package/dist/commands/synthetics/__tests__/crypto.test.d.ts +1 -0
  92. package/dist/commands/synthetics/__tests__/fixtures.d.ts +71 -0
  93. package/dist/commands/synthetics/__tests__/fixtures.js +17 -2
  94. package/dist/commands/synthetics/__tests__/reporters/default.test.d.ts +1 -0
  95. package/dist/commands/synthetics/__tests__/reporters/default.test.js +5 -4
  96. package/dist/commands/synthetics/__tests__/reporters/junit.test.d.ts +1 -0
  97. package/dist/commands/synthetics/__tests__/run-test.test.d.ts +1 -0
  98. package/dist/commands/synthetics/__tests__/run-test.test.js +48 -319
  99. package/dist/commands/synthetics/__tests__/tunnel.test.d.ts +1 -0
  100. package/dist/commands/synthetics/__tests__/utils.test.d.ts +1 -0
  101. package/dist/commands/synthetics/__tests__/utils.test.js +13 -1
  102. package/dist/commands/synthetics/__tests__/websocket.test.d.ts +1 -0
  103. package/dist/commands/synthetics/__tests__/websocket.test.js +6 -5
  104. package/dist/commands/synthetics/api.d.ts +24 -0
  105. package/dist/commands/synthetics/cli.d.ts +26 -0
  106. package/dist/commands/synthetics/cli.js +229 -0
  107. package/dist/commands/synthetics/crypto.d.ts +5 -0
  108. package/dist/commands/synthetics/errors.d.ts +9 -0
  109. package/dist/commands/synthetics/errors.js +25 -0
  110. package/dist/commands/synthetics/index.d.ts +1 -0
  111. package/dist/commands/synthetics/index.js +2 -2
  112. package/dist/commands/synthetics/interfaces.d.ts +342 -0
  113. package/dist/commands/synthetics/reporters/default.d.ts +18 -0
  114. package/dist/commands/synthetics/reporters/default.js +4 -3
  115. package/dist/commands/synthetics/reporters/junit.d.ts +95 -0
  116. package/dist/commands/synthetics/run-test.d.ts +74 -0
  117. package/dist/commands/synthetics/run-test.js +135 -319
  118. package/dist/commands/synthetics/tunnel.d.ts +43 -0
  119. package/dist/commands/synthetics/utils.d.ts +27 -0
  120. package/dist/commands/synthetics/utils.js +24 -5
  121. package/dist/commands/synthetics/websocket.d.ts +38 -0
  122. package/dist/commands/trace/__tests__/trace.test.d.ts +1 -0
  123. package/dist/commands/trace/api.d.ts +6 -0
  124. package/dist/commands/trace/index.d.ts +1 -0
  125. package/dist/commands/trace/interfaces.d.ts +23 -0
  126. package/dist/commands/trace/trace.d.ts +17 -0
  127. package/dist/commands/trace/trace.js +32 -3
  128. package/dist/helpers/__tests__/ci.test.d.ts +1 -0
  129. package/dist/helpers/__tests__/ci.test.js +23 -0
  130. package/dist/helpers/__tests__/git.test.d.ts +1 -0
  131. package/dist/helpers/__tests__/retry.test.d.ts +1 -0
  132. package/dist/helpers/__tests__/retry.test.js +98 -0
  133. package/dist/helpers/__tests__/tags.test.d.ts +1 -0
  134. package/dist/helpers/__tests__/upload.test.d.ts +1 -0
  135. package/dist/helpers/__tests__/user-provided-git.test.d.ts +1 -0
  136. package/dist/helpers/__tests__/utils.test.d.ts +1 -0
  137. package/dist/helpers/apikey.d.ts +14 -0
  138. package/dist/helpers/ci.d.ts +15 -0
  139. package/dist/helpers/ci.js +13 -6
  140. package/dist/helpers/errors.d.ts +2 -0
  141. package/dist/helpers/formatting.d.ts +5 -0
  142. package/dist/helpers/git.d.ts +2 -0
  143. package/dist/helpers/interfaces.d.ts +19 -0
  144. package/dist/helpers/metrics.d.ts +11 -0
  145. package/dist/helpers/retry.d.ts +2 -0
  146. package/dist/helpers/retry.js +38 -0
  147. package/dist/helpers/tags.d.ts +28 -0
  148. package/dist/helpers/upload.d.ts +44 -0
  149. package/dist/helpers/upload.js +4 -26
  150. package/dist/helpers/user-provided-git.d.ts +1 -0
  151. package/dist/helpers/utils.d.ts +31 -0
  152. package/dist/index.d.ts +1 -0
  153. package/package.json +2 -1
@@ -0,0 +1 @@
1
+ export {};
@@ -9,30 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ const constants_1 = require("../constants");
12
13
  const loggroup_1 = require("../loggroup");
13
- const makeMockCloudWatch = (logGroups) => ({
14
- createLogGroup: jest.fn().mockImplementation(() => ({ promise: () => Promise.resolve() })),
15
- deleteSubscriptionFilter: jest.fn().mockImplementation(() => ({ promise: () => Promise.resolve() })),
16
- describeLogGroups: jest.fn().mockImplementation(({ logGroupNamePrefix }) => {
17
- var _a, _b;
18
- const groups = (_b = (_a = logGroups[logGroupNamePrefix]) === null || _a === void 0 ? void 0 : _a.config) !== null && _b !== void 0 ? _b : { logGroups: [] };
19
- return {
20
- promise: () => Promise.resolve(groups),
21
- };
22
- }),
23
- describeSubscriptionFilters: jest.fn().mockImplementation(({ logGroupName }) => {
24
- var _a, _b;
25
- const groups = (_b = (_a = logGroups[logGroupName]) === null || _a === void 0 ? void 0 : _a.filters) !== null && _b !== void 0 ? _b : { subscriptionFilters: [] };
26
- return {
27
- promise: () => Promise.resolve(groups),
28
- };
29
- }),
30
- putSubscriptionFilter: jest.fn().mockImplementation(() => ({ promise: () => Promise.resolve() })),
31
- });
14
+ const fixtures_1 = require("./fixtures");
32
15
  describe('loggroup', () => {
33
16
  describe('calculateLogGroupUpdateRequest', () => {
34
17
  test("creates a new log group when one doesn't exist", () => __awaiter(void 0, void 0, void 0, function* () {
35
- const logs = makeMockCloudWatch({});
18
+ const logs = fixtures_1.makeMockCloudWatchLogs({});
36
19
  const result = yield loggroup_1.calculateLogGroupUpdateRequest(logs, '/aws/lambda/my-func', 'my-forwarder');
37
20
  expect(result).toMatchInlineSnapshot(`
38
21
  Object {
@@ -50,7 +33,7 @@ describe('loggroup', () => {
50
33
  `);
51
34
  }));
52
35
  test("adds a subscription filter when one doesn't exist", () => __awaiter(void 0, void 0, void 0, function* () {
53
- const logs = makeMockCloudWatch({
36
+ const logs = fixtures_1.makeMockCloudWatchLogs({
54
37
  '/aws/lambda/my-func': {
55
38
  config: {
56
39
  logGroups: [{ logGroupName: '/aws/lambda/my-func' }],
@@ -72,7 +55,7 @@ describe('loggroup', () => {
72
55
  `);
73
56
  }));
74
57
  test('updates a subscription filter when an owned one already exists', () => __awaiter(void 0, void 0, void 0, function* () {
75
- const logs = makeMockCloudWatch({
58
+ const logs = fixtures_1.makeMockCloudWatchLogs({
76
59
  '/aws/lambda/my-func': {
77
60
  config: {
78
61
  logGroups: [{ logGroupName: '/aws/lambda/my-func' }],
@@ -81,7 +64,7 @@ describe('loggroup', () => {
81
64
  subscriptionFilters: [
82
65
  {
83
66
  destinationArn: 'wrong-destination',
84
- filterName: 'datadog-ci-filter',
67
+ filterName: constants_1.SUBSCRIPTION_FILTER_NAME,
85
68
  logGroupName: '/aws/lambda/my-func',
86
69
  },
87
70
  ],
@@ -102,7 +85,7 @@ describe('loggroup', () => {
102
85
  `);
103
86
  }));
104
87
  test('throws an exception when an unowned subscription filter exists', () => __awaiter(void 0, void 0, void 0, function* () {
105
- const logs = makeMockCloudWatch({
88
+ const logs = fixtures_1.makeMockCloudWatchLogs({
106
89
  '/aws/lambda/my-func': {
107
90
  config: {
108
91
  logGroups: [{ logGroupName: '/aws/lambda/my-func' }],
@@ -122,7 +105,7 @@ describe('loggroup', () => {
122
105
  yield expect(promise).rejects.toEqual(Error('Unknown subscription filter already on log group /aws/lambda/my-func. Only one subscription is allowed.'));
123
106
  }));
124
107
  test("doesn't update a subscription when filter is already correct", () => __awaiter(void 0, void 0, void 0, function* () {
125
- const logs = makeMockCloudWatch({
108
+ const logs = fixtures_1.makeMockCloudWatchLogs({
126
109
  '/aws/lambda/my-func': {
127
110
  config: {
128
111
  logGroups: [{ logGroupName: '/aws/lambda/my-func' }],
@@ -131,7 +114,7 @@ describe('loggroup', () => {
131
114
  subscriptionFilters: [
132
115
  {
133
116
  destinationArn: 'my-forwarder',
134
- filterName: 'datadog-ci-filter',
117
+ filterName: constants_1.SUBSCRIPTION_FILTER_NAME,
135
118
  logGroupName: '/aws/lambda/my-func',
136
119
  },
137
120
  ],
@@ -142,21 +125,102 @@ describe('loggroup', () => {
142
125
  expect(result).toMatchInlineSnapshot('undefined');
143
126
  }));
144
127
  });
128
+ describe('calculateLogGroupRemoveRequest', () => {
129
+ test('deletes the subscription filter that matches the forwarder', () => __awaiter(void 0, void 0, void 0, function* () {
130
+ const logs = fixtures_1.makeMockCloudWatchLogs({
131
+ '/aws/lambda/my-func': {
132
+ config: {
133
+ logGroups: [{ logGroupName: '/aws/lambda/my-func' }],
134
+ },
135
+ filters: {
136
+ subscriptionFilters: [
137
+ {
138
+ destinationArn: 'my-forwarder',
139
+ filterName: constants_1.SUBSCRIPTION_FILTER_NAME,
140
+ logGroupName: '/aws/lambda/my-func',
141
+ },
142
+ ],
143
+ },
144
+ },
145
+ });
146
+ const result = yield loggroup_1.calculateLogGroupRemoveRequest(logs, '/aws/lambda/my-func', 'my-forwarder');
147
+ expect(result.deleteSubscriptionFilterRequest).toMatchInlineSnapshot(`
148
+ Object {
149
+ "filterName": "datadog-ci-filter",
150
+ "logGroupName": "/aws/lambda/my-func",
151
+ }
152
+ `);
153
+ }));
154
+ test('deletes the subscription filter that matches the datadog subscription filter constant name', () => __awaiter(void 0, void 0, void 0, function* () {
155
+ const logs = fixtures_1.makeMockCloudWatchLogs({
156
+ '/aws/lambda/my-func': {
157
+ config: {
158
+ logGroups: [{ logGroupName: '/aws/lambda/my-func' }],
159
+ },
160
+ filters: {
161
+ subscriptionFilters: [
162
+ {
163
+ destinationArn: 'wrong-destination',
164
+ filterName: constants_1.SUBSCRIPTION_FILTER_NAME,
165
+ logGroupName: '/aws/lambda/my-func',
166
+ },
167
+ ],
168
+ },
169
+ },
170
+ });
171
+ const result = yield loggroup_1.calculateLogGroupRemoveRequest(logs, '/aws/lambda/my-func', 'my-forwarder');
172
+ expect(result.deleteSubscriptionFilterRequest).toMatchInlineSnapshot(`
173
+ Object {
174
+ "filterName": "datadog-ci-filter",
175
+ "logGroupName": "/aws/lambda/my-func",
176
+ }
177
+ `);
178
+ }));
179
+ test('returns log group configuration without delete request when forwarder and filter name does not match', () => __awaiter(void 0, void 0, void 0, function* () {
180
+ const logs = fixtures_1.makeMockCloudWatchLogs({
181
+ '/aws/lambda/my-func': {
182
+ config: {
183
+ logGroups: [{ logGroupName: '/aws/lambda/my-func' }],
184
+ },
185
+ filters: {
186
+ subscriptionFilters: [
187
+ {
188
+ destinationArn: 'some-destination',
189
+ filterName: 'not-datadog',
190
+ logGroupName: '/aws/lambda/my-func',
191
+ },
192
+ {
193
+ destinationArn: 'some-other-destination',
194
+ filterName: 'not-datadog-either',
195
+ logGroupName: '/aws/lambda/my-func',
196
+ },
197
+ ],
198
+ },
199
+ },
200
+ });
201
+ const result = yield loggroup_1.calculateLogGroupRemoveRequest(logs, '/aws/lambda/my-func', 'my-forwarder');
202
+ expect(result).toMatchInlineSnapshot(`
203
+ Object {
204
+ "logGroupName": "/aws/lambda/my-func",
205
+ }
206
+ `);
207
+ }));
208
+ });
145
209
  describe('applyLogGroupConfiguration', () => {
146
210
  test('applies specified changes', () => __awaiter(void 0, void 0, void 0, function* () {
147
- const logs = makeMockCloudWatch({});
211
+ const logs = fixtures_1.makeMockCloudWatchLogs({});
148
212
  const config = {
149
213
  createLogGroupRequest: {
150
214
  logGroupName: '/aws/lambda/my-func',
151
215
  },
152
216
  deleteSubscriptionFilterRequest: {
153
- filterName: 'datadog-ci-filter',
217
+ filterName: constants_1.SUBSCRIPTION_FILTER_NAME,
154
218
  logGroupName: '/aws/lambda/my-func',
155
219
  },
156
220
  logGroupName: '/aws/lambda/my-func',
157
221
  subscriptionFilterRequest: {
158
222
  destinationArn: 'my-forwarder',
159
- filterName: 'datadog-ci-filter',
223
+ filterName: constants_1.SUBSCRIPTION_FILTER_NAME,
160
224
  filterPattern: '',
161
225
  logGroupName: '/aws/lambda/my-func',
162
226
  },
@@ -166,23 +230,23 @@ describe('loggroup', () => {
166
230
  logGroupName: '/aws/lambda/my-func',
167
231
  });
168
232
  expect(logs.deleteSubscriptionFilter).toHaveBeenCalledWith({
169
- filterName: 'datadog-ci-filter',
233
+ filterName: constants_1.SUBSCRIPTION_FILTER_NAME,
170
234
  logGroupName: '/aws/lambda/my-func',
171
235
  });
172
236
  expect(logs.putSubscriptionFilter).toHaveBeenCalledWith({
173
237
  destinationArn: 'my-forwarder',
174
- filterName: 'datadog-ci-filter',
238
+ filterName: constants_1.SUBSCRIPTION_FILTER_NAME,
175
239
  filterPattern: '',
176
240
  logGroupName: '/aws/lambda/my-func',
177
241
  });
178
242
  }));
179
243
  test("doesn't apply unspecified changes", () => __awaiter(void 0, void 0, void 0, function* () {
180
- const logs = makeMockCloudWatch({});
244
+ const logs = fixtures_1.makeMockCloudWatchLogs({});
181
245
  const config = {
182
246
  logGroupName: '/aws/lambda/my-func',
183
247
  subscriptionFilterRequest: {
184
248
  destinationArn: 'my-forwarder',
185
- filterName: 'datadog-ci-filter',
249
+ filterName: constants_1.SUBSCRIPTION_FILTER_NAME,
186
250
  filterPattern: '',
187
251
  logGroupName: '/aws/lambda/my-func',
188
252
  },
@@ -192,7 +256,7 @@ describe('loggroup', () => {
192
256
  expect(logs.deleteSubscriptionFilter).not.toHaveBeenCalled();
193
257
  expect(logs.putSubscriptionFilter).toHaveBeenCalledWith({
194
258
  destinationArn: 'my-forwarder',
195
- filterName: 'datadog-ci-filter',
259
+ filterName: constants_1.SUBSCRIPTION_FILTER_NAME,
196
260
  filterPattern: '',
197
261
  logGroupName: '/aws/lambda/my-func',
198
262
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -14,11 +14,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  jest.mock('../loggroup');
16
16
  const path_1 = __importDefault(require("path"));
17
+ const constants_1 = require("../constants");
17
18
  const tags_1 = require("../tags");
18
19
  // tslint:disable-next-line
19
20
  const { version } = require(path_1.default.join(__dirname, '../../../../package.json'));
20
- const makeMockLambda = (functionConfigs) => ({
21
- listTags: jest.fn().mockImplementation(() => ({ promise: () => Promise.resolve({ Tags: {} }) })),
21
+ const makeMockLambda = (functions) => ({
22
+ listTags: jest.fn().mockImplementation(({ Resource }) => {
23
+ var _a, _b;
24
+ const tags = (_b = (_a = functions[Resource]) === null || _a === void 0 ? void 0 : _a.tagsResponse) !== null && _b !== void 0 ? _b : { Tags: {} };
25
+ return {
26
+ promise: () => Promise.resolve(tags),
27
+ };
28
+ }),
22
29
  tagResource: jest.fn().mockImplementation(() => ({ promise: () => Promise.resolve() })),
23
30
  });
24
31
  const VERSION_REGEX = /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$/;
@@ -27,9 +34,11 @@ describe('tags', () => {
27
34
  test('Calls tagResource with config data', () => __awaiter(void 0, void 0, void 0, function* () {
28
35
  const lambda = makeMockLambda({
29
36
  'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument': {
30
- FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
31
- Handler: 'index.handler',
32
- Runtime: 'nodejs12.x',
37
+ config: {
38
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
39
+ Handler: 'index.handler',
40
+ Runtime: 'nodejs12.x',
41
+ },
33
42
  },
34
43
  });
35
44
  const config = {
@@ -47,9 +56,11 @@ describe('tags', () => {
47
56
  test('Handles undefined config', () => __awaiter(void 0, void 0, void 0, function* () {
48
57
  const lambda = makeMockLambda({
49
58
  'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument': {
50
- FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
51
- Handler: 'index.handler',
52
- Runtime: 'nodejs12.x',
59
+ config: {
60
+ FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
61
+ Handler: 'index.handler',
62
+ Runtime: 'nodejs12.x',
63
+ },
53
64
  },
54
65
  });
55
66
  const config = {
@@ -65,9 +76,11 @@ describe('tags', () => {
65
76
  const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument';
66
77
  const lambda = makeMockLambda({
67
78
  'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument': {
68
- FunctionArn: functionARN,
69
- Handler: 'index.handler',
70
- Runtime: 'nodejs12.x',
79
+ config: {
80
+ FunctionArn: functionARN,
81
+ Handler: 'index.handler',
82
+ Runtime: 'nodejs12.x',
83
+ },
71
84
  },
72
85
  });
73
86
  const result = yield tags_1.calculateTagUpdateRequest(lambda, functionARN);
@@ -85,9 +98,11 @@ describe('tags', () => {
85
98
  const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument';
86
99
  const lambda = makeMockLambda({
87
100
  'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument': {
88
- FunctionArn: functionARN,
89
- Handler: 'index.handler',
90
- Runtime: 'nodejs12.x',
101
+ config: {
102
+ FunctionArn: functionARN,
103
+ Handler: 'index.handler',
104
+ Runtime: 'nodejs12.x',
105
+ },
91
106
  },
92
107
  });
93
108
  lambda.listTags.mockImplementation(() => ({ promise: () => Promise.resolve({ Tags: { dd_sls_ci: 'v0.0.0' } }) }));
@@ -106,9 +121,11 @@ describe('tags', () => {
106
121
  const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument';
107
122
  const lambda = makeMockLambda({
108
123
  'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument': {
109
- FunctionArn: functionARN,
110
- Handler: 'index.handler',
111
- Runtime: 'nodejs12.x',
124
+ config: {
125
+ FunctionArn: functionARN,
126
+ Handler: 'index.handler',
127
+ Runtime: 'nodejs12.x',
128
+ },
112
129
  },
113
130
  });
114
131
  lambda.listTags.mockImplementation(() => ({ promise: () => Promise.resolve({ Tags: { dd_sls_ci: `v${version}` } }) }));
@@ -117,14 +134,63 @@ describe('tags', () => {
117
134
  expect(lambda.listTags).toHaveBeenCalledWith({ Resource: functionARN });
118
135
  }));
119
136
  });
137
+ describe('calculateTagRemoveRequest', () => {
138
+ test('returns untag resource configuration with the keys to delete', () => __awaiter(void 0, void 0, void 0, function* () {
139
+ const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument';
140
+ const lambda = makeMockLambda({
141
+ 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument': {
142
+ config: {
143
+ FunctionArn: functionARN,
144
+ Handler: 'index.handler',
145
+ Runtime: 'nodejs12.x',
146
+ },
147
+ tagsResponse: {
148
+ Tags: { dd_sls_ci: `v${version}` },
149
+ },
150
+ },
151
+ });
152
+ const result = yield tags_1.calculateTagRemoveRequest(lambda, functionARN);
153
+ expect(result).toMatchInlineSnapshot(`
154
+ Object {
155
+ "untagResourceRequest": Object {
156
+ "Resource": "${functionARN}",
157
+ "TagKeys": Array [
158
+ "${constants_1.TAG_VERSION_NAME}",
159
+ ],
160
+ },
161
+ }
162
+ `);
163
+ expect(lambda.listTags).toHaveBeenCalledWith({ Resource: functionARN });
164
+ }));
165
+ test('returns undefined when no tags need to be removed', () => __awaiter(void 0, void 0, void 0, function* () {
166
+ const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument';
167
+ const lambda = makeMockLambda({
168
+ 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument': {
169
+ config: {
170
+ FunctionArn: functionARN,
171
+ Handler: 'index.handler',
172
+ Runtime: 'nodejs12.x',
173
+ },
174
+ tagsResponse: {
175
+ Tags: { not_datadog: 'some-tag' },
176
+ },
177
+ },
178
+ });
179
+ const result = yield tags_1.calculateTagRemoveRequest(lambda, functionARN);
180
+ expect(result).toBeUndefined();
181
+ expect(lambda.listTags).toHaveBeenCalledWith({ Resource: functionARN });
182
+ }));
183
+ });
120
184
  describe('hasVersionTag', () => {
121
185
  test('handles no tags', () => __awaiter(void 0, void 0, void 0, function* () {
122
186
  const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument';
123
187
  const lambda = makeMockLambda({
124
188
  'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument': {
125
- FunctionArn: functionARN,
126
- Handler: 'index.handler',
127
- Runtime: 'nodejs12.x',
189
+ config: {
190
+ FunctionArn: functionARN,
191
+ Handler: 'index.handler',
192
+ Runtime: 'nodejs12.x',
193
+ },
128
194
  },
129
195
  });
130
196
  const result = yield tags_1.hasVersionTag(lambda, functionARN);
@@ -135,9 +201,11 @@ describe('tags', () => {
135
201
  const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument';
136
202
  const lambda = makeMockLambda({
137
203
  'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument': {
138
- FunctionArn: functionARN,
139
- Handler: 'index.handler',
140
- Runtime: 'nodejs12.x',
204
+ config: {
205
+ FunctionArn: functionARN,
206
+ Handler: 'index.handler',
207
+ Runtime: 'nodejs12.x',
208
+ },
141
209
  },
142
210
  });
143
211
  lambda.listTags.mockImplementation(() => ({ promise: () => Promise.resolve({ Tags: { foo: 'bar' } }) }));
@@ -149,12 +217,16 @@ describe('tags', () => {
149
217
  const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument';
150
218
  const lambda = makeMockLambda({
151
219
  'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument': {
152
- FunctionArn: functionARN,
153
- Handler: 'index.handler',
154
- Runtime: 'nodejs12.x',
220
+ config: {
221
+ FunctionArn: functionARN,
222
+ Handler: 'index.handler',
223
+ Runtime: 'nodejs12.x',
224
+ },
225
+ tagsResponse: {
226
+ Tags: { dd_sls_ci: 'v0.0.0' },
227
+ },
155
228
  },
156
229
  });
157
- lambda.listTags.mockImplementation(() => ({ promise: () => Promise.resolve({ Tags: { dd_sls_ci: 'v0.0.0' } }) }));
158
230
  const result = yield tags_1.hasVersionTag(lambda, functionARN);
159
231
  expect(result).toBe(false);
160
232
  expect(lambda.listTags).toHaveBeenCalledWith({ Resource: functionARN });
@@ -163,12 +235,16 @@ describe('tags', () => {
163
235
  const functionARN = 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument';
164
236
  const lambda = makeMockLambda({
165
237
  'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument': {
166
- FunctionArn: functionARN,
167
- Handler: 'index.handler',
168
- Runtime: 'nodejs12.x',
238
+ config: {
239
+ FunctionArn: functionARN,
240
+ Handler: 'index.handler',
241
+ Runtime: 'nodejs12.x',
242
+ },
243
+ tagsResponse: {
244
+ Tags: { dd_sls_ci: `v${version}` },
245
+ },
169
246
  },
170
247
  });
171
- lambda.listTags.mockImplementation(() => ({ promise: () => Promise.resolve({ Tags: { dd_sls_ci: `v${version}` } }) }));
172
248
  const result = yield tags_1.hasVersionTag(lambda, functionARN);
173
249
  expect(result).toBe(true);
174
250
  expect(lambda.listTags).toHaveBeenCalledWith({ Resource: functionARN });