-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding first unit test for S3BucketOrigin (#31164)
There will be more unit tests to come. This first one verifies that correct number of resources are created when re-using an OAC across two Distributions.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
packages/aws-cdk-lib/aws-cloudfront-origins/test/s3-bucket-origin.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Template } from '../../assertions'; | ||
import * as cloudfront from '../../aws-cloudfront/index'; | ||
import * as origins from '../../aws-cloudfront-origins'; | ||
import * as s3 from '../../aws-s3/index'; | ||
import { Stack } from '../../core'; | ||
|
||
describe('S3BucketOrigin', () => { | ||
describe('withOriginAccessControl', () => { | ||
test('origin can be used by multiple Distributions', () => { | ||
const stack = new Stack(); | ||
const bucket = new s3.Bucket(stack, 'MyBucket'); | ||
const origin = origins.S3BucketOrigin.withOriginAccessControl(bucket); | ||
|
||
new cloudfront.Distribution(stack, 'MyDistributionA', { | ||
defaultBehavior: { origin: origin }, | ||
}); | ||
new cloudfront.Distribution(stack, 'MyDistributionB', { | ||
defaultBehavior: { origin: origin }, | ||
}); | ||
|
||
const template = Template.fromStack(stack); | ||
template.resourceCountIs('AWS::CloudFront::OriginAccessControl', 1); | ||
template.resourceCountIs('AWS::CloudFront::Distribution', 2); | ||
template.resourceCountIs('AWS::S3::Bucket', 1); | ||
template.resourceCountIs('AWS::S3::BucketPolicy', 1); | ||
}); | ||
}); | ||
}); |