|
1 | 1 | 'use strict'; |
2 | 2 |
|
| 3 | +const _ = require('lodash'); |
3 | 4 | const expect = require('chai').expect; |
4 | 5 | const Serverless = require('serverless/lib/Serverless'); |
5 | 6 | const AwsProvider = require('serverless/lib/plugins/aws/provider/awsProvider'); |
@@ -596,6 +597,28 @@ describe('#compileStateMachines', () => { |
596 | 597 | }, |
597 | 598 | MessageBody: 'This is a static message', |
598 | 599 | }, |
| 600 | + Next: 'Fargate', |
| 601 | + }, |
| 602 | + Fargate: { |
| 603 | + Type: 'Task', |
| 604 | + Resource: 'arn:aws:states:::ecs:runTask.waitForTaskToken', |
| 605 | + Parameters: { |
| 606 | + LaunchType: 'FARGATE', |
| 607 | + Cluster: { |
| 608 | + Ref: 'ActivityCluster', |
| 609 | + }, |
| 610 | + NetworkConfiguration: { |
| 611 | + AwsvpcConfiguration: { |
| 612 | + AssignPublicIp: 'ENABLED', |
| 613 | + SecurityGroups: [{ |
| 614 | + Ref: 'ActivitySecurityGroup', |
| 615 | + }], |
| 616 | + Subnets: [{ |
| 617 | + Ref: 'ActivitySubnet', |
| 618 | + }], |
| 619 | + }, |
| 620 | + }, |
| 621 | + }, |
599 | 622 | Next: 'Parallel', |
600 | 623 | }, |
601 | 624 | Parallel: { |
@@ -633,34 +656,38 @@ describe('#compileStateMachines', () => { |
633 | 656 | const [json, params] = stateMachine.Properties.DefinitionString['Fn::Sub']; |
634 | 657 | const modifiedDefinition = JSON.parse(json); |
635 | 658 |
|
636 | | - const lambda = modifiedDefinition.States.Lambda; |
637 | | - expect(lambda.Resource.startsWith('${')).to.eq(true); |
638 | | - const functionParam = lambda.Resource.replace(/[${}]/g, ''); |
639 | | - expect(params).to.haveOwnProperty(functionParam); |
640 | | - expect(params[functionParam]).to.eql({ Ref: 'MyFunction' }); |
641 | | - |
642 | | - const sns = modifiedDefinition.States.Sns; |
643 | | - expect(sns.Parameters.Message.startsWith('${')).to.eq(true); |
644 | | - const topicNameParam = sns.Parameters.Message.replace(/[${}]/g, ''); |
645 | | - expect(params).to.haveOwnProperty(topicNameParam); |
646 | | - expect(params[topicNameParam]).to.eql({ 'Fn::GetAtt': ['MyTopic', 'TopicName'] }); |
647 | | - expect(sns.Parameters.TopicArn.startsWith('${')).to.eq(true); |
648 | | - const topicArnParam = sns.Parameters.TopicArn.replace(/[${}]/g, ''); |
649 | | - expect(params).to.haveOwnProperty(topicArnParam); |
650 | | - expect(params[topicArnParam]).to.eql({ Ref: 'MyTopic' }); |
651 | | - |
652 | | - const sqs = modifiedDefinition.States.Sqs; |
653 | | - expect(sqs.Parameters.QueueUrl.startsWith('${')).to.eq(true); |
654 | | - const queueUrlParam = sqs.Parameters.QueueUrl.replace(/[${}]/g, ''); |
655 | | - expect(params[queueUrlParam]).to.eql({ Ref: 'MyQueue' }); |
656 | | - |
657 | | - const parallel = modifiedDefinition.States.Parallel; |
658 | | - expect(parallel.Branches).to.have.lengthOf(1); |
659 | | - const lambda2 = parallel.Branches[0].States.Lambda2; |
660 | | - expect(lambda2.Resource.startsWith('${')).to.eq(true); |
661 | | - const functionParam2 = lambda2.Resource.replace(/[${}]/g, ''); |
662 | | - expect(params).to.haveOwnProperty(functionParam2); |
663 | | - expect(params[functionParam2]).to.eql({ Ref: 'MyFunction2' }); |
| 659 | + const hasParam = (state, path, expected) => { |
| 660 | + const attr = _.get(state, path); |
| 661 | + expect(attr.startsWith('${')).to.eq(true); |
| 662 | + const paramName = attr.replace(/[${}]/g, ''); |
| 663 | + expect(params).to.haveOwnProperty(paramName); |
| 664 | + expect(params[paramName]).to.eql(expected); |
| 665 | + }; |
| 666 | + |
| 667 | + hasParam(modifiedDefinition.States.Lambda, 'Resource', { |
| 668 | + Ref: 'MyFunction', |
| 669 | + }); |
| 670 | + hasParam(modifiedDefinition.States.Sns, 'Parameters.Message', { |
| 671 | + 'Fn::GetAtt': ['MyTopic', 'TopicName'], |
| 672 | + }); |
| 673 | + hasParam(modifiedDefinition.States.Sns, 'Parameters.TopicArn', { |
| 674 | + Ref: 'MyTopic', |
| 675 | + }); |
| 676 | + hasParam(modifiedDefinition.States.Sqs, 'Parameters.QueueUrl', { |
| 677 | + Ref: 'MyQueue', |
| 678 | + }); |
| 679 | + hasParam(modifiedDefinition.States.Fargate, 'Parameters.Cluster', { |
| 680 | + Ref: 'ActivityCluster', |
| 681 | + }); |
| 682 | + hasParam(modifiedDefinition.States.Fargate, 'Parameters.NetworkConfiguration.AwsvpcConfiguration.SecurityGroups.0', { |
| 683 | + Ref: 'ActivitySecurityGroup', |
| 684 | + }); |
| 685 | + hasParam(modifiedDefinition.States.Fargate, 'Parameters.NetworkConfiguration.AwsvpcConfiguration.Subnets.0', { |
| 686 | + Ref: 'ActivitySubnet', |
| 687 | + }); |
| 688 | + hasParam(modifiedDefinition.States.Parallel, 'Branches.0.States.Lambda2.Resource', { |
| 689 | + Ref: 'MyFunction2', |
| 690 | + }); |
664 | 691 | }); |
665 | 692 |
|
666 | 693 | it('should allow null values #193', () => { |
|
0 commit comments