@datadog/datadog-ci 2.4.1 → 2.5.0
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.
- package/dist/commands/dsyms/upload.js +2 -1
- package/dist/commands/dsyms/upload.js.map +1 -1
- package/dist/commands/flutter-symbols/helpers.js +1 -1
- package/dist/commands/flutter-symbols/helpers.js.map +1 -1
- package/dist/commands/flutter-symbols/upload.js +1 -1
- package/dist/commands/flutter-symbols/upload.js.map +1 -1
- package/dist/commands/lambda/instrument.js +1 -1
- package/dist/commands/lambda/instrument.js.map +1 -1
- package/dist/commands/lambda/uninstrument.js +1 -1
- package/dist/commands/lambda/uninstrument.js.map +1 -1
- package/dist/commands/react-native/upload.js +2 -2
- package/dist/commands/react-native/upload.js.map +1 -1
- package/dist/commands/react-native/xcode.js +5 -0
- package/dist/commands/react-native/xcode.js.map +1 -1
- package/dist/commands/synthetics/api.d.ts +2 -1
- package/dist/commands/synthetics/api.js +7 -0
- package/dist/commands/synthetics/api.js.map +1 -1
- package/dist/commands/synthetics/command.js +11 -2
- package/dist/commands/synthetics/command.js.map +1 -1
- package/dist/commands/synthetics/interfaces.d.ts +4 -1
- package/dist/commands/synthetics/reporters/default.d.ts +3 -2
- package/dist/commands/synthetics/reporters/default.js +19 -5
- package/dist/commands/synthetics/reporters/default.js.map +1 -1
- package/dist/commands/synthetics/reporters/junit.d.ts +2 -2
- package/dist/commands/synthetics/reporters/junit.js +1 -1
- package/dist/commands/synthetics/reporters/junit.js.map +1 -1
- package/dist/commands/synthetics/run-test.js +9 -1
- package/dist/commands/synthetics/run-test.js.map +1 -1
- package/dist/commands/synthetics/utils.d.ts +4 -2
- package/dist/commands/synthetics/utils.js +14 -5
- package/dist/commands/synthetics/utils.js.map +1 -1
- package/dist/helpers/utils.d.ts +2 -2
- package/dist/helpers/utils.js +9 -5
- package/dist/helpers/utils.js.map +1 -1
- package/package.json +3 -3
- package/dist/commands/dsyms/__tests__/upload.test.d.ts +0 -1
- package/dist/commands/dsyms/__tests__/upload.test.js +0 -297
- package/dist/commands/dsyms/__tests__/upload.test.js.map +0 -1
- package/dist/commands/dsyms/__tests__/utils.test.d.ts +0 -1
- package/dist/commands/dsyms/__tests__/utils.test.js +0 -99
- package/dist/commands/dsyms/__tests__/utils.test.js.map +0 -1
- package/dist/commands/flutter-symbols/__tests__/upload.test.d.ts +0 -1
- package/dist/commands/flutter-symbols/__tests__/upload.test.js +0 -538
- package/dist/commands/flutter-symbols/__tests__/upload.test.js.map +0 -1
- package/dist/commands/git-metadata/__tests__/git.test.d.ts +0 -1
- package/dist/commands/git-metadata/__tests__/git.test.js +0 -148
- package/dist/commands/git-metadata/__tests__/git.test.js.map +0 -1
- package/dist/commands/git-metadata/__tests__/library.test.d.ts +0 -1
- package/dist/commands/git-metadata/__tests__/library.test.js +0 -103
- package/dist/commands/git-metadata/__tests__/library.test.js.map +0 -1
- package/dist/commands/git-metadata/__tests__/upload.test.d.ts +0 -1
- package/dist/commands/git-metadata/__tests__/upload.test.js +0 -60
- package/dist/commands/git-metadata/__tests__/upload.test.js.map +0 -1
- package/dist/commands/junit/__tests__/api.test.d.ts +0 -1
- package/dist/commands/junit/__tests__/api.test.js +0 -9
- package/dist/commands/junit/__tests__/api.test.js.map +0 -1
- package/dist/commands/junit/__tests__/upload.test.d.ts +0 -1
- package/dist/commands/junit/__tests__/upload.test.js +0 -283
- package/dist/commands/junit/__tests__/upload.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/fixtures.d.ts +0 -49
- package/dist/commands/lambda/__tests__/fixtures.js +0 -88
- package/dist/commands/lambda/__tests__/fixtures.js.map +0 -1
- package/dist/commands/lambda/__tests__/functions/commons.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/functions/commons.test.js +0 -716
- package/dist/commands/lambda/__tests__/functions/commons.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/functions/instrument.part1.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js +0 -350
- package/dist/commands/lambda/__tests__/functions/instrument.part1.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/functions/instrument.part2.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js +0 -583
- package/dist/commands/lambda/__tests__/functions/instrument.part2.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.js +0 -477
- package/dist/commands/lambda/__tests__/functions/uninstrument.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/functions/versionChecker.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/functions/versionChecker.test.js +0 -33
- package/dist/commands/lambda/__tests__/functions/versionChecker.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/instrument.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/instrument.test.js +0 -1478
- package/dist/commands/lambda/__tests__/instrument.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/loggroup.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/loggroup.test.js +0 -332
- package/dist/commands/lambda/__tests__/loggroup.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/prompt.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/prompt.test.js +0 -235
- package/dist/commands/lambda/__tests__/prompt.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/tags.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/tags.test.js +0 -253
- package/dist/commands/lambda/__tests__/tags.test.js.map +0 -1
- package/dist/commands/lambda/__tests__/uninstrument.test.d.ts +0 -1
- package/dist/commands/lambda/__tests__/uninstrument.test.js +0 -679
- package/dist/commands/lambda/__tests__/uninstrument.test.js.map +0 -1
- package/dist/commands/metric/__tests__/metric.test.d.ts +0 -1
- package/dist/commands/metric/__tests__/metric.test.js +0 -97
- package/dist/commands/metric/__tests__/metric.test.js.map +0 -1
- package/dist/commands/react-native/__tests__/codepush.test.d.ts +0 -1
- package/dist/commands/react-native/__tests__/codepush.test.js +0 -153
- package/dist/commands/react-native/__tests__/codepush.test.js.map +0 -1
- package/dist/commands/react-native/__tests__/interfaces.test.d.ts +0 -1
- package/dist/commands/react-native/__tests__/interfaces.test.js +0 -52
- package/dist/commands/react-native/__tests__/interfaces.test.js.map +0 -1
- package/dist/commands/react-native/__tests__/upload.test.d.ts +0 -1
- package/dist/commands/react-native/__tests__/upload.test.js +0 -176
- package/dist/commands/react-native/__tests__/upload.test.js.map +0 -1
- package/dist/commands/react-native/__tests__/xcode.test.d.ts +0 -1
- package/dist/commands/react-native/__tests__/xcode.test.js +0 -417
- package/dist/commands/react-native/__tests__/xcode.test.js.map +0 -1
- package/dist/commands/sourcemaps/__tests__/upload.test.d.ts +0 -1
- package/dist/commands/sourcemaps/__tests__/upload.test.js +0 -270
- package/dist/commands/sourcemaps/__tests__/upload.test.js.map +0 -1
- package/dist/commands/sourcemaps/__tests__/utils.test.d.ts +0 -1
- package/dist/commands/sourcemaps/__tests__/utils.test.js +0 -31
- package/dist/commands/sourcemaps/__tests__/utils.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/api.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/api.test.js +0 -273
- package/dist/commands/synthetics/__tests__/api.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/cli.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/cli.test.js +0 -391
- package/dist/commands/synthetics/__tests__/cli.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/fixtures.d.ts +0 -119
- package/dist/commands/synthetics/__tests__/fixtures.js +0 -386
- package/dist/commands/synthetics/__tests__/fixtures.js.map +0 -1
- package/dist/commands/synthetics/__tests__/mobile.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/mobile.test.js +0 -228
- package/dist/commands/synthetics/__tests__/mobile.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/reporters/default.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/reporters/default.test.js +0 -202
- package/dist/commands/synthetics/__tests__/reporters/default.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/reporters/junit.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/reporters/junit.test.js +0 -339
- package/dist/commands/synthetics/__tests__/reporters/junit.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/run-test.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/run-test.test.js +0 -419
- package/dist/commands/synthetics/__tests__/run-test.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/tunnel/crypto.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js +0 -21
- package/dist/commands/synthetics/__tests__/tunnel/crypto.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js +0 -80
- package/dist/commands/synthetics/__tests__/tunnel/tunnel.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/tunnel/websocket.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js +0 -111
- package/dist/commands/synthetics/__tests__/tunnel/websocket.test.js.map +0 -1
- package/dist/commands/synthetics/__tests__/utils.test.d.ts +0 -1
- package/dist/commands/synthetics/__tests__/utils.test.js +0 -933
- package/dist/commands/synthetics/__tests__/utils.test.js.map +0 -1
- package/dist/commands/tag/__tests__/tag.test.d.ts +0 -1
- package/dist/commands/tag/__tests__/tag.test.js +0 -77
- package/dist/commands/tag/__tests__/tag.test.js.map +0 -1
- package/dist/commands/trace/__tests__/trace.test.d.ts +0 -1
- package/dist/commands/trace/__tests__/trace.test.js +0 -64
- package/dist/commands/trace/__tests__/trace.test.js.map +0 -1
- package/dist/helpers/__tests__/ci.test.d.ts +0 -1
- package/dist/helpers/__tests__/ci.test.js +0 -197
- package/dist/helpers/__tests__/ci.test.js.map +0 -1
- package/dist/helpers/__tests__/plist.test.d.ts +0 -1
- package/dist/helpers/__tests__/plist.test.js +0 -31
- package/dist/helpers/__tests__/plist.test.js.map +0 -1
- package/dist/helpers/__tests__/retry.test.d.ts +0 -1
- package/dist/helpers/__tests__/retry.test.js +0 -99
- package/dist/helpers/__tests__/retry.test.js.map +0 -1
- package/dist/helpers/__tests__/tags.test.d.ts +0 -1
- package/dist/helpers/__tests__/tags.test.js +0 -17
- package/dist/helpers/__tests__/tags.test.js.map +0 -1
- package/dist/helpers/__tests__/upload.test.d.ts +0 -1
- package/dist/helpers/__tests__/upload.test.js +0 -185
- package/dist/helpers/__tests__/upload.test.js.map +0 -1
- package/dist/helpers/__tests__/user-provided-git.test.d.ts +0 -1
- package/dist/helpers/__tests__/user-provided-git.test.js +0 -119
- package/dist/helpers/__tests__/user-provided-git.test.js.map +0 -1
- package/dist/helpers/__tests__/utils.test.d.ts +0 -1
- package/dist/helpers/__tests__/utils.test.js +0 -382
- package/dist/helpers/__tests__/utils.test.js.map +0 -1
- package/dist/helpers/__tests__/validation.test.d.ts +0 -1
- package/dist/helpers/__tests__/validation.test.js +0 -21
- package/dist/helpers/__tests__/validation.test.js.map +0 -1
- package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.d.ts +0 -1
- package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js +0 -106
- package/dist/helpers/git/__tests__/format-git-sourcemaps-data.test.js.map +0 -1
- package/dist/helpers/git/__tests__/format-git-span-data.test.d.ts +0 -1
- package/dist/helpers/git/__tests__/format-git-span-data.test.js +0 -67
- package/dist/helpers/git/__tests__/format-git-span-data.test.js.map +0 -1
- package/dist/helpers/git/__tests__/get-git-data.test.d.ts +0 -1
- package/dist/helpers/git/__tests__/get-git-data.test.js +0 -60
- package/dist/helpers/git/__tests__/get-git-data.test.js.map +0 -1
|
@@ -1,716 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const aws_sdk_1 = require("aws-sdk");
|
|
13
|
-
jest.mock('aws-sdk');
|
|
14
|
-
jest.mock('../../renderer', () => require('../../__mocks__/renderer'));
|
|
15
|
-
const constants_1 = require("../../constants");
|
|
16
|
-
const commons_1 = require("../../functions/commons");
|
|
17
|
-
const instrument_1 = require("../../instrument");
|
|
18
|
-
const fixtures_1 = require("../fixtures");
|
|
19
|
-
describe('commons', () => {
|
|
20
|
-
describe('addLayerArn', () => {
|
|
21
|
-
test('adds layers and removes previous versions', () => {
|
|
22
|
-
const runtime = 'python3.9';
|
|
23
|
-
const config = {
|
|
24
|
-
Runtime: runtime,
|
|
25
|
-
};
|
|
26
|
-
let layerARNs = [
|
|
27
|
-
'arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Python39:48',
|
|
28
|
-
'arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:10',
|
|
29
|
-
];
|
|
30
|
-
const region = 'sa-east-1';
|
|
31
|
-
const lambdaLibraryLayerName = constants_1.LAYER_LOOKUP[runtime];
|
|
32
|
-
const fullLambdaLibraryLayerArn = commons_1.getLayerArn(config, config.Runtime, region) + ':49';
|
|
33
|
-
const fullExtensionLayerArn = commons_1.getLayerArn(config, constants_1.EXTENSION_LAYER_KEY, region) + ':11';
|
|
34
|
-
layerARNs = commons_1.addLayerArn(fullLambdaLibraryLayerArn, lambdaLibraryLayerName, layerARNs);
|
|
35
|
-
layerARNs = commons_1.addLayerArn(fullExtensionLayerArn, constants_1.DD_LAMBDA_EXTENSION_LAYER_NAME, layerARNs);
|
|
36
|
-
expect(layerARNs).toEqual([
|
|
37
|
-
'arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Python39:49',
|
|
38
|
-
'arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:11',
|
|
39
|
-
]);
|
|
40
|
-
});
|
|
41
|
-
test('swaps layers if architecture is arm64', () => {
|
|
42
|
-
const runtime = 'python3.9';
|
|
43
|
-
const config = {
|
|
44
|
-
Architectures: ['arm64'],
|
|
45
|
-
Runtime: runtime,
|
|
46
|
-
};
|
|
47
|
-
let layerARNs = [
|
|
48
|
-
'arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Python39:49',
|
|
49
|
-
'arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension:11',
|
|
50
|
-
];
|
|
51
|
-
const region = 'sa-east-1';
|
|
52
|
-
const lambdaLibraryLayerName = constants_1.LAYER_LOOKUP[runtime];
|
|
53
|
-
const fullLambdaLibraryLayerArn = commons_1.getLayerArn(config, config.Runtime, region) + ':49';
|
|
54
|
-
const fullExtensionLayerArn = commons_1.getLayerArn(config, constants_1.EXTENSION_LAYER_KEY, region) + ':11';
|
|
55
|
-
layerARNs = commons_1.addLayerArn(fullLambdaLibraryLayerArn, lambdaLibraryLayerName, layerARNs);
|
|
56
|
-
layerARNs = commons_1.addLayerArn(fullExtensionLayerArn, constants_1.DD_LAMBDA_EXTENSION_LAYER_NAME, layerARNs);
|
|
57
|
-
expect(layerARNs).toEqual([
|
|
58
|
-
'arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Python39-ARM:49',
|
|
59
|
-
'arn:aws:lambda:sa-east-1:464622532012:layer:Datadog-Extension-ARM:11',
|
|
60
|
-
]);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
describe('coerceBoolean', () => {
|
|
64
|
-
test('return fallback when none of the values provided can be parsed to boolean', () => {
|
|
65
|
-
expect(commons_1.coerceBoolean(true, 'NotBoolean', 123, [], {})).toBe(true);
|
|
66
|
-
expect(commons_1.coerceBoolean(false, 'NotBooleanEither', 456, ['An array'], { booleanInObject: true })).toBe(false);
|
|
67
|
-
});
|
|
68
|
-
test('return the first boolean when one of the values provided can be parsed to boolean', () => {
|
|
69
|
-
expect(commons_1.coerceBoolean(true, 'false', 'true')).toBe(false);
|
|
70
|
-
expect(commons_1.coerceBoolean(false, 'true', 'False')).toBe(true);
|
|
71
|
-
});
|
|
72
|
-
test('return the first boolean when one of the values provided is boolean', () => {
|
|
73
|
-
expect(commons_1.coerceBoolean(true, false, 'truE', true)).toBe(false);
|
|
74
|
-
expect(commons_1.coerceBoolean(false, true, 'False', false)).toBe(true);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
describe('collectFunctionsByRegion', () => {
|
|
78
|
-
test('groups functions with region read from arn', () => {
|
|
79
|
-
process.env = {};
|
|
80
|
-
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
81
|
-
const region = 'us-east-1';
|
|
82
|
-
command['functions'] = [
|
|
83
|
-
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
84
|
-
'arn:aws:lambda:us-east-1:123456789012:function:another',
|
|
85
|
-
'arn:aws:lambda:us-east-2:123456789012:function:third-func',
|
|
86
|
-
];
|
|
87
|
-
expect(commons_1.collectFunctionsByRegion(command['functions'], region)).toEqual({
|
|
88
|
-
'us-east-1': [
|
|
89
|
-
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
90
|
-
'arn:aws:lambda:us-east-1:123456789012:function:another',
|
|
91
|
-
],
|
|
92
|
-
'us-east-2': ['arn:aws:lambda:us-east-2:123456789012:function:third-func'],
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
test('groups functions in the config object', () => {
|
|
96
|
-
process.env = {};
|
|
97
|
-
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
98
|
-
const region = 'us-east-1';
|
|
99
|
-
command['config']['functions'] = [
|
|
100
|
-
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
101
|
-
'arn:aws:lambda:us-east-1:123456789012:function:another',
|
|
102
|
-
'arn:aws:lambda:us-east-2:123456789012:function:third-func',
|
|
103
|
-
];
|
|
104
|
-
expect(commons_1.collectFunctionsByRegion(command['config']['functions'], region)).toEqual({
|
|
105
|
-
'us-east-1': [
|
|
106
|
-
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
107
|
-
'arn:aws:lambda:us-east-1:123456789012:function:another',
|
|
108
|
-
],
|
|
109
|
-
'us-east-2': ['arn:aws:lambda:us-east-2:123456789012:function:third-func'],
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
test('uses default region for functions not in arn format', () => {
|
|
113
|
-
process.env = {};
|
|
114
|
-
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
115
|
-
command['functions'] = [
|
|
116
|
-
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
117
|
-
'arn:aws:lambda:*:123456789012:function:func-with-wildcard',
|
|
118
|
-
'func-without-region',
|
|
119
|
-
'arn:aws:lambda:us-east-2:123456789012:function:third-func',
|
|
120
|
-
];
|
|
121
|
-
command['region'] = 'ap-south-1';
|
|
122
|
-
expect(commons_1.collectFunctionsByRegion(command['functions'], command['region'])).toEqual({
|
|
123
|
-
'ap-south-1': ['arn:aws:lambda:*:123456789012:function:func-with-wildcard', 'func-without-region'],
|
|
124
|
-
'us-east-1': ['arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world'],
|
|
125
|
-
'us-east-2': ['arn:aws:lambda:us-east-2:123456789012:function:third-func'],
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
test('fails to collect when there are regionless functions and no default region is set', () => {
|
|
129
|
-
process.env = {};
|
|
130
|
-
const command = fixtures_1.createCommand(instrument_1.InstrumentCommand);
|
|
131
|
-
command['functions'] = [
|
|
132
|
-
'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world',
|
|
133
|
-
'arn:aws:lambda:*:123456789012:function:func-with-wildcard',
|
|
134
|
-
'func-without-region',
|
|
135
|
-
'arn:aws:lambda:us-east-2:123456789012:function:third-func',
|
|
136
|
-
];
|
|
137
|
-
command['region'] = undefined;
|
|
138
|
-
command['config']['region'] = undefined;
|
|
139
|
-
let functionsGroup;
|
|
140
|
-
try {
|
|
141
|
-
functionsGroup = commons_1.collectFunctionsByRegion(command['functions'], command['region']);
|
|
142
|
-
}
|
|
143
|
-
catch (err) {
|
|
144
|
-
// Do nothing
|
|
145
|
-
}
|
|
146
|
-
expect(functionsGroup).toBeUndefined();
|
|
147
|
-
});
|
|
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 only AWS_SECRET_ACCESS_KEY env var is set and `~/.aws/credentials` are missing', () => {
|
|
242
|
-
process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = 'SOME-AWS-SECRET-ACCESS-KEY';
|
|
243
|
-
aws_sdk_1.config.credentials = undefined;
|
|
244
|
-
expect(commons_1.isMissingAWSCredentials()).toBe(true); // We return true since AWS_ACCESS_KEY_ID_ENV_VAR is missing
|
|
245
|
-
});
|
|
246
|
-
test('returns true when only AWS_ACCESS_KEY_ID environment variable is set and `~/.aws/credentials` are missing', () => {
|
|
247
|
-
process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = 'SOME-AWS-ACCESS-KEY-ID';
|
|
248
|
-
aws_sdk_1.config.credentials = undefined;
|
|
249
|
-
expect(commons_1.isMissingAWSCredentials()).toBe(true); // We return true since AWS_SECRET_ACCESS_KEY_ENV_VAR is missing
|
|
250
|
-
});
|
|
251
|
-
test('returns false when AWS credentials via environment variables are set', () => {
|
|
252
|
-
process.env[constants_1.AWS_ACCESS_KEY_ID_ENV_VAR] = 'SOME-AWS-ACCESS-KEY-ID';
|
|
253
|
-
process.env[constants_1.AWS_SECRET_ACCESS_KEY_ENV_VAR] = 'SOME-AWS-SECRET-ACCESS-KEY';
|
|
254
|
-
aws_sdk_1.config.credentials = { foo: 'bar' };
|
|
255
|
-
expect(commons_1.isMissingAWSCredentials()).toBe(false);
|
|
256
|
-
});
|
|
257
|
-
test('returns true when both environment variables and `~/.aws/credentials` are missing', () => {
|
|
258
|
-
aws_sdk_1.config.credentials = undefined;
|
|
259
|
-
expect(commons_1.isMissingAWSCredentials()).toBe(true);
|
|
260
|
-
});
|
|
261
|
-
test('returns false when AWS credentials via `~/.aws/credentials` are set', () => {
|
|
262
|
-
aws_sdk_1.config.credentials = { foo: 'bar' };
|
|
263
|
-
expect(commons_1.isMissingAWSCredentials()).toBe(false);
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
describe('isMissingDatadogEnvVars', () => {
|
|
267
|
-
const OLD_ENV = process.env;
|
|
268
|
-
beforeEach(() => {
|
|
269
|
-
jest.resetModules();
|
|
270
|
-
process.env = {};
|
|
271
|
-
});
|
|
272
|
-
afterAll(() => {
|
|
273
|
-
process.env = OLD_ENV;
|
|
274
|
-
});
|
|
275
|
-
test('returns true when any Datadog Env Var is missing', () => {
|
|
276
|
-
process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
|
|
277
|
-
expect(commons_1.isMissingDatadogEnvVars()).toBe(true);
|
|
278
|
-
// Reset env
|
|
279
|
-
process.env = {};
|
|
280
|
-
process.env[constants_1.CI_API_KEY_ENV_VAR] = 'SOME-DATADOG-API-KEY';
|
|
281
|
-
expect(commons_1.isMissingDatadogEnvVars()).toBe(true);
|
|
282
|
-
process.env = {};
|
|
283
|
-
process.env[constants_1.CI_KMS_API_KEY_ENV_VAR] = 'SOME-AWS-KMS-API-KEY-CONTAINING-DATADOG-API-KEY';
|
|
284
|
-
expect(commons_1.isMissingDatadogEnvVars()).toBe(true);
|
|
285
|
-
process.env = {};
|
|
286
|
-
process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'SOME-AWS-SECRET-ARN-CONTAINING-DATADOG-API-KEY';
|
|
287
|
-
expect(commons_1.isMissingDatadogEnvVars()).toBe(true);
|
|
288
|
-
});
|
|
289
|
-
test('returns false when Datadog Env Vars are set with DATADOG_API_KEY', () => {
|
|
290
|
-
process.env[constants_1.CI_API_KEY_ENV_VAR] = 'SOME-DATADOG-API-KEY';
|
|
291
|
-
process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
|
|
292
|
-
expect(commons_1.isMissingDatadogEnvVars()).toBe(false);
|
|
293
|
-
});
|
|
294
|
-
test('returns false when Datadog Env Vars are set with DATADOG_KMS_API_KEY', () => {
|
|
295
|
-
process.env[constants_1.CI_KMS_API_KEY_ENV_VAR] = 'SOME-AWS-KMS-API-KEY-CONTAINING-DATADOG-API-KEY';
|
|
296
|
-
process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
|
|
297
|
-
expect(commons_1.isMissingDatadogEnvVars()).toBe(false);
|
|
298
|
-
});
|
|
299
|
-
test('returns false when Datadog Env Vars are set with DATADOG_API_KEY_SECRET_ARN', () => {
|
|
300
|
-
process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'SOME-AWS-SECRET-ARN-CONTAINING-DATADOG-API-KEY';
|
|
301
|
-
process.env[constants_1.CI_SITE_ENV_VAR] = 'datadoghq.com';
|
|
302
|
-
expect(commons_1.isMissingDatadogEnvVars()).toBe(false);
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
describe('isMissingAnyDatadogApiKeyEnvVar', () => {
|
|
306
|
-
const OLD_ENV = process.env;
|
|
307
|
-
beforeEach(() => {
|
|
308
|
-
jest.resetModules();
|
|
309
|
-
process.env = {};
|
|
310
|
-
});
|
|
311
|
-
afterAll(() => {
|
|
312
|
-
process.env = OLD_ENV;
|
|
313
|
-
});
|
|
314
|
-
test('returns true when no Datadog Api Key is set', () => {
|
|
315
|
-
expect(commons_1.isMissingAnyDatadogApiKeyEnvVar()).toBe(true);
|
|
316
|
-
});
|
|
317
|
-
test('returns false when DATADOG_API_KEY is set', () => {
|
|
318
|
-
process.env[constants_1.CI_API_KEY_ENV_VAR] = 'SOME-DATADOG-API-KEY';
|
|
319
|
-
expect(commons_1.isMissingAnyDatadogApiKeyEnvVar()).toBe(false);
|
|
320
|
-
});
|
|
321
|
-
test('returns false when DATADOG_KMS_API_KEY is set', () => {
|
|
322
|
-
process.env[constants_1.CI_KMS_API_KEY_ENV_VAR] = 'SOME-AWS-KMS-API-KEY-CONTAINING-DATADOG-API-KEY';
|
|
323
|
-
expect(commons_1.isMissingAnyDatadogApiKeyEnvVar()).toBe(false);
|
|
324
|
-
});
|
|
325
|
-
test('returns false when DATADOG_API_KEY_SECRET_ARN is set', () => {
|
|
326
|
-
process.env[constants_1.CI_API_KEY_SECRET_ARN_ENV_VAR] = 'SOME-AWS-SECRET-ARN-CONTAINING-DATADOG-API-KEY';
|
|
327
|
-
expect(commons_1.isMissingAnyDatadogApiKeyEnvVar()).toBe(false);
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
describe('getLayerArn', () => {
|
|
331
|
-
const OLD_ENV = process.env;
|
|
332
|
-
beforeEach(() => {
|
|
333
|
-
jest.resetModules();
|
|
334
|
-
process.env = {};
|
|
335
|
-
});
|
|
336
|
-
afterAll(() => {
|
|
337
|
-
process.env = OLD_ENV;
|
|
338
|
-
});
|
|
339
|
-
test('gets sa-east-1 Lambda Extension layer ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
340
|
-
const settings = {
|
|
341
|
-
flushMetricsToLogs: false,
|
|
342
|
-
layerAWSAccount: fixtures_1.mockAwsAccount,
|
|
343
|
-
mergeXrayTraces: false,
|
|
344
|
-
tracingEnabled: false,
|
|
345
|
-
};
|
|
346
|
-
const region = 'sa-east-1';
|
|
347
|
-
const layerArn = commons_1.getLayerArn({}, constants_1.EXTENSION_LAYER_KEY, region, settings);
|
|
348
|
-
expect(layerArn).toEqual(`arn:aws:lambda:${region}:${fixtures_1.mockAwsAccount}:layer:Datadog-Extension`);
|
|
349
|
-
}));
|
|
350
|
-
test('gets sa-east-1 arm64 Lambda Extension layer ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
351
|
-
const config = {
|
|
352
|
-
Architectures: ['arm64'],
|
|
353
|
-
};
|
|
354
|
-
const settings = {
|
|
355
|
-
flushMetricsToLogs: false,
|
|
356
|
-
layerAWSAccount: fixtures_1.mockAwsAccount,
|
|
357
|
-
mergeXrayTraces: false,
|
|
358
|
-
tracingEnabled: false,
|
|
359
|
-
};
|
|
360
|
-
const region = 'sa-east-1';
|
|
361
|
-
const layerArn = commons_1.getLayerArn(config, constants_1.EXTENSION_LAYER_KEY, region, settings);
|
|
362
|
-
expect(layerArn).toEqual(`arn:aws:lambda:${region}:${fixtures_1.mockAwsAccount}:layer:Datadog-Extension-ARM`);
|
|
363
|
-
}));
|
|
364
|
-
test('gets us-gov-1 gov cloud Lambda Extension layer ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
365
|
-
const settings = {
|
|
366
|
-
flushMetricsToLogs: false,
|
|
367
|
-
layerAWSAccount: fixtures_1.mockAwsAccount,
|
|
368
|
-
mergeXrayTraces: false,
|
|
369
|
-
tracingEnabled: false,
|
|
370
|
-
};
|
|
371
|
-
const region = 'us-gov-1';
|
|
372
|
-
const layerArn = commons_1.getLayerArn({}, constants_1.EXTENSION_LAYER_KEY, region, settings);
|
|
373
|
-
expect(layerArn).toEqual(`arn:aws-us-gov:lambda:${region}:${constants_1.GOVCLOUD_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension`);
|
|
374
|
-
}));
|
|
375
|
-
test('gets us-gov-1 gov cloud arm64 Lambda Extension layer ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
376
|
-
const config = {
|
|
377
|
-
Architectures: ['arm64'],
|
|
378
|
-
};
|
|
379
|
-
const settings = {
|
|
380
|
-
flushMetricsToLogs: false,
|
|
381
|
-
layerAWSAccount: fixtures_1.mockAwsAccount,
|
|
382
|
-
mergeXrayTraces: false,
|
|
383
|
-
tracingEnabled: false,
|
|
384
|
-
};
|
|
385
|
-
const region = 'us-gov-1';
|
|
386
|
-
const layerArn = commons_1.getLayerArn(config, constants_1.EXTENSION_LAYER_KEY, region, settings);
|
|
387
|
-
expect(layerArn).toEqual(`arn:aws-us-gov:lambda:${region}:${constants_1.GOVCLOUD_LAYER_AWS_ACCOUNT}:layer:Datadog-Extension-ARM`);
|
|
388
|
-
}));
|
|
389
|
-
test('gets sa-east-1 Node12 Lambda Library layer ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
390
|
-
const runtime = 'nodejs12.x';
|
|
391
|
-
const config = {
|
|
392
|
-
Runtime: runtime,
|
|
393
|
-
};
|
|
394
|
-
const settings = {
|
|
395
|
-
flushMetricsToLogs: false,
|
|
396
|
-
layerAWSAccount: fixtures_1.mockAwsAccount,
|
|
397
|
-
mergeXrayTraces: false,
|
|
398
|
-
tracingEnabled: false,
|
|
399
|
-
};
|
|
400
|
-
const region = 'sa-east-1';
|
|
401
|
-
const layerArn = commons_1.getLayerArn(config, config.Runtime, region, settings);
|
|
402
|
-
expect(layerArn).toEqual(`arn:aws:lambda:${region}:${fixtures_1.mockAwsAccount}:layer:Datadog-Node12-x`);
|
|
403
|
-
}));
|
|
404
|
-
test('gets sa-east-1 Python3.9 arm64 Lambda Library layer ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
405
|
-
const runtime = 'python3.9';
|
|
406
|
-
const config = {
|
|
407
|
-
Architectures: ['arm64'],
|
|
408
|
-
Runtime: runtime,
|
|
409
|
-
};
|
|
410
|
-
const settings = {
|
|
411
|
-
flushMetricsToLogs: false,
|
|
412
|
-
layerAWSAccount: fixtures_1.mockAwsAccount,
|
|
413
|
-
mergeXrayTraces: false,
|
|
414
|
-
tracingEnabled: false,
|
|
415
|
-
};
|
|
416
|
-
const region = 'sa-east-1';
|
|
417
|
-
const layerArn = commons_1.getLayerArn(config, config.Runtime, region, settings);
|
|
418
|
-
expect(layerArn).toEqual(`arn:aws:lambda:${region}:${fixtures_1.mockAwsAccount}:layer:Datadog-Python39-ARM`);
|
|
419
|
-
}));
|
|
420
|
-
test('gets us-gov-1 Python37 gov cloud Lambda Library layer ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
421
|
-
const runtime = 'python3.7';
|
|
422
|
-
const config = {
|
|
423
|
-
Runtime: runtime,
|
|
424
|
-
};
|
|
425
|
-
const settings = {
|
|
426
|
-
flushMetricsToLogs: false,
|
|
427
|
-
layerAWSAccount: fixtures_1.mockAwsAccount,
|
|
428
|
-
mergeXrayTraces: false,
|
|
429
|
-
tracingEnabled: false,
|
|
430
|
-
};
|
|
431
|
-
const region = 'us-gov-1';
|
|
432
|
-
const layerArn = commons_1.getLayerArn(config, config.Runtime, region, settings);
|
|
433
|
-
expect(layerArn).toEqual(`arn:aws-us-gov:lambda:${region}:${constants_1.GOVCLOUD_LAYER_AWS_ACCOUNT}:layer:Datadog-Python37`);
|
|
434
|
-
}));
|
|
435
|
-
test('gets us-gov-1 Python39 gov cloud arm64 Lambda Library layer ARN', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
436
|
-
const runtime = 'python3.9';
|
|
437
|
-
const config = {
|
|
438
|
-
Architectures: ['arm64'],
|
|
439
|
-
Runtime: runtime,
|
|
440
|
-
};
|
|
441
|
-
const settings = {
|
|
442
|
-
flushMetricsToLogs: false,
|
|
443
|
-
layerAWSAccount: fixtures_1.mockAwsAccount,
|
|
444
|
-
mergeXrayTraces: false,
|
|
445
|
-
tracingEnabled: false,
|
|
446
|
-
};
|
|
447
|
-
const region = 'us-gov-1';
|
|
448
|
-
const layerArn = commons_1.getLayerArn(config, config.Runtime, region, settings);
|
|
449
|
-
expect(layerArn).toEqual(`arn:aws-us-gov:lambda:${region}:${constants_1.GOVCLOUD_LAYER_AWS_ACCOUNT}:layer:Datadog-Python39-ARM`);
|
|
450
|
-
}));
|
|
451
|
-
});
|
|
452
|
-
describe('getLayerNameWithVersion', () => {
|
|
453
|
-
const OLD_ENV = process.env;
|
|
454
|
-
beforeEach(() => {
|
|
455
|
-
jest.resetModules();
|
|
456
|
-
process.env = {};
|
|
457
|
-
});
|
|
458
|
-
afterAll(() => {
|
|
459
|
-
process.env = OLD_ENV;
|
|
460
|
-
});
|
|
461
|
-
test('returns the correct name and version given an extension layer arn', () => {
|
|
462
|
-
const layerName = constants_1.DD_LAMBDA_EXTENSION_LAYER_NAME;
|
|
463
|
-
const version = '16';
|
|
464
|
-
const layerNameWithVersion = `${layerName}:${version}`;
|
|
465
|
-
const layerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:${layerNameWithVersion}`;
|
|
466
|
-
expect(commons_1.getLayerNameWithVersion(layerArn)).toBe(layerNameWithVersion);
|
|
467
|
-
});
|
|
468
|
-
test('returns the correct name and version given a library layer arn', () => {
|
|
469
|
-
const layerName = 'Datadog-Python39';
|
|
470
|
-
const version = '59';
|
|
471
|
-
const layerNameWithVersion = `${layerName}:${version}`;
|
|
472
|
-
const layerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:${layerNameWithVersion}`;
|
|
473
|
-
expect(commons_1.getLayerNameWithVersion(layerArn)).toBe(layerNameWithVersion);
|
|
474
|
-
});
|
|
475
|
-
test('returns undefined if arn is incomplete', () => {
|
|
476
|
-
const layerArn = `arn:aws:lambda:sa-east-1:${fixtures_1.mockAwsAccount}:layer:Datadog-Python39`;
|
|
477
|
-
expect(commons_1.getLayerNameWithVersion(layerArn)).toBe(undefined);
|
|
478
|
-
});
|
|
479
|
-
});
|
|
480
|
-
describe('getRegion', () => {
|
|
481
|
-
test('should return the expected region', () => {
|
|
482
|
-
const functionARN = 'arn:aws:lambda:us-east-1:123456789012:function:lambda-hello-world';
|
|
483
|
-
const expectedRegion = 'us-east-1';
|
|
484
|
-
const region = commons_1.getRegion(functionARN);
|
|
485
|
-
expect(region).toBe(expectedRegion);
|
|
486
|
-
});
|
|
487
|
-
test('should return undefined if Function ARN does not contain the region', () => {
|
|
488
|
-
const functionName = 'lambda-hello-world';
|
|
489
|
-
const region = commons_1.getRegion(functionName);
|
|
490
|
-
expect(region).toBe(undefined);
|
|
491
|
-
});
|
|
492
|
-
});
|
|
493
|
-
describe('sentenceMatchesRegEx', () => {
|
|
494
|
-
const tags = [
|
|
495
|
-
['not-complying:regex-should-fail', false],
|
|
496
|
-
['1first-char-is-number:should-fail', false],
|
|
497
|
-
['_also-not-complying:should-fail', false],
|
|
498
|
-
['complying_tag:accepted/with/slashes.and.dots,but-empty-tag', false],
|
|
499
|
-
['also_complying:success,1but_is_illegal:should-fail', false],
|
|
500
|
-
['this:complies,also_this_one:yes,numb3r_in_name:should-succeed,dots:al.lo.wed', true],
|
|
501
|
-
['complying_ip_address_4:192.342.3134.231', true],
|
|
502
|
-
['complying:alone', true],
|
|
503
|
-
['one_divided_by_two:1/2,one_divided_by_four:0.25,three_minus_one_half:3-1/2', true],
|
|
504
|
-
['this_is_a_valid_t4g:yes/it.is-42', true],
|
|
505
|
-
];
|
|
506
|
-
test.each(tags)('check if the tags match the expected result from the regex', (tag, expectedResult) => {
|
|
507
|
-
const result = !!commons_1.sentenceMatchesRegEx(tag, constants_1.EXTRA_TAGS_REG_EXP);
|
|
508
|
-
expect(result).toEqual(expectedResult);
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
describe('updateLambdaFunctionConfig', () => {
|
|
512
|
-
const OLD_ENV = process.env;
|
|
513
|
-
beforeEach(() => {
|
|
514
|
-
jest.resetModules();
|
|
515
|
-
process.env = {};
|
|
516
|
-
});
|
|
517
|
-
afterAll(() => {
|
|
518
|
-
process.env = OLD_ENV;
|
|
519
|
-
});
|
|
520
|
-
test('updates every lambda', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
521
|
-
const lambda = fixtures_1.makeMockLambda({});
|
|
522
|
-
const configs = [
|
|
523
|
-
{
|
|
524
|
-
functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
|
|
525
|
-
lambdaConfig: {
|
|
526
|
-
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
|
|
527
|
-
Handler: 'index.handler',
|
|
528
|
-
Runtime: 'nodejs12.x',
|
|
529
|
-
},
|
|
530
|
-
lambdaLibraryLayerArn: 'arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x',
|
|
531
|
-
updateRequest: {
|
|
532
|
-
Environment: {
|
|
533
|
-
Variables: {
|
|
534
|
-
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'index.handler',
|
|
535
|
-
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
536
|
-
[constants_1.TRACE_ENABLED_ENV_VAR]: 'false',
|
|
537
|
-
},
|
|
538
|
-
},
|
|
539
|
-
FunctionName: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
|
|
540
|
-
Handler: '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler',
|
|
541
|
-
Layers: ['arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:22'],
|
|
542
|
-
},
|
|
543
|
-
},
|
|
544
|
-
];
|
|
545
|
-
const cloudWatch = fixtures_1.makeMockCloudWatchLogs({});
|
|
546
|
-
yield Promise.all(configs.map((config) => __awaiter(void 0, void 0, void 0, function* () { return commons_1.updateLambdaFunctionConfig(lambda, cloudWatch, config); })));
|
|
547
|
-
expect(lambda.updateFunctionConfiguration).toHaveBeenCalledWith({
|
|
548
|
-
Environment: {
|
|
549
|
-
Variables: {
|
|
550
|
-
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'index.handler',
|
|
551
|
-
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
552
|
-
[constants_1.TRACE_ENABLED_ENV_VAR]: 'false',
|
|
553
|
-
},
|
|
554
|
-
},
|
|
555
|
-
FunctionName: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
|
|
556
|
-
Handler: '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler',
|
|
557
|
-
Layers: ['arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:22'],
|
|
558
|
-
});
|
|
559
|
-
}));
|
|
560
|
-
});
|
|
561
|
-
describe('handleLambdaFunctionUpdates', () => {
|
|
562
|
-
const OLD_ENV = process.env;
|
|
563
|
-
beforeEach(() => {
|
|
564
|
-
jest.resetModules();
|
|
565
|
-
process.env = {};
|
|
566
|
-
});
|
|
567
|
-
afterAll(() => {
|
|
568
|
-
process.env = OLD_ENV;
|
|
569
|
-
});
|
|
570
|
-
const cloudWatchLogs = fixtures_1.makeMockCloudWatchLogs({});
|
|
571
|
-
const stdout = { write: (_) => jest.fn() };
|
|
572
|
-
const getConfigs = (lambda) => [
|
|
573
|
-
{
|
|
574
|
-
lambda,
|
|
575
|
-
cloudWatchLogs,
|
|
576
|
-
configs: [
|
|
577
|
-
{
|
|
578
|
-
functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
|
|
579
|
-
lambdaConfig: {
|
|
580
|
-
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
|
|
581
|
-
Handler: 'index.handler',
|
|
582
|
-
Runtime: 'nodejs12.x',
|
|
583
|
-
},
|
|
584
|
-
lambdaLibraryLayerArn: 'arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x',
|
|
585
|
-
updateRequest: {
|
|
586
|
-
Environment: {
|
|
587
|
-
Variables: {
|
|
588
|
-
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'index.handler',
|
|
589
|
-
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
590
|
-
[constants_1.TRACE_ENABLED_ENV_VAR]: 'false',
|
|
591
|
-
},
|
|
592
|
-
},
|
|
593
|
-
FunctionName: 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument',
|
|
594
|
-
Handler: '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler',
|
|
595
|
-
Layers: ['arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node12-x:XX'],
|
|
596
|
-
},
|
|
597
|
-
},
|
|
598
|
-
],
|
|
599
|
-
region: 'us-east-1',
|
|
600
|
-
},
|
|
601
|
-
{
|
|
602
|
-
lambda,
|
|
603
|
-
cloudWatchLogs,
|
|
604
|
-
configs: [
|
|
605
|
-
{
|
|
606
|
-
functionARN: 'arn:aws:lambda:us-east-2:000000000000:function:autoinstrument',
|
|
607
|
-
lambdaConfig: {
|
|
608
|
-
FunctionArn: 'arn:aws:lambda:us-east-2:000000000000:function:autoinstrument',
|
|
609
|
-
Handler: 'index.handler',
|
|
610
|
-
Runtime: 'nodejs14.x',
|
|
611
|
-
},
|
|
612
|
-
lambdaLibraryLayerArn: 'arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node14-x',
|
|
613
|
-
updateRequest: {
|
|
614
|
-
Environment: {
|
|
615
|
-
Variables: {
|
|
616
|
-
[constants_1.LAMBDA_HANDLER_ENV_VAR]: 'index.handler',
|
|
617
|
-
[constants_1.MERGE_XRAY_TRACES_ENV_VAR]: 'false',
|
|
618
|
-
[constants_1.TRACE_ENABLED_ENV_VAR]: 'false',
|
|
619
|
-
},
|
|
620
|
-
},
|
|
621
|
-
FunctionName: 'arn:aws:lambda:us-east-2:000000000000:function:autoinstrument',
|
|
622
|
-
Handler: '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler',
|
|
623
|
-
Layers: ['arn:aws:lambda:us-east-1:464622532012:layer:Datadog-Node14-x:XX'],
|
|
624
|
-
},
|
|
625
|
-
},
|
|
626
|
-
],
|
|
627
|
-
region: 'us-east-2',
|
|
628
|
-
},
|
|
629
|
-
];
|
|
630
|
-
test('throws an error when all functions from every region fail to update', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
631
|
-
const lambda = Object.assign(Object.assign({}, fixtures_1.makeMockLambda({})), { updateFunctionConfiguration: jest.fn().mockImplementation((_) => {
|
|
632
|
-
return { promise: () => Promise.reject() };
|
|
633
|
-
}) });
|
|
634
|
-
const configs = getConfigs(lambda);
|
|
635
|
-
yield expect(commons_1.handleLambdaFunctionUpdates(configs, stdout)).rejects.toThrow();
|
|
636
|
-
}));
|
|
637
|
-
test('throws an error when all functions from every region fail to update', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
638
|
-
const lambda = Object.assign(Object.assign({}, fixtures_1.makeMockLambda({})), { updateFunctionConfiguration: jest.fn().mockImplementation((_) => ({ promise: () => Promise.reject() })) });
|
|
639
|
-
const configs = getConfigs(lambda);
|
|
640
|
-
yield expect(commons_1.handleLambdaFunctionUpdates(configs, stdout)).rejects.toThrow();
|
|
641
|
-
}));
|
|
642
|
-
test('to not throw an error when at least one function is updated', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
643
|
-
const lambda = Object.assign(Object.assign({}, fixtures_1.makeMockLambda({})), { updateFunctionConfiguration: jest.fn().mockImplementation((updateRequest) => {
|
|
644
|
-
if (updateRequest['FunctionName'] === 'arn:aws:lambda:us-east-1:000000000000:function:autoinstrument') {
|
|
645
|
-
return { promise: () => Promise.reject() };
|
|
646
|
-
}
|
|
647
|
-
return { promise: () => Promise.resolve() };
|
|
648
|
-
}) });
|
|
649
|
-
const configs = getConfigs(lambda);
|
|
650
|
-
// when sucessful, the function doesnt do anything
|
|
651
|
-
const result = yield commons_1.handleLambdaFunctionUpdates(configs, stdout);
|
|
652
|
-
expect(result).toBe(undefined);
|
|
653
|
-
}));
|
|
654
|
-
});
|
|
655
|
-
describe('Correctly handles multiple runtimes', () => {
|
|
656
|
-
test('returns true if all runtimes are uniform', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
657
|
-
const configs = [
|
|
658
|
-
{
|
|
659
|
-
functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func1',
|
|
660
|
-
lambdaConfig: {
|
|
661
|
-
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func1',
|
|
662
|
-
Handler: 'index.handler',
|
|
663
|
-
Runtime: 'nodejs14.x',
|
|
664
|
-
},
|
|
665
|
-
},
|
|
666
|
-
{
|
|
667
|
-
functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func2',
|
|
668
|
-
lambdaConfig: {
|
|
669
|
-
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func2',
|
|
670
|
-
Handler: 'index.handler',
|
|
671
|
-
Runtime: 'nodejs12.x',
|
|
672
|
-
},
|
|
673
|
-
},
|
|
674
|
-
{
|
|
675
|
-
functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func3',
|
|
676
|
-
lambdaConfig: {
|
|
677
|
-
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func3',
|
|
678
|
-
Handler: 'index.handler',
|
|
679
|
-
Runtime: 'nodejs16.x',
|
|
680
|
-
},
|
|
681
|
-
},
|
|
682
|
-
{
|
|
683
|
-
functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func4',
|
|
684
|
-
lambdaConfig: {
|
|
685
|
-
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func4',
|
|
686
|
-
Handler: 'index.handler',
|
|
687
|
-
Runtime: 'nodejs18.x',
|
|
688
|
-
},
|
|
689
|
-
},
|
|
690
|
-
];
|
|
691
|
-
expect(commons_1.checkRuntimeTypesAreUniform(configs)).toBe(true);
|
|
692
|
-
}));
|
|
693
|
-
test('returns false if runtimes are not uniform', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
694
|
-
const configs = [
|
|
695
|
-
{
|
|
696
|
-
functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func1',
|
|
697
|
-
lambdaConfig: {
|
|
698
|
-
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func1',
|
|
699
|
-
Handler: 'index.handler',
|
|
700
|
-
Runtime: 'nodejs14.x',
|
|
701
|
-
},
|
|
702
|
-
},
|
|
703
|
-
{
|
|
704
|
-
functionARN: 'arn:aws:lambda:us-east-1:000000000000:function:func2',
|
|
705
|
-
lambdaConfig: {
|
|
706
|
-
FunctionArn: 'arn:aws:lambda:us-east-1:000000000000:function:func2',
|
|
707
|
-
Handler: 'index.handler',
|
|
708
|
-
Runtime: 'python3.9',
|
|
709
|
-
},
|
|
710
|
-
},
|
|
711
|
-
];
|
|
712
|
-
expect(commons_1.checkRuntimeTypesAreUniform(configs)).toBe(false);
|
|
713
|
-
}));
|
|
714
|
-
});
|
|
715
|
-
});
|
|
716
|
-
//# sourceMappingURL=commons.test.js.map
|