|
1 | | -import { expect } from '@aws-cdk/assert'; |
| 1 | +import '@aws-cdk/assert/jest'; |
2 | 2 | import * as cdk from '@aws-cdk/core'; |
3 | | -import { nodeunitShim, Test } from 'nodeunit-shim'; |
4 | 3 | import { OriginAccessIdentity } from '../lib'; |
5 | 4 |
|
6 | | -/* eslint-disable quote-props */ |
7 | | - |
8 | | -nodeunitShim({ |
9 | | - 'Origin Access Identity with automatic comment'(test: Test) { |
| 5 | +describe('Origin Access Identity', () => { |
| 6 | + test('With automatic comment', () => { |
10 | 7 | const stack = new cdk.Stack(); |
11 | 8 |
|
12 | 9 | new OriginAccessIdentity(stack, 'OAI'); |
13 | 10 |
|
14 | | - expect(stack).toMatch( |
| 11 | + expect(stack).toMatchTemplate( |
15 | 12 | { |
16 | | - 'Resources': { |
17 | | - 'OAIE1EFC67F': { |
18 | | - 'Type': 'AWS::CloudFront::CloudFrontOriginAccessIdentity', |
19 | | - 'Properties': { |
20 | | - 'CloudFrontOriginAccessIdentityConfig': { |
21 | | - 'Comment': 'Allows CloudFront to reach the bucket', |
| 13 | + Resources: { |
| 14 | + OAIE1EFC67F: { |
| 15 | + Type: 'AWS::CloudFront::CloudFrontOriginAccessIdentity', |
| 16 | + Properties: { |
| 17 | + CloudFrontOriginAccessIdentityConfig: { |
| 18 | + Comment: 'Allows CloudFront to reach the bucket', |
22 | 19 | }, |
23 | 20 | }, |
24 | 21 | }, |
25 | 22 | }, |
26 | 23 | }, |
27 | 24 | ); |
| 25 | + }); |
28 | 26 |
|
29 | | - test.done(); |
30 | | - }, |
31 | | - 'Origin Access Identity with comment'(test: Test) { |
| 27 | + test('With provided comment', () => { |
32 | 28 | const stack = new cdk.Stack(); |
33 | 29 |
|
34 | 30 | new OriginAccessIdentity(stack, 'OAI', { |
35 | 31 | comment: 'test comment', |
36 | 32 | }); |
37 | 33 |
|
38 | | - expect(stack).toMatch( |
| 34 | + expect(stack).toMatchTemplate( |
39 | 35 | { |
40 | | - 'Resources': { |
41 | | - 'OAIE1EFC67F': { |
42 | | - 'Type': 'AWS::CloudFront::CloudFrontOriginAccessIdentity', |
43 | | - 'Properties': { |
44 | | - 'CloudFrontOriginAccessIdentityConfig': { |
45 | | - 'Comment': 'test comment', |
| 36 | + Resources: { |
| 37 | + OAIE1EFC67F: { |
| 38 | + Type: 'AWS::CloudFront::CloudFrontOriginAccessIdentity', |
| 39 | + Properties: { |
| 40 | + CloudFrontOriginAccessIdentityConfig: { |
| 41 | + Comment: 'test comment', |
46 | 42 | }, |
47 | 43 | }, |
48 | 44 | }, |
49 | 45 | }, |
50 | 46 | }, |
51 | 47 | ); |
| 48 | + }); |
| 49 | + |
| 50 | + test('Truncates long comments', () => { |
| 51 | + const stack = new cdk.Stack(); |
| 52 | + |
| 53 | + new OriginAccessIdentity(stack, 'OAI', { |
| 54 | + comment: 'This is a really long comment. Auto-generated comments based on ids of origins might sometimes be this long or even longer and that will break', |
| 55 | + }); |
52 | 56 |
|
53 | | - test.done(); |
54 | | - }, |
| 57 | + expect(stack).toHaveResourceLike('AWS::CloudFront::CloudFrontOriginAccessIdentity', { |
| 58 | + CloudFrontOriginAccessIdentityConfig: { |
| 59 | + Comment: 'This is a really long comment. Auto-generated comments based on ids of origins might sometimes be this long or even longer and t', |
| 60 | + }, |
| 61 | + }); |
| 62 | + }); |
55 | 63 |
|
56 | | - 'Builds ARN of CloudFront user'(test: Test) { |
| 64 | + test('Builds ARN of CloudFront user', () => { |
57 | 65 | const stack = new cdk.Stack(); |
58 | 66 |
|
59 | 67 | const oai = OriginAccessIdentity.fromOriginAccessIdentityName(stack, 'OAI', 'OAITest'); |
60 | 68 |
|
61 | | - test.ok( |
62 | | - oai.grantPrincipal.policyFragment.principalJson.AWS[0].endsWith( |
63 | | - ':iam::cloudfront:user/CloudFront Origin Access Identity OAITest', |
64 | | - ), |
65 | | - ); |
66 | | - |
67 | | - test.done(); |
68 | | - }, |
| 69 | + expect(oai.grantPrincipal.policyFragment.principalJson.AWS[0]).toMatch(/:iam::cloudfront:user\/CloudFront Origin Access Identity OAITest$/); |
| 70 | + }); |
69 | 71 | }); |
0 commit comments