Skip to content

Commit

Permalink
fixing some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iliapolo committed Mar 1, 2020
1 parent 335cfd9 commit d6c89b9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export class PhysicalResourceId {
/**
* Construct a resource id from an explicit id.
*/
public static fromLiteralString(literalId: string): PhysicalResourceId {
return new PhysicalResourceId(undefined, literalId);
public static of(id: string): PhysicalResourceId {
return new PhysicalResourceId(undefined, id);
}

/**
* @param responsePath Path to a response data element to be used as the physical id.
* @param literalId Literal string to be used as the physical id.
* @param id Literal string to be used as the physical id.
*/
private constructor(public readonly responsePath?: string, public readonly literalId?: string) { }
private constructor(public readonly responsePath?: string, public readonly id?: string) { }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent
let physicalResourceId: string;
switch (event.RequestType) {
case 'Create':
physicalResourceId = event.ResourceProperties.Create?.physicalResourceId.id ??
event.ResourceProperties.Update?.physicalResourceId.id ??
event.ResourceProperties.Delete?.physicalResourceId.id ??
physicalResourceId = event.ResourceProperties.Create?.physicalResourceId?.id ??
event.ResourceProperties.Update?.physicalResourceId?.id ??
event.ResourceProperties.Delete?.physicalResourceId?.id ??
event.LogicalResourceId;
break;
case 'Update':
case 'Delete':
physicalResourceId = event.ResourceProperties[event.RequestType]?.physicalResourceId.id ?? event.PhysicalResourceId;
physicalResourceId = event.ResourceProperties[event.RequestType]?.physicalResourceId?.id ?? event.PhysicalResourceId;
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as AWS from 'aws-sdk-mock';
import * as fs from 'fs-extra';
import * as nock from 'nock';
import * as sinon from 'sinon';
import { AwsSdkCall } from '../../lib';
import { AwsSdkCall, PhysicalResourceId } from '../../lib';
import { flatten, handler } from '../../lib/aws-custom-resource/runtime';

AWS.setSDK(require.resolve('aws-sdk'));
Expand Down Expand Up @@ -62,7 +62,7 @@ test('create event with physical resource id path', async () => {
parameters: {
Bucket: 'my-bucket'
},
physicalResourceIdPath: 'Contents.1.ETag'
physicalResourceId: PhysicalResourceId.fromResponsePath('Contents.1.ETag')
} as AwsSdkCall
}
};
Expand Down Expand Up @@ -101,7 +101,7 @@ test('update event with physical resource id', async () => {
Message: 'hello',
TopicArn: 'topicarn'
},
physicalResourceId: 'topicarn'
physicalResourceId: PhysicalResourceId.of('topicarn')
} as AwsSdkCall
}
};
Expand Down Expand Up @@ -133,7 +133,7 @@ test('delete event', async () => {
parameters: {
Bucket: 'my-bucket'
},
physicalResourceIdPath: 'Contents.1.ETag'
physicalResourceId: PhysicalResourceId.fromResponsePath('Contents.1.ETag')
} as AwsSdkCall
}
};
Expand Down Expand Up @@ -236,7 +236,7 @@ test('catch errors', async () => {
parameters: {
Bucket: 'my-bucket'
},
physicalResourceId: 'physicalResourceId',
physicalResourceId: PhysicalResourceId.of('physicalResourceId'),
catchErrorPattern: 'NoSuchBucket'
} as AwsSdkCall
}
Expand Down Expand Up @@ -283,7 +283,7 @@ test('decodes booleans', async () => {
},
}
},
physicalResourceId: 'put-item'
physicalResourceId: PhysicalResourceId.of('put-item')
} as AwsSdkCall
}
};
Expand Down Expand Up @@ -342,7 +342,7 @@ test('restrict output path', async () => {
parameters: {
Bucket: 'my-bucket'
},
physicalResourceId: 'id',
physicalResourceId: PhysicalResourceId.of('id'),
outputPath: 'Contents.0'
} as AwsSdkCall
}
Expand Down Expand Up @@ -379,7 +379,7 @@ test('can specify apiVersion and region', async () => {
},
apiVersion: '2010-03-31',
region: 'eu-west-1',
physicalResourceId: 'id',
physicalResourceId: PhysicalResourceId.of('id'),
} as AwsSdkCall
}
};
Expand Down Expand Up @@ -433,7 +433,7 @@ test('installs the latest SDK', async () => {
Message: 'message',
TopicArn: 'topic'
},
physicalResourceId: 'id',
physicalResourceId: PhysicalResourceId.of('id'),
} as AwsSdkCall
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('aws sdk js custom resource with onCreate and onDelete', () => {
logGroupName: '/aws/lambda/loggroup',
retentionInDays: 90
},
physicalResourceId: PhysicalResourceId.fromLiteralString('loggroup')
physicalResourceId: PhysicalResourceId.of('loggroup')
},
onDelete: {
service: 'CloudWatchLogs',
Expand All @@ -39,7 +39,9 @@ test('aws sdk js custom resource with onCreate and onDelete', () => {
"logGroupName": "/aws/lambda/loggroup",
"retentionInDays": 90
},
"physicalResourceId": "loggroup"
"physicalResourceId": {
"id": "loggroup"
}
},
"Delete": {
"service": "CloudWatchLogs",
Expand Down Expand Up @@ -98,7 +100,9 @@ test('onCreate defaults to onUpdate', () => {
"Key": "my-key",
"Body": "my-body"
},
"physicalResourceIdPath": "ETag"
"physicalResourceId": {
"responsePath": "ETag"
}
},
"Update": {
"service": "s3",
Expand All @@ -108,7 +112,9 @@ test('onCreate defaults to onUpdate', () => {
"Key": "my-key",
"Body": "my-body"
},
"physicalResourceIdPath": "ETag"
"physicalResourceId": {
"responsePath": "ETag"
}
},
});
});
Expand Down Expand Up @@ -188,7 +194,7 @@ test('encodes booleans', () => {
falseBoolean: false,
falseString: 'false'
},
physicalResourceId: PhysicalResourceId.fromResponsePath('id')
physicalResourceId: PhysicalResourceId.of('id')
},
});

Expand All @@ -203,7 +209,9 @@ test('encodes booleans', () => {
"falseBoolean": "FALSE:BOOLEAN",
"falseString": "false"
},
"physicalResourceId": "id"
"physicalResourceId": {
"id": "id"
}
},
});
});
Expand All @@ -217,7 +225,7 @@ test('timeout defaults to 2 minutes', () => {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.fromLiteralString('id')
physicalResourceId: PhysicalResourceId.of('id')
}
});

Expand All @@ -236,7 +244,7 @@ test('can specify timeout', () => {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.fromLiteralString('id')
physicalResourceId: PhysicalResourceId.of('id')
},
timeout: cdk.Duration.minutes(15)
});
Expand All @@ -257,7 +265,7 @@ test('implements IGrantable', () => {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.fromLiteralString('id')
physicalResourceId: PhysicalResourceId.of('id')
}
});

Expand Down Expand Up @@ -298,7 +306,7 @@ test('can use existing role', () => {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.fromLiteralString('id')
physicalResourceId: PhysicalResourceId.of('id')
},
role
});
Expand All @@ -318,7 +326,7 @@ test('getData', () => {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.fromLiteralString('id')
physicalResourceId: PhysicalResourceId.of('id')
}
});

Expand All @@ -341,7 +349,7 @@ test('getDataString', () => {
onCreate: {
service: 'service',
action: 'action',
physicalResourceId: PhysicalResourceId.fromLiteralString('id')
physicalResourceId: PhysicalResourceId.of('id')
}
});

Expand All @@ -353,7 +361,7 @@ test('getDataString', () => {
parameters: {
a: awsSdk.getDataString('Data')
},
physicalResourceId: PhysicalResourceId.fromLiteralString('id')
physicalResourceId: PhysicalResourceId.of('id')
}
});

Expand All @@ -370,7 +378,9 @@ test('getDataString', () => {
]
}
},
physicalResourceId: 'id'
physicalResourceId: {
"id": 'id'
}
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const snsPublish = new AwsCustomResource(stack, 'Publish', {
Message: 'hello',
TopicArn: topic.topicArn
},
physicalResourceId: PhysicalResourceId.fromLiteralString(topic.topicArn),
physicalResourceId: PhysicalResourceId.of(topic.topicArn),
}
});

Expand Down

0 comments on commit d6c89b9

Please sign in to comment.