Skip to content

Commit

Permalink
Adding first unit test for S3BucketOrigin (#31164)
Browse files Browse the repository at this point in the history
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
gracelu0 authored Aug 20, 2024
2 parents 7e2dea7 + c5578ea commit a790a3a
Showing 1 changed file with 28 additions and 0 deletions.
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);
});
});
});

0 comments on commit a790a3a

Please sign in to comment.