Skip to content

Commit

Permalink
fixing/adding tests for aws resources
Browse files Browse the repository at this point in the history
  • Loading branch information
corymhall committed Sep 6, 2024
1 parent da9f689 commit 2480f3e
Showing 1 changed file with 123 additions and 9 deletions.
132 changes: 123 additions & 9 deletions tests/aws-resource-mappings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@ import * as aws from '@pulumi/aws';

jest.mock('@pulumi/aws', () => {
return {
autoscaling: {
Group: jest.fn().mockImplementation(() => {
apigatewayv2: {
Integration: jest.fn().mockImplementation(() => {
return {};
}),
},
iam: {
Policy: jest.fn().mockImplementation(() => {
return {};
}),
UserPolicyAttachment: jest.fn().mockImplementation(() => {
return {};
}),
RolePolicyAttachment: jest.fn().mockImplementation(() => {
return {};
}),
GroupPolicyAttachment: jest.fn().mockImplementation(() => {
return {};
}),
},
Expand All @@ -22,13 +36,99 @@ beforeAll(() => {
});

describe('AWS Resource Mappings', () => {
test('maps autoscaling.Group props', () => {
test('maps iam.Policy', () => {
// GIVEN
const cfnType = 'AWS::IAM::Policy';
const logicalId = 'my-resource';
const cfnProps = {
PolicyDocument: {
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Action: ['cloudformation:Describe*', 'cloudformation:List*', 'cloudformation:Get*'],
Resource: '*',
},
],
},
Groups: ['my-group'],
Roles: ['my-role'],
Users: ['my-user'],
};
// WHEN
mapToAwsResource(
new CfnResource(new Stack(), logicalId, {
type: cfnType,
properties: cfnProps,
}),
logicalId,
cfnType,
cfnProps,
{},
);
// THEN
expect(aws.iam.Policy).toHaveBeenCalledWith(
logicalId,
expect.objectContaining({
policy: {
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Action: ['cloudformation:Describe*', 'cloudformation:List*', 'cloudformation:Get*'],
Resource: '*',
},
],
},
}),
{},
);
expect(aws.iam.GroupPolicyAttachment).toHaveBeenCalledWith(
`${logicalId}-0`,
expect.objectContaining({
group: 'my-group',
policyArn: undefined,
}),
{},
);
expect(aws.iam.RolePolicyAttachment).toHaveBeenCalledWith(
`${logicalId}-0`,
expect.objectContaining({
role: 'my-role',
policyArn: undefined,
}),
{},
);
expect(aws.iam.UserPolicyAttachment).toHaveBeenCalledWith(
`${logicalId}-0`,
expect.objectContaining({
user: 'my-user',
policyArn: undefined,
}),
{},
);
});
test('maps apigatewayv2.Integration', () => {
// GIVEN
const cfnType = 'AWS::AutoScaling::AutoScalingGroup';
const cfnType = 'AWS::ApiGatewayV2::Integration';
const logicalId = 'my-resource';
const cfnProps = {
TargetGroupARNs: ['arn'],
VPCZoneIdentifier: ['ids'],
Description: 'Lambda Integration',
IntegrationType: 'AWS_PROXY',
RequestParameters: {
'append:header.header1': '$context.requestId',
},
ResponseParameters: {
'200': {
ResponseParameters: [
{
Source: 'headervalue',
Destination: 'append:header.header2',
},
],
},
},
TlsConfig: { ServerNameToVerify: 'example.com' },
};
// WHEN
mapToAwsResource(
Expand All @@ -42,11 +142,25 @@ describe('AWS Resource Mappings', () => {
{},
);
// THEN
expect(aws.autoscaling.Group).toHaveBeenCalledWith(
expect(aws.apigatewayv2.Integration).toHaveBeenCalledWith(
logicalId,
expect.objectContaining({
targetGroupArns: ['arn'],
vpcZoneIdentifiers: ['ids'],
description: 'Lambda Integration',
integrationType: 'AWS_PROXY',
requestParameters: {
'append:header.header1': '$context.requestId',
},
responseParameters: {
'200': {
ResponseParameters: [
{
Source: 'headervalue',
Destination: 'append:header.header2',
},
],
},
},
tlsConfig: { insecureSkipVerification: true },
}),
{},
);
Expand Down

0 comments on commit 2480f3e

Please sign in to comment.