Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hencrice committed Mar 20, 2020
1 parent 9edfd74 commit 44effbf
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.l3s-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ export = {
}
}));

expect(stack).notTo(haveResourceLike('AWS::ServiceDiscovery::Service', {
DnsConfig: {
DnsRecords: [
{
Type: "A"
}
]
}
}));

test.done();
},

Expand Down
73 changes: 73 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.l3s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,44 @@ export = {
test.done();
},

'test ECS loadbalanced construct with private load balancer'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') });

// WHEN
new ecsPatterns.ApplicationLoadBalancedEc2Service(stack, 'Service', {
cluster,
memoryLimitMiB: 1024,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('test'),
environment: {
TEST_ENVIRONMENT_VARIABLE1: "test environment variable 1 value",
TEST_ENVIRONMENT_VARIABLE2: "test environment variable 2 value"
}
},
desiredCount: 2,
publicLoadBalancer: false,
});

// THEN - stack contains a load balancer and a service
expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::LoadBalancer'));

expect(stack).notTo(haveResourceLike('AWS::ServiceDiscovery::Service', {
DnsConfig: {
DnsRecords: [
{
Type: "A"
}
]
}
}));

test.done();
},

'set vpc instead of cluster'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down Expand Up @@ -336,6 +374,41 @@ export = {
test.done();
},

'test Fargate loadbalanced construct with private load balancer'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });

// WHEN
new ecsPatterns.ApplicationLoadBalancedFargateService(stack, 'Service', {
cluster,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('test'),
environment: {
TEST_ENVIRONMENT_VARIABLE1: "test environment variable 1 value",
TEST_ENVIRONMENT_VARIABLE2: "test environment variable 2 value"
}
},
desiredCount: 2,
publicLoadBalancer: false,
});

// THEN - stack contains a load balancer and a service
expect(stack).to(haveResource('AWS::ElasticLoadBalancingV2::LoadBalancer'));
expect(stack).notTo(haveResourceLike('AWS::ServiceDiscovery::Service', {
DnsConfig: {
DnsRecords: [
{
Type: "A"
}
]
}
}));

test.done();
},

'test Fargate loadbalanced construct opting out of log driver creation'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit 44effbf

Please sign in to comment.