@datadog/datadog-ci 0.17.12 → 0.17.13

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 (43) hide show
  1. package/README.md +6 -1
  2. package/dist/commands/junit/upload.js +1 -1
  3. package/dist/commands/lambda/__tests__/fixtures.d.ts +5 -1
  4. package/dist/commands/lambda/__tests__/fixtures.js +13 -2
  5. package/dist/commands/lambda/__tests__/functions/commons.test.js +221 -0
  6. package/dist/commands/lambda/__tests__/functions/instrument.test.js +64 -42
  7. package/dist/commands/lambda/__tests__/instrument.test.js +425 -4
  8. package/dist/commands/lambda/__tests__/prompt.test.d.ts +1 -0
  9. package/dist/commands/lambda/__tests__/prompt.test.js +216 -0
  10. package/dist/commands/lambda/__tests__/uninstrument.test.js +310 -4
  11. package/dist/commands/lambda/constants.d.ts +10 -0
  12. package/dist/commands/lambda/constants.js +36 -2
  13. package/dist/commands/lambda/functions/commons.d.ts +15 -0
  14. package/dist/commands/lambda/functions/commons.js +105 -2
  15. package/dist/commands/lambda/functions/instrument.d.ts +1 -1
  16. package/dist/commands/lambda/functions/instrument.js +17 -7
  17. package/dist/commands/lambda/functions/uninstrument.js +1 -0
  18. package/dist/commands/lambda/instrument.d.ts +2 -0
  19. package/dist/commands/lambda/instrument.js +100 -47
  20. package/dist/commands/lambda/interfaces.d.ts +4 -0
  21. package/dist/commands/lambda/prompt.d.ts +9 -0
  22. package/dist/commands/lambda/prompt.js +187 -0
  23. package/dist/commands/lambda/uninstrument.d.ts +1 -0
  24. package/dist/commands/lambda/uninstrument.js +68 -30
  25. package/dist/commands/synthetics/__tests__/cli.test.js +1 -0
  26. package/dist/commands/synthetics/__tests__/fixtures.js +1 -0
  27. package/dist/commands/synthetics/__tests__/run-test.test.js +48 -2
  28. package/dist/commands/synthetics/__tests__/utils.test.js +11 -0
  29. package/dist/commands/synthetics/command.d.ts +1 -0
  30. package/dist/commands/synthetics/command.js +11 -5
  31. package/dist/commands/synthetics/interfaces.d.ts +8 -3
  32. package/dist/commands/synthetics/interfaces.js +7 -3
  33. package/dist/commands/synthetics/reporters/default.js +5 -1
  34. package/dist/commands/synthetics/run-test.js +3 -1
  35. package/dist/commands/synthetics/utils.d.ts +3 -0
  36. package/dist/commands/synthetics/utils.js +20 -1
  37. package/dist/commands/trace/api.js +1 -1
  38. package/dist/helpers/__tests__/ci.test.js +71 -24
  39. package/dist/helpers/__tests__/user-provided-git.test.js +69 -27
  40. package/dist/helpers/ci.js +1 -1
  41. package/dist/helpers/user-provided-git.d.ts +2 -1
  42. package/dist/helpers/user-provided-git.js +18 -3
  43. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![Continuous Integration](https://github.com/DataDog/datadog-ci/workflows/Continuous%20Integration/badge.svg) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) ![NodeJS Version](https://img.shields.io/badge/Node.js-10.24.1+-green)
4
4
 
5
- Execute commands with Datadog from within your Continuous Integration/Continuous Deployment scripts. A good way to perform end to end tests of your application before applying you changes or deploying. It currently features running synthetics tests and waiting for the results.
5
+ Execute commands with Datadog from within your Continuous Integration/Continuous Deployment scripts. A good way to perform end to end tests of your application before applying your changes or deploying. It currently features running synthetics tests and waiting for the results.
6
6
 
7
7
  ## How to install the CLI
8
8
 
@@ -28,6 +28,7 @@ npm install -g @datadog/datadog-ci
28
28
  # Yarn v1 add globally
29
29
  yarn global add @datadog/datadog-ci
30
30
  ```
31
+
31
32
  ## Usage
32
33
 
33
34
  ```bash
@@ -40,6 +41,8 @@ Available commands:
40
41
  - synthetics
41
42
  - dsyms
42
43
  - git-metadata
44
+ - junit
45
+ - trace
43
46
  ```
44
47
 
45
48
  Each command allows interacting with a product of the Datadog platform. The commands are defined in the [src/commands](/src/commands) folder.
@@ -52,6 +55,8 @@ Further documentation for each command can be found in its folder, ie:
52
55
  - [Synthetics CI/CD Testing](src/commands/synthetics/)
53
56
  - [iOS dSYM Files](src/commands/dsyms/)
54
57
  - [Git metadata](src/commands/git-metadata)
58
+ - [JUnit XML](src/commands/junit)
59
+ - [Trace](src/commands/trace)
55
60
 
56
61
  ## Contributing
57
62
 
@@ -100,7 +100,7 @@ class UploadJUnitXMLCommand extends clipanion_1.Command {
100
100
  }, []);
101
101
  const ciSpanTags = ci_1.getCISpanTags();
102
102
  const gitSpanTags = yield git_1.getGitMetadata();
103
- const userGitSpanTags = user_provided_git_1.getUserGitMetadata();
103
+ const userGitSpanTags = user_provided_git_1.getUserGitSpanTags();
104
104
  const envVarTags = this.config.envVarTags ? tags_1.parseTags(this.config.envVarTags.split(',')) : {};
105
105
  const cliTags = this.tags ? tags_1.parseTags(this.tags) : {};
106
106
  const spanTags = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, gitSpanTags), ciSpanTags), userGitSpanTags), cliTags), envVarTags), (this.config.env ? { env: this.config.env } : {}));
@@ -22,8 +22,9 @@ export declare type ConstructorOf<T> = new (...args: any[]) => T;
22
22
  * @returns the instance of the given command with a mock context attatched.
23
23
  */
24
24
  export declare const createCommand: <T extends Command<import("clipanion/lib/advanced").BaseContext>>(commandClass: ConstructorOf<T>, ...parameters: any[]) => T;
25
- export declare const makeMockLambda: (functionConfigs: Record<string, Lambda.FunctionConfiguration>) => {
25
+ export declare const makeMockLambda: (functionConfigs: Record<string, Lambda.FunctionConfiguration>, layers?: Record<string, Lambda.LayerVersionsListItem> | undefined) => {
26
26
  getFunction: jest.Mock<any, any>;
27
+ getLayerVersion: jest.Mock<any, any>;
27
28
  listFunctions: jest.Mock<any, any>;
28
29
  listTags: jest.Mock<any, any>;
29
30
  tagResource: jest.Mock<any, any>;
@@ -40,3 +41,6 @@ export declare const makeMockCloudWatchLogs: (logGroups: Record<string, {
40
41
  putSubscriptionFilter: jest.Mock<any, any>;
41
42
  };
42
43
  export declare const mockAwsAccount = "123456789012";
44
+ export declare const mockAwsAccessKeyId = "M0CKAWS4CC3SSK3Y1DSL";
45
+ export declare const mockAwsSecretAccessKey = "M0CKAWSs3cR3T4cC3SSK3YS3rv3rL3SSD4tad0g0";
46
+ export declare const mockDatadogApiKey = "02aeb762fff59ac0d5ad1536cd9633bd";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mockAwsAccount = exports.makeMockCloudWatchLogs = exports.makeMockLambda = exports.createCommand = exports.makeCli = exports.createMockContext = void 0;
3
+ exports.mockDatadogApiKey = exports.mockAwsSecretAccessKey = exports.mockAwsAccessKeyId = exports.mockAwsAccount = exports.makeMockCloudWatchLogs = exports.makeMockLambda = exports.createCommand = exports.makeCli = exports.createMockContext = void 0;
4
4
  const advanced_1 = require("clipanion/lib/advanced");
5
5
  const instrument_1 = require("../instrument");
6
6
  const uninstrument_1 = require("../uninstrument");
@@ -38,10 +38,18 @@ const createCommand = (commandClass, ...parameters) => {
38
38
  return command;
39
39
  };
40
40
  exports.createCommand = createCommand;
41
- const makeMockLambda = (functionConfigs) => ({
41
+ const makeMockLambda = (functionConfigs, layers) => ({
42
42
  getFunction: jest.fn().mockImplementation(({ FunctionName }) => ({
43
43
  promise: () => Promise.resolve({ Configuration: functionConfigs[FunctionName] }),
44
44
  })),
45
+ getLayerVersion: jest.fn().mockImplementation(({ LayerName, VersionNumber }) => ({
46
+ promise: () => {
47
+ const layer = LayerName + ':' + VersionNumber;
48
+ return layers && layers[layer] && layers[layer].Version === VersionNumber
49
+ ? Promise.resolve(layers[layer])
50
+ : Promise.reject();
51
+ },
52
+ })),
45
53
  listFunctions: jest.fn().mockImplementation(() => ({
46
54
  promise: () => Promise.resolve({ Functions: Object.values(functionConfigs) }),
47
55
  })),
@@ -71,3 +79,6 @@ const makeMockCloudWatchLogs = (logGroups) => ({
71
79
  });
72
80
  exports.makeMockCloudWatchLogs = makeMockCloudWatchLogs;
73
81
  exports.mockAwsAccount = '123456789012';
82
+ exports.mockAwsAccessKeyId = 'M0CKAWS4CC3SSK3Y1DSL';
83
+ exports.mockAwsSecretAccessKey = 'M0CKAWSs3cR3T4cC3SSK3YS3rv3rL3SSD4tad0g0';
84
+ exports.mockDatadogApiKey = '02aeb762fff59ac0d5ad1536cd9633bd';
@@ -10,6 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  /* tslint:disable:no-string-literal */
13
+ jest.mock('aws-sdk');
14
+ const aws_sdk_1 = require("aws-sdk");
13
15
  const constants_1 = require("../../constants");
14
16
  const commons_1 = require("../../functions/commons");
15
17
  const instrument_1 = require("../../instrument");
@@ -144,6 +146,197 @@ describe('commons', () => {
144
146
  expect(functionsGroup).toBeUndefined();
145
147
  });
146
148
  });
149
+ describe('findLatestLayerVersion', () => {
150
+ test('finds latests version for Python39', () => __awaiter(void 0, void 0, void 0, function* () {
151
+ const layer = `arn:aws:lambda:sa-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Python39`;
152
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}, {
153
+ [`${layer}:1`]: {
154
+ LayerVersionArn: `${layer}:1`,
155
+ Version: 1,
156
+ },
157
+ [`${layer}:2`]: {
158
+ LayerVersionArn: `${layer}:2`,
159
+ Version: 2,
160
+ },
161
+ [`${layer}:10`]: {
162
+ LayerVersionArn: `${layer}:10`,
163
+ Version: 10,
164
+ },
165
+ [`${layer}:20`]: {
166
+ LayerVersionArn: `${layer}:20`,
167
+ Version: 20,
168
+ },
169
+ [`${layer}:30`]: {
170
+ LayerVersionArn: `${layer}:30`,
171
+ Version: 30,
172
+ },
173
+ [`${layer}:31`]: {
174
+ LayerVersionArn: `${layer}:31`,
175
+ Version: 31,
176
+ },
177
+ [`${layer}:32`]: {
178
+ LayerVersionArn: `${layer}:32`,
179
+ Version: 32,
180
+ },
181
+ }));
182
+ const runtime = 'python3.9';
183
+ const region = 'sa-east-1';
184
+ const expectedLatestVersion = 32;
185
+ const latestVersionFound = yield commons_1.findLatestLayerVersion(runtime, region);
186
+ expect(latestVersionFound).toBe(expectedLatestVersion);
187
+ }));
188
+ test('finds latests version for Node14', () => __awaiter(void 0, void 0, void 0, function* () {
189
+ const layer = `arn:aws:lambda:us-east-1:${constants_1.DEFAULT_LAYER_AWS_ACCOUNT}:layer:Datadog-Node14-x`;
190
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}, {
191
+ [`${layer}:1`]: {
192
+ LayerVersionArn: `${layer}:1`,
193
+ Version: 1,
194
+ },
195
+ [`${layer}:10`]: {
196
+ LayerVersionArn: `${layer}:10`,
197
+ Version: 10,
198
+ },
199
+ [`${layer}:20`]: {
200
+ LayerVersionArn: `${layer}:20`,
201
+ Version: 20,
202
+ },
203
+ [`${layer}:30`]: {
204
+ LayerVersionArn: `${layer}:30`,
205
+ Version: 30,
206
+ },
207
+ [`${layer}:40`]: {
208
+ LayerVersionArn: `${layer}:40`,
209
+ Version: 40,
210
+ },
211
+ [`${layer}:41`]: {
212
+ LayerVersionArn: `${layer}:41`,
213
+ Version: 41,
214
+ },
215
+ }));
216
+ const runtime = 'nodejs14.x';
217
+ const region = 'us-east-1';
218
+ const expectedLatestVersion = 41;
219
+ const latestVersionFound = yield commons_1.findLatestLayerVersion(runtime, region);
220
+ expect(latestVersionFound).toBe(expectedLatestVersion);
221
+ }));
222
+ test('returns 0 when no layer can be found', () => __awaiter(void 0, void 0, void 0, function* () {
223
+ ;
224
+ aws_sdk_1.Lambda.mockImplementation(() => fixtures_1.makeMockLambda({}, {}));
225
+ const runtime = 'python3.7';
226
+ const region = 'us-east-1';
227
+ const expectedLatestVersion = 0;
228
+ const latestVersionFound = yield commons_1.findLatestLayerVersion(runtime, region);
229
+ expect(latestVersionFound).toBe(expectedLatestVersion);
230
+ }));
231
+ });
232
+ describe('isMissingAWSCredentials', () => {
233
+ const OLD_ENV = process.env;
234
+ beforeEach(() => {
235
+ jest.resetModules();
236
+ process.env = {};
237
+ });
238
+ afterAll(() => {
239
+ process.env = OLD_ENV;
240
+ });
241
+ test('returns true when any AWS credential is missing', () => {
242
+ process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = 'SOME-AWS-SECRET-ACCESS-KEY';
243
+ expect(commons_1.isMissingAWSCredentials()).toBe(true);
244
+ // Reset env
245
+ process.env = {};
246
+ process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = 'SOME-AWS-ACCESS-KEY-ID';
247
+ expect(commons_1.isMissingAWSCredentials()).toBe(true);
248
+ });
249
+ test('returns false when AWS credentials are set', () => {
250
+ process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = 'SOME-AWS-ACCESS-KEY-ID';
251
+ process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = 'SOME-AWS-SECRET-ACCESS-KEY';
252
+ expect(commons_1.isMissingAWSCredentials()).toBe(false);
253
+ });
254
+ });
255
+ describe('isMissingDatadogEnvVars', () => {
256
+ const OLD_ENV = process.env;
257
+ beforeEach(() => {
258
+ jest.resetModules();
259
+ process.env = {};
260
+ });
261
+ afterAll(() => {
262
+ process.env = OLD_ENV;
263
+ });
264
+ test('returns true when any Datadog Env Var is missing', () => {
265
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
266
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(true);
267
+ // Reset env
268
+ process.env = {};
269
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = 'SOME-DATADOG-API-KEY';
270
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(true);
271
+ process.env = {};
272
+ process.env[constants_1.CI_KMS_API_KEY_ENV_VAR] = 'SOME-AWS-KMS-API-KEY-CONTAINING-DATADOG-API-KEY';
273
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(true);
274
+ process.env = {};
275
+ process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'SOME-AWS-SECRET-ARN-CONTAINING-DATADOG-API-KEY';
276
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(true);
277
+ });
278
+ test('returns false when Datadog Env Vars are set with DATADOG_API_KEY', () => {
279
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = 'SOME-DATADOG-API-KEY';
280
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
281
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(false);
282
+ });
283
+ test('returns false when Datadog Env Vars are set with DATADOG_KMS_API_KEY', () => {
284
+ process.env[constants_1.CI_KMS_API_KEY_ENV_VAR] = 'SOME-AWS-KMS-API-KEY-CONTAINING-DATADOG-API-KEY';
285
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
286
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(false);
287
+ });
288
+ test('returns false when Datadog Env Vars are set with DATADOG_API_KEY_SECRET_ARN', () => {
289
+ process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'SOME-AWS-SECRET-ARN-CONTAINING-DATADOG-API-KEY';
290
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
291
+ expect(commons_1.isMissingDatadogEnvVars()).toBe(false);
292
+ });
293
+ });
294
+ describe('isMissingDatadogSiteEnvVar', () => {
295
+ const OLD_ENV = process.env;
296
+ beforeEach(() => {
297
+ jest.resetModules();
298
+ process.env = {};
299
+ });
300
+ afterAll(() => {
301
+ process.env = OLD_ENV;
302
+ });
303
+ test('returns true when Datadog Site Env Var is missing', () => {
304
+ expect(commons_1.isMissingDatadogSiteEnvVar()).toBe(true);
305
+ });
306
+ test('returns false when Datadog Site Env Var is set', () => {
307
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
308
+ expect(commons_1.isMissingDatadogSiteEnvVar()).toBe(false);
309
+ });
310
+ test('returns true when Datadog Site Env Var is set and is not a valid Datadog site', () => {
311
+ process.env[constants_1.CI_SITE_ENV_VAR] = 'datacathq.com';
312
+ expect(commons_1.isMissingDatadogSiteEnvVar()).toBe(true);
313
+ });
314
+ });
315
+ describe('isMissingAnyDatadogApiKeyEnvVar', () => {
316
+ const OLD_ENV = process.env;
317
+ beforeEach(() => {
318
+ jest.resetModules();
319
+ process.env = {};
320
+ });
321
+ afterAll(() => {
322
+ process.env = OLD_ENV;
323
+ });
324
+ test('returns true when no Datadog Api Key is set', () => {
325
+ expect(commons_1.isMissingAnyDatadogApiKeyEnvVar()).toBe(true);
326
+ });
327
+ test('returns false when DATADOG_API_KEY is set', () => {
328
+ process.env[constants_1.CI_API_KEY_ENV_VAR] = 'SOME-DATADOG-API-KEY';
329
+ expect(commons_1.isMissingAnyDatadogApiKeyEnvVar()).toBe(false);
330
+ });
331
+ test('returns false when DATADOG_KMS_API_KEY is set', () => {
332
+ process.env[constants_1.CI_KMS_API_KEY_ENV_VAR] = 'SOME-AWS-KMS-API-KEY-CONTAINING-DATADOG-API-KEY';
333
+ expect(commons_1.isMissingAnyDatadogApiKeyEnvVar()).toBe(false);
334
+ });
335
+ test('returns false when DATADOG_API_KEY_SECRET_ARN is set', () => {
336
+ process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'SOME-AWS-SECRET-ARN-CONTAINING-DATADOG-API-KEY';
337
+ expect(commons_1.isMissingAnyDatadogApiKeyEnvVar()).toBe(false);
338
+ });
339
+ });
147
340
  describe('getLayerArn', () => {
148
341
  const OLD_ENV = process.env;
149
342
  beforeEach(() => {
@@ -266,6 +459,34 @@ describe('commons', () => {
266
459
  expect(layerArn).toEqual(`arn:aws-us-gov:lambda:${region}:${constants_1.GOVCLOUD_LAYER_AWS_ACCOUNT}:layer:Datadog-Python39-ARM`);
267
460
  }));
268
461
  });
462
+ describe('getLayerNameWithVersion', () => {
463
+ const OLD_ENV = process.env;
464
+ beforeEach(() => {
465
+ jest.resetModules();
466
+ process.env = {};
467
+ });
468
+ afterAll(() => {
469
+ process.env = OLD_ENV;
470
+ });
471
+ test('returns the correct name and version given an extension layer arn', () => {
472
+ const layerName = constants_1.DD_LAMBDA_EXTENSION_LAYER_NAME;
473
+ const version = '16';
474
+ const layerNameWithVersion = `${layerName}:${version}`;
475
+ const layerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:${layerNameWithVersion}`;
476
+ expect(commons_1.getLayerNameWithVersion(layerArn)).toBe(layerNameWithVersion);
477
+ });
478
+ test('returns the correct name and version given a library layer arn', () => {
479
+ const layerName = 'Datadog-Python39';
480
+ const version = '59';
481
+ const layerNameWithVersion = `${layerName}:${version}`;
482
+ const layerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:${layerNameWithVersion}`;
483
+ expect(commons_1.getLayerNameWithVersion(layerArn)).toBe(layerNameWithVersion);
484
+ });
485
+ test('returns undefined if arn is incomplete', () => {
486
+ const layerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Python39`;
487
+ expect(commons_1.getLayerNameWithVersion(layerArn)).toBe(undefined);
488
+ });
489
+ });
269
490
  describe('getRegion', () => {
270
491
  test('should return the expected region', () => {
271
492
  const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
@@ -43,7 +43,7 @@ describe('instrument', () => {
43
43
  afterAll(() => {
44
44
  process.env = OLD_ENV;
45
45
  });
46
- test('calculates an update request with just lambda library layers', () => {
46
+ test('calculates an update request with just lambda library layers', () => __awaiter(void 0, void 0, void 0, function* () {
47
47
  const runtime = 'nodejs12.x';
48
48
  const config = {
49
49
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
@@ -59,7 +59,7 @@ describe('instrument', () => {
59
59
  tracingEnabled: false,
60
60
  };
61
61
  const region = 'sa-east-1';
62
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
62
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
63
63
  expect(updateRequest).toMatchInlineSnapshot(`
64
64
  Object {
65
65
  "Environment": Object {
@@ -78,8 +78,8 @@ describe('instrument', () => {
78
78
  ],
79
79
  }
80
80
  `);
81
- });
82
- test('calculates an update request with just lambda library layers in arm architecture', () => {
81
+ }));
82
+ test('calculates an update request with just lambda library layers in arm architecture', () => __awaiter(void 0, void 0, void 0, function* () {
83
83
  const runtime = 'python3.9';
84
84
  const config = {
85
85
  Architectures: ['arm64'],
@@ -96,7 +96,7 @@ describe('instrument', () => {
96
96
  tracingEnabled: false,
97
97
  };
98
98
  const region = 'sa-east-1';
99
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
99
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
100
100
  expect(updateRequest).toMatchInlineSnapshot(`
101
101
  Object {
102
102
  "Environment": Object {
@@ -115,8 +115,8 @@ describe('instrument', () => {
115
115
  ],
116
116
  }
117
117
  `);
118
- });
119
- test('calculates an update request with a lambda library, extension, and DATADOG_API_KEY', () => {
118
+ }));
119
+ test('calculates an update request with a lambda library, extension, and DATADOG_API_KEY', () => __awaiter(void 0, void 0, void 0, function* () {
120
120
  process.env[constants_1.CI_API_KEY_ENV_VAR] = '1234';
121
121
  const runtime = 'nodejs12.x';
122
122
  const config = {
@@ -134,7 +134,7 @@ describe('instrument', () => {
134
134
  tracingEnabled: false,
135
135
  };
136
136
  const region = 'sa-east-1';
137
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
137
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
138
138
  expect(updateRequest).toMatchInlineSnapshot(`
139
139
  Object {
140
140
  "Environment": Object {
@@ -154,8 +154,8 @@ describe('instrument', () => {
154
154
  ],
155
155
  }
156
156
  `);
157
- });
158
- test('calculates an update request with a lambda library, extension, and DATADOG_API_KEY_SECRET_ARN', () => {
157
+ }));
158
+ test('calculates an update request with a lambda library, extension, and DATADOG_API_KEY_SECRET_ARN', () => __awaiter(void 0, void 0, void 0, function* () {
159
159
  process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'some-secret:arn:from:aws';
160
160
  const runtime = 'python3.9';
161
161
  const config = {
@@ -173,7 +173,7 @@ describe('instrument', () => {
173
173
  tracingEnabled: false,
174
174
  };
175
175
  const region = 'sa-east-1';
176
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
176
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
177
177
  expect(updateRequest).toMatchInlineSnapshot(`
178
178
  Object {
179
179
  "Environment": Object {
@@ -193,8 +193,8 @@ describe('instrument', () => {
193
193
  ],
194
194
  }
195
195
  `);
196
- });
197
- test('calculates an update request with a lambda library, extension, and DATADOG_KMS_API_KEY', () => {
196
+ }));
197
+ test('calculates an update request with a lambda library, extension, and DATADOG_KMS_API_KEY', () => __awaiter(void 0, void 0, void 0, function* () {
198
198
  process.env[constants_1.CI_KMS_API_KEY_ENV_VAR] = '5678';
199
199
  const runtime = 'python3.6';
200
200
  const config = {
@@ -212,7 +212,7 @@ describe('instrument', () => {
212
212
  tracingEnabled: false,
213
213
  };
214
214
  const region = 'sa-east-1';
215
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
215
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
216
216
  expect(updateRequest).toMatchInlineSnapshot(`
217
217
  Object {
218
218
  "Environment": Object {
@@ -232,8 +232,8 @@ describe('instrument', () => {
232
232
  ],
233
233
  }
234
234
  `);
235
- });
236
- test('prioritizes the KMS API KEY when all of them are exported', () => {
235
+ }));
236
+ test('prioritizes the KMS API KEY when all of them are exported', () => __awaiter(void 0, void 0, void 0, function* () {
237
237
  process.env = {
238
238
  [constants_1.CI_API_KEY_ENV_VAR]: '1234',
239
239
  [constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR]: '5678',
@@ -246,7 +246,7 @@ describe('instrument', () => {
246
246
  };
247
247
  const runtime = 'python3.9';
248
248
  const region = 'sa-east-1';
249
- const updateRequest = instrument_1.calculateUpdateRequest(config, {}, region, runtime);
249
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, {}, region, runtime);
250
250
  expect(updateRequest).toMatchInlineSnapshot(`
251
251
  Object {
252
252
  "Environment": Object {
@@ -260,8 +260,8 @@ describe('instrument', () => {
260
260
  "Handler": "datadog_lambda.handler.handler",
261
261
  }
262
262
  `);
263
- });
264
- test("doesn't set DD_FLUSH_TO_LOGS when extension is being used", () => {
263
+ }));
264
+ test("doesn't set DD_FLUSH_TO_LOGS when extension is being used", () => __awaiter(void 0, void 0, void 0, function* () {
265
265
  process.env[constants_1.CI_API_KEY_ENV_VAR] = '1234';
266
266
  const config = {
267
267
  FunctionArn: 'arn:aws:lambda:sa-east-1:123456789012:function:lambda-hello-world',
@@ -276,7 +276,7 @@ describe('instrument', () => {
276
276
  mergeXrayTraces: false,
277
277
  tracingEnabled: false,
278
278
  };
279
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
279
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
280
280
  expect(updateRequest).toMatchInlineSnapshot(`
281
281
  Object {
282
282
  "Environment": Object {
@@ -295,8 +295,8 @@ describe('instrument', () => {
295
295
  ],
296
296
  }
297
297
  `);
298
- });
299
- test('by default calculates an update request with DATADOG_SITE being set to datadoghq.com', () => {
298
+ }));
299
+ test('by default calculates an update request with DATADOG_SITE being set to datadoghq.com', () => __awaiter(void 0, void 0, void 0, function* () {
300
300
  const runtime = 'python3.6';
301
301
  const config = {
302
302
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
@@ -311,7 +311,7 @@ describe('instrument', () => {
311
311
  tracingEnabled: false,
312
312
  };
313
313
  const region = 'sa-east-1';
314
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
314
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
315
315
  expect(updateRequest).toMatchInlineSnapshot(`
316
316
  Object {
317
317
  "Environment": Object {
@@ -327,8 +327,8 @@ describe('instrument', () => {
327
327
  "Handler": "datadog_lambda.handler.handler",
328
328
  }
329
329
  `);
330
- });
331
- test('calculates an update request with DATADOG_SITE being set to datadoghq.eu', () => {
330
+ }));
331
+ test('calculates an update request with DATADOG_SITE being set to datadoghq.eu', () => __awaiter(void 0, void 0, void 0, function* () {
332
332
  process.env.DATADOG_SITE = 'datadoghq.eu';
333
333
  const config = {
334
334
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
@@ -343,7 +343,7 @@ describe('instrument', () => {
343
343
  };
344
344
  const region = 'sa-east-1';
345
345
  const runtime = 'python3.6';
346
- const updateRequest = instrument_1.calculateUpdateRequest(config, settings, region, runtime);
346
+ const updateRequest = yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
347
347
  expect(updateRequest).toMatchInlineSnapshot(`
348
348
  Object {
349
349
  "Environment": Object {
@@ -359,8 +359,8 @@ describe('instrument', () => {
359
359
  "Handler": "datadog_lambda.handler.handler",
360
360
  }
361
361
  `);
362
- });
363
- test('throws an error when an invalid DATADOG_SITE url is given', () => {
362
+ }));
363
+ test('throws an error when an invalid DATADOG_SITE url is given', () => __awaiter(void 0, void 0, void 0, function* () {
364
364
  process.env.DATADOG_SITE = 'datacathq.eu';
365
365
  const config = {
366
366
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
@@ -369,6 +369,7 @@ describe('instrument', () => {
369
369
  };
370
370
  const settings = {
371
371
  flushMetricsToLogs: false,
372
+ interactive: false,
372
373
  layerAWSAccount: fixtures_1.mockAwsAccount,
373
374
  layerVersion: 5,
374
375
  mergeXrayTraces: false,
@@ -376,11 +377,18 @@ describe('instrument', () => {
376
377
  };
377
378
  const region = 'us-east-1';
378
379
  const runtime = 'python3.6';
379
- expect(() => {
380
- instrument_1.calculateUpdateRequest(config, settings, region, runtime);
381
- }).toThrowError('Warning: Invalid site URL. Must be either datadoghq.com, datadoghq.eu, us3.datadoghq.com, us5.datadoghq.com, or ddog-gov.com.');
382
- });
383
- test('throws an error when neither DATADOG_API_KEY nor DATADOG_KMS_API_KEY are given through the environment while using extensionVersion', () => {
380
+ let error;
381
+ try {
382
+ yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
383
+ }
384
+ catch (e) {
385
+ if (e instanceof Error) {
386
+ error = e;
387
+ }
388
+ }
389
+ expect(error === null || error === void 0 ? void 0 : error.message).toBe('Warning: Invalid site URL. Must be either datadoghq.com, datadoghq.eu, us3.datadoghq.com, us5.datadoghq.com, or ddog-gov.com.');
390
+ }));
391
+ test('throws an error when neither DATADOG_API_KEY nor DATADOG_KMS_API_KEY are given through the environment while using extensionVersion', () => __awaiter(void 0, void 0, void 0, function* () {
384
392
  const config = {
385
393
  FunctionArn: 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
386
394
  Handler: 'index.handler',
@@ -396,11 +404,18 @@ describe('instrument', () => {
396
404
  };
397
405
  const region = 'us-east-1';
398
406
  const runtime = 'python3.6';
399
- expect(() => {
400
- instrument_1.calculateUpdateRequest(config, settings, region, runtime);
401
- }).toThrowError("When 'extensionLayer' is set, DATADOG_API_KEY, DATADOG_KMS_API_KEY, or DATADOG_API_KEY_SECRET_ARN must also be set");
402
- });
403
- test('throws error when trying to add `DD_API_KEY_SECRET_ARN` while using sync metrics in a node runtime', () => {
407
+ let error;
408
+ try {
409
+ yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
410
+ }
411
+ catch (e) {
412
+ if (e instanceof Error) {
413
+ error = e;
414
+ }
415
+ }
416
+ expect(error === null || error === void 0 ? void 0 : error.message).toBe("When 'extensionLayer' is set, DATADOG_API_KEY, DATADOG_KMS_API_KEY, or DATADOG_API_KEY_SECRET_ARN must also be set");
417
+ }));
418
+ test('throws error when trying to add `DD_API_KEY_SECRET_ARN` while using sync metrics in a node runtime', () => __awaiter(void 0, void 0, void 0, function* () {
404
419
  process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'some-secret:arn:from:aws';
405
420
  const runtime = 'nodejs14.x';
406
421
  const region = 'us-east-1';
@@ -417,10 +432,17 @@ describe('instrument', () => {
417
432
  mergeXrayTraces: false,
418
433
  tracingEnabled: false,
419
434
  };
420
- expect(() => {
421
- instrument_1.calculateUpdateRequest(config, settings, region, runtime);
422
- }).toThrowError('`apiKeySecretArn` is not supported for Node runtimes when using Synchronous Metrics. Use either `apiKey` or `apiKmsKey`.');
423
- });
435
+ let error;
436
+ try {
437
+ yield instrument_1.calculateUpdateRequest(config, settings, region, runtime);
438
+ }
439
+ catch (e) {
440
+ if (e instanceof Error) {
441
+ error = e;
442
+ }
443
+ }
444
+ expect(error === null || error === void 0 ? void 0 : error.message).toBe('`apiKeySecretArn` is not supported for Node runtimes when using Synchronous Metrics. Use either `apiKey` or `apiKmsKey`.');
445
+ }));
424
446
  });
425
447
  describe('getInstrumentedFunctionConfig', () => {
426
448
  const OLD_ENV = process.env;