mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Introduce logical id naming function
This commit is contained in:
parent
3cede35cc9
commit
3d2879ef56
@ -291,6 +291,9 @@ module.exports = {
|
||||
getApiGatewayLogGroupLogicalId() {
|
||||
return 'ApiGatewayLogGroup';
|
||||
},
|
||||
getApiGatewayAccountCloudWatchRoleResourceLogicalId() {
|
||||
return 'ApiGatewayAccountCloudWatchRole';
|
||||
},
|
||||
|
||||
// S3
|
||||
getDeploymentBucketLogicalId() {
|
||||
|
||||
@ -456,6 +456,14 @@ describe('#naming()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getApiGatewayAccountCloudWatchRoleResourceLogicalId()', () => {
|
||||
it('should return the API Gateway account CloudWatch role logical id', () => {
|
||||
expect(sdk.naming.getApiGatewayAccountCloudWatchRoleResourceLogicalId()).to.equal(
|
||||
'ApiGatewayAccountCloudWatchRole'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getDeploymentBucketLogicalId()', () => {
|
||||
it('should return "ServerlessDeploymentBucket"', () => {
|
||||
expect(sdk.naming.getDeploymentBucketLogicalId()).to.equal('ServerlessDeploymentBucket');
|
||||
|
||||
@ -6,6 +6,7 @@ const { addCustomResourceToService } = require('../../../../customResources');
|
||||
|
||||
module.exports = memoize(provider => {
|
||||
const cfTemplate = provider.serverless.service.provider.compiledCloudFormationTemplate;
|
||||
const logicalId = provider.naming.getApiGatewayAccountCloudWatchRoleResourceLogicalId();
|
||||
const customResourceLogicalId = provider.naming.getCustomResourceApiGatewayAccountCloudWatchRoleResourceLogicalId();
|
||||
const customResourceFunctionLogicalId = provider.naming.getCustomResourceApiGatewayAccountCloudWatchRoleHandlerFunctionLogicalId();
|
||||
|
||||
@ -15,7 +16,7 @@ module.exports = memoize(provider => {
|
||||
const configuredRoleArn = restApi && restApi.role;
|
||||
|
||||
if (configuredRoleArn) {
|
||||
cfTemplate.Resources.apiGatewayCloudWatchRole = {
|
||||
cfTemplate.Resources[logicalId] = {
|
||||
Type: 'AWS::ApiGateway::Account',
|
||||
Properties: {
|
||||
CloudWatchRoleArn: configuredRoleArn,
|
||||
|
||||
@ -14,6 +14,7 @@ describe('ensureApiGatewayCloudWatchRole', () => {
|
||||
let resources;
|
||||
let addCustomResourceToServiceStub;
|
||||
let ensureApiGatewayCloudWatchRole;
|
||||
const logicalId = 'Id';
|
||||
const customResourceLogicalId = 'CustomResourceId';
|
||||
|
||||
beforeEach(() => {
|
||||
@ -35,6 +36,7 @@ describe('ensureApiGatewayCloudWatchRole', () => {
|
||||
},
|
||||
},
|
||||
naming: {
|
||||
getApiGatewayAccountCloudWatchRoleResourceLogicalId: () => logicalId,
|
||||
getCustomResourceApiGatewayAccountCloudWatchRoleResourceLogicalId: () =>
|
||||
customResourceLogicalId,
|
||||
getCustomResourceApiGatewayAccountCloudWatchRoleHandlerFunctionLogicalId: () => 'bar',
|
||||
@ -53,7 +55,7 @@ describe('ensureApiGatewayCloudWatchRole', () => {
|
||||
return expect(ensureApiGatewayCloudWatchRole(provider)).to.eventually.be.fulfilled.then(
|
||||
() => {
|
||||
expect(_.isObject(resources[customResourceLogicalId])).to.equal(false);
|
||||
expect(_.isObject(resources.apiGatewayCloudWatchRole)).to.equal(true);
|
||||
expect(_.isObject(resources[logicalId])).to.equal(true);
|
||||
}
|
||||
);
|
||||
});
|
||||
@ -74,6 +76,7 @@ describe('ensureApiGatewayCloudWatchRole', () => {
|
||||
it('Should ensure custom resource on template', () => {
|
||||
return expect(ensureApiGatewayCloudWatchRole(provider)).to.eventually.be.fulfilled.then(
|
||||
() => {
|
||||
expect(_.isObject(resources[logicalId])).to.equal(false);
|
||||
expect(_.isObject(resources[customResourceLogicalId])).to.equal(true);
|
||||
}
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user