-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathinteg.canary.ts
140 lines (127 loc) · 4.5 KB
/
integ.canary.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/// !cdk-integ canary-one
import * as path from 'path';
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
import * as s3 from 'aws-cdk-lib/aws-s3';
import * as cdk from 'aws-cdk-lib/core';
import { Canary, Cleanup, Code, Runtime, Schedule, Test } from 'aws-cdk-lib/aws-synthetics';
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha';
import { RemovalPolicy } from 'aws-cdk-lib';
const app = new cdk.App();
const stack = new cdk.Stack(app, 'canary-one');
const bucket = new s3.Bucket(stack, 'MyTestBucket', {
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
});
const prefix = 'integ';
const api = new apigateway.RestApi(stack, 'ApiGateway');
api.root.addMethod('GET', new apigateway.MockIntegration({
integrationResponses: [{
statusCode: '200',
}],
passthroughBehavior: apigateway.PassthroughBehavior.NEVER,
requestTemplates: {
'application/json': '{ "statusCode": 200 }',
},
}), {
methodResponses: [{ statusCode: '200' }],
});
const inlineAsset = new Canary(stack, 'InlineAsset', {
test: Test.custom({
handler: 'index.handler',
code: Code.fromInline(`
exports.handler = async () => {
console.log(\'hello world\');
};`),
}),
schedule: Schedule.rate(cdk.Duration.minutes(1)),
artifactsBucketLocation: { bucket, prefix },
runtime: Runtime.SYNTHETICS_NODEJS_PUPPETEER_7_0,
cleanup: Cleanup.LAMBDA,
});
const directoryAsset = new Canary(stack, 'DirectoryAsset', {
test: Test.custom({
handler: 'canary.handler',
code: Code.fromAsset(path.join(__dirname, 'canaries')),
}),
runtime: Runtime.SYNTHETICS_NODEJS_PUPPETEER_7_0,
environmentVariables: {
URL: api.url,
},
cleanup: Cleanup.LAMBDA,
});
const folderAsset = new Canary(stack, 'FolderAsset', {
test: Test.custom({
handler: 'folder/canary.functionName',
code: Code.fromAsset(path.join(__dirname, 'canaries')),
}),
runtime: Runtime.SYNTHETICS_NODEJS_PUPPETEER_7_0,
environmentVariables: {
URL: api.url,
},
cleanup: Cleanup.LAMBDA,
});
const zipAsset = new Canary(stack, 'ZipAsset', {
test: Test.custom({
handler: 'canary.handler',
code: Code.fromAsset(path.join(__dirname, 'canary.zip')),
}),
artifactsBucketLifecycleRules: [
{
expiration: cdk.Duration.days(30),
},
],
runtime: Runtime.SYNTHETICS_NODEJS_PUPPETEER_7_0,
cleanup: Cleanup.LAMBDA,
});
const kebabToPascal = (text:string) => text.replace(/(^\w|[-./]\w)/g, (v) => v.replace(/[-./]/, '').toUpperCase());
const createCanaryByRuntimes = (runtime: Runtime, handler?: string) =>
new Canary(stack, kebabToPascal(runtime.name + (handler ?? '')), {
test: Test.custom({
handler: handler ?? 'canary.handler',
code: Code.fromAsset(path.join(__dirname, 'canaries')),
}),
environmentVariables: {
URL: api.url,
},
runtime,
cleanup: Cleanup.LAMBDA,
});
const puppeteer52 = createCanaryByRuntimes(Runtime.SYNTHETICS_NODEJS_PUPPETEER_5_2);
const puppeteer62 = createCanaryByRuntimes(Runtime.SYNTHETICS_NODEJS_PUPPETEER_6_2);
const puppeteer70 = createCanaryByRuntimes(Runtime.SYNTHETICS_NODEJS_PUPPETEER_7_0);
const puppeteer80 = createCanaryByRuntimes(Runtime.SYNTHETICS_NODEJS_PUPPETEER_8_0);
const puppeteer90 = createCanaryByRuntimes(Runtime.SYNTHETICS_NODEJS_PUPPETEER_9_0);
const puppeteer91 = createCanaryByRuntimes(Runtime.SYNTHETICS_NODEJS_PUPPETEER_9_1);
const playwright10 = createCanaryByRuntimes(Runtime.SYNTHETICS_NODEJS_PLAYWRIGHT_1_0);
const playwright10_with_handler_name = createCanaryByRuntimes(Runtime.SYNTHETICS_NODEJS_PLAYWRIGHT_1_0, 'playwright/canary.handler');
const selenium21 = createCanaryByRuntimes(Runtime.SYNTHETICS_PYTHON_SELENIUM_2_1);
const selenium30 = createCanaryByRuntimes(Runtime.SYNTHETICS_PYTHON_SELENIUM_3_0);
const selenium40 = createCanaryByRuntimes(Runtime.SYNTHETICS_PYTHON_SELENIUM_4_0);
const selenium41 = createCanaryByRuntimes(Runtime.SYNTHETICS_PYTHON_SELENIUM_4_1);
const test = new IntegTest(app, 'IntegCanaryTest', {
testCases: [stack],
});
// Assertion that all Canary's are Passed
[
inlineAsset,
directoryAsset,
folderAsset,
zipAsset,
puppeteer52,
puppeteer62,
puppeteer70,
puppeteer80,
puppeteer90,
puppeteer91,
playwright10,
playwright10_with_handler_name,
selenium21,
selenium30,
selenium40,
selenium41,
].forEach((canary) => test.assertions
.awsApiCall('Synthetics', 'getCanaryRuns', {
Name: canary.canaryName,
})
.assertAtPath('CanaryRuns.0.Status.State', ExpectedResult.stringLikeRegexp('PASSED'))
.waitForAssertions({ totalTimeout: cdk.Duration.minutes(5) }));