@mbc-cqrs-serverless/cli 0.1.25-beta.0 → 0.1.26-beta.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/package.json +2 -2
- package/templates/gitignore +3 -1
- package/templates/infra/jest.config.js +4 -0
- package/templates/infra/libs/build-app.ts +7 -4
- package/templates/infra/libs/pipeline-stack.ts +3 -3
- package/templates/infra/package.json +1 -0
- package/templates/infra/test/__snapshots__/infra.test.ts.snap +2392 -0
- package/templates/infra/test/infra.test.ts +81 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Murakami Business Consulting, Inc. All rights are reserved.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as cdk from 'aws-cdk-lib'
|
|
6
|
+
import { Template } from 'aws-cdk-lib/assertions'
|
|
7
|
+
import { getConfig } from '../config'
|
|
8
|
+
import { InfraStack } from '../libs/infra-stack'
|
|
9
|
+
|
|
10
|
+
jest.mock('crypto', () => ({
|
|
11
|
+
...jest.requireActual('crypto'),
|
|
12
|
+
randomBytes: jest.fn(() => Buffer.from('e380014717dda68f930961c8fdcde7')),
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
jest.mock('aws-cdk-lib', () => ({
|
|
16
|
+
...jest.requireActual('aws-cdk-lib'),
|
|
17
|
+
Duration: {
|
|
18
|
+
days: jest.fn(() => ({
|
|
19
|
+
toMilliseconds: jest.fn(() => 365 * 24 * 60 * 60 * 1000), // Mock milliseconds for 365 days
|
|
20
|
+
})),
|
|
21
|
+
hours: jest.fn(() => ({
|
|
22
|
+
minutes: jest.fn(() => 365 * 24 * 60),
|
|
23
|
+
toSeconds: jest.fn(() => 365 * 24 * 60 * 60),
|
|
24
|
+
})),
|
|
25
|
+
minutes: jest.fn(() => ({
|
|
26
|
+
toSeconds: jest.fn(() => 365 * 24 * 60),
|
|
27
|
+
})),
|
|
28
|
+
seconds: jest.fn(() => ({
|
|
29
|
+
toSeconds: jest.fn(() => 365 * 24 * 60 * 60),
|
|
30
|
+
})),
|
|
31
|
+
},
|
|
32
|
+
Expiration: {
|
|
33
|
+
after: jest.fn(() => ({
|
|
34
|
+
isBefore: jest.fn(() => false),
|
|
35
|
+
isAfter: jest.fn(() => false),
|
|
36
|
+
toEpoch: jest.fn(() => 1762419954),
|
|
37
|
+
})),
|
|
38
|
+
},
|
|
39
|
+
}))
|
|
40
|
+
|
|
41
|
+
function replaceKeyValue(obj: any, desKey: string, desVal: string): any {
|
|
42
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
43
|
+
return obj
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (const key in obj) {
|
|
47
|
+
if (obj.hasOwnProperty(key)) {
|
|
48
|
+
if (key === desKey) {
|
|
49
|
+
obj[key] = desVal
|
|
50
|
+
} else if (typeof obj[key] === 'object') {
|
|
51
|
+
obj[key] = replaceKeyValue(obj[key], desKey, desVal)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return obj
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
test('snapshot test for InfraStack', () => {
|
|
60
|
+
const cdkEnv: cdk.Environment = {
|
|
61
|
+
account: '101010101010',
|
|
62
|
+
region: 'ap-northeast-1',
|
|
63
|
+
}
|
|
64
|
+
const config = getConfig('dev')
|
|
65
|
+
const app = new cdk.App()
|
|
66
|
+
const stack = new InfraStack(app, 'TestInfraStack', { env: cdkEnv, config })
|
|
67
|
+
let template = Template.fromStack(stack).toJSON()
|
|
68
|
+
template = replaceKeyValue(
|
|
69
|
+
template,
|
|
70
|
+
'S3Key',
|
|
71
|
+
`${Array(64).fill('x').join('')}.zip`,
|
|
72
|
+
)
|
|
73
|
+
template = replaceKeyValue(
|
|
74
|
+
template,
|
|
75
|
+
'Fn::Sub',
|
|
76
|
+
'101010101010.dkr.ecr.xxxxxxxxxxxx.${AWS::URLSuffix}/cdk-hnb659fds-container-assets-101010101010-xxxxxxxxxxxx:' +
|
|
77
|
+
Array(64).fill('x').join(''),
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
expect(template).toMatchSnapshot()
|
|
81
|
+
})
|