Skip to content

Commit

Permalink
Added unit tests and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Schmid committed Jun 21, 2017
1 parent ceee071 commit 29046f4
Show file tree
Hide file tree
Showing 3 changed files with 465 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/removeAlias.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ module.exports = {
if (err.message === NO_UPDATE_MESSAGE) {
return BbPromise.resolve([ currentTemplate, aliasStackTemplates, currentAliasStackTemplate ]);
}
throw new this._serverless.classes.Error(err);
throw err;
});

},
Expand All @@ -207,10 +207,10 @@ module.exports = {
.catch(e => {
if (_.includes(e.message, 'does not exist')) {
const message = `Alias ${this._alias} is not deployed.`;
throw new this._serverless.classes.Error(new Error(message));
throw new this._serverless.classes.Error(message);
}

throw new this._serverless.classes.Error(e);
throw e;
});

},
Expand Down
205 changes: 205 additions & 0 deletions test/data/alias-stack-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Alias stack for sls-test-project-dev (myAlias)",
"Resources": {
"ServerlessAliasLogGroup": {
"Type": "AWS::Logs::LogGroup",
"Properties": {
"LogGroupName": "/serverless/sls-test-project-dev-myAlias",
"RetentionInDays": 7
}
},
"Testfct1Alias": {
"Type": "AWS::Lambda::Alias",
"Properties": {
"Description": "Echo function echoes alias",
"FunctionName": {
"Fn::ImportValue": "sls-test-project-dev-Testfct1-LambdaFunctionArn"
},
"FunctionVersion": {
"Fn::GetAtt": [
"Testfct1LambdaVersionWh5jTkiTR67V05RPWQIlzPI25WiPbdHDYNgbtAMneU",
"Version"
]
},
"Name": "myAlias"
},
"DependsOn": [
"Testfct1LambdaVersionWh5jTkiTR67V05RPWQIlzPI25WiPbdHDYNgbtAMneU"
]
},
"WarmUpPluginAlias": {
"Type": "AWS::Lambda::Alias",
"Properties": {
"Description": "Serverless WarmUP Plugin",
"FunctionName": {
"Fn::ImportValue": "sls-test-project-dev-WarmUpPlugin-LambdaFunctionArn"
},
"FunctionVersion": {
"Fn::GetAtt": [
"WarmUpPluginLambdaVersionWh5jTkiTR67V05RPWQIlzPI25WiPbdHDYNgbtAMneU",
"Version"
]
},
"Name": "myAlias"
},
"DependsOn": [
"WarmUpPluginLambdaVersionWh5jTkiTR67V05RPWQIlzPI25WiPbdHDYNgbtAMneU"
]
},
"Testfct1LambdaVersionWh5jTkiTR67V05RPWQIlzPI25WiPbdHDYNgbtAMneU": {
"Type": "AWS::Lambda::Version",
"DeletionPolicy": "Delete",
"Properties": {
"FunctionName": {
"Fn::ImportValue": "sls-test-project-dev-Testfct1-LambdaFunctionArn"
},
"CodeSha256": "Wh5jTkiTR67+V05RPWQIlzPI25WiPbdHDYNgbtAMneU=",
"Description": "Echo function echoes alias"
}
},
"WarmUpPluginLambdaVersionWh5jTkiTR67V05RPWQIlzPI25WiPbdHDYNgbtAMneU": {
"Type": "AWS::Lambda::Version",
"DeletionPolicy": "Delete",
"Properties": {
"FunctionName": {
"Fn::ImportValue": "sls-test-project-dev-WarmUpPlugin-LambdaFunctionArn"
},
"CodeSha256": "Wh5jTkiTR67+V05RPWQIlzPI25WiPbdHDYNgbtAMneU=",
"Description": "Serverless WarmUP Plugin"
}
},
"ApiGatewayDeployment1494367071211": {
"Type": "AWS::ApiGateway::Deployment",
"Properties": {
"RestApiId": {
"Fn::ImportValue": "sls-test-project-dev-ApiGatewayRestApi"
}
},
"DependsOn": []
},
"ApiGatewayStage": {
"Type": "AWS::ApiGateway::Stage",
"Properties": {
"StageName": "myAlias",
"DeploymentId": {
"Ref": "ApiGatewayDeployment1494367071211"
},
"RestApiId": {
"Fn::ImportValue": "sls-test-project-dev-ApiGatewayRestApi"
},
"Variables": {
"SERVERLESS_ALIAS": "myAlias",
"SERVERLESS_STAGE": "dev"
}
},
"DependsOn": [
"ApiGatewayDeployment1494367071211"
]
},
"Testfct1LambdaPermissionApiGateway": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": {
"Ref": "Testfct1Alias"
},
"Action": "lambda:InvokeFunction",
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
"Fn::Join": [
"",
[
"arn:aws:execute-api:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":",
{
"Fn::ImportValue": "sls-test-project-dev-ApiGatewayRestApi"
},
"/*/*"
]
]
}
},
"DependsOn": [
"Testfct1LambdaVersionWh5jTkiTR67V05RPWQIlzPI25WiPbdHDYNgbtAMneU",
"Testfct1Alias"
]
},
"WarmUpPluginEventsRuleSchedule1": {
"Type": "AWS::Events::Rule",
"Properties": {
"ScheduleExpression": "rate(5 minutes)",
"State": "ENABLED",
"Targets": [
{
"Arn": {
"Ref": "WarmUpPluginAlias"
},
"Id": "warmUpPluginSchedule"
}
]
},
"DependsOn": [
"WarmUpPluginAlias"
]
},
"WarmUpPluginLambdaPermissionEventsRuleSchedule1": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": {
"Ref": "WarmUpPluginAlias"
},
"Action": "lambda:InvokeFunction",
"Principal": "events.amazonaws.com",
"SourceArn": {
"Fn::GetAtt": [
"WarmUpPluginEventsRuleSchedule1",
"Arn"
]
}
},
"DependsOn": [
"WarmUpPluginAlias"
]
}
},
"Outputs": {
"ServerlessAliasName": {
"Description": "Alias the stack represents.",
"Value": "myStage"
},
"ServerlessAliasLogGroup": {
"Description": "Log group for alias.",
"Value": {
"Ref": "ServerlessAliasLogGroup"
},
"Export": {
"Name": "sls-test-project-dev-myAlias-LogGroup"
}
},
"AliasFlags": {
"Description": "Alias flags.",
"Value": "{\"hasRole\":false}"
},
"AliasResources": {
"Description": "Custom resource references",
"Value": "[]"
},
"AliasOutputs": {
"Description": "Custom output references",
"Value": "[]"
},
"ServerlessAliasReference": {
"Description": "Alias stack reference.",
"Value": {
"Fn::ImportValue": "sls-test-project-dev-ServerlessAliasReference"
}
}
}
}
Loading

0 comments on commit 29046f4

Please sign in to comment.