Skip to content

Commit

Permalink
Wrap NamespaceType enum
Browse files Browse the repository at this point in the history
also moar tests
  • Loading branch information
SoManyHs committed Apr 2, 2019
1 parent 92a3072 commit b73d2e9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
11 changes: 8 additions & 3 deletions packages/@aws-cdk/aws-ecs/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ export class Cluster extends cdk.Construct implements ICluster {

const namespaceType = options.type !== undefined
? options.type
: cloudmap.NamespaceType.DnsPrivate;
: NamespaceType.PrivateDns;

const sdNamespace = namespaceType === cloudmap.NamespaceType.DnsPrivate ?
const sdNamespace = namespaceType === NamespaceType.PrivateDns ?
new cloudmap.PrivateDnsNamespace(this, 'DefaultServiceDiscoveryNamespace', {
name: options.name,
vpc: this.vpc
Expand Down Expand Up @@ -446,7 +446,7 @@ export interface NamespaceOptions {
*
* @default PrivateDns
*/
readonly type?: cloudmap.NamespaceType.DnsPrivate | cloudmap.NamespaceType.DnsPublic;
readonly type?: NamespaceType

/**
* The Amazon VPC that you want to associate the namespace with. Required for Private DNS namespaces
Expand All @@ -455,3 +455,8 @@ export interface NamespaceOptions {
*/
readonly vpc?: ec2.IVpcNetwork;
}

export enum NamespaceType {
PrivateDns = cloudmap.NamespaceType.DnsPrivate,
PublicDns = cloudmap.NamespaceType.DnsPublic
}
10 changes: 5 additions & 5 deletions packages/@aws-cdk/aws-ecs/test/ec2/test.ec2-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cloudmap = require('@aws-cdk/aws-servicediscovery');
import cdk = require('@aws-cdk/cdk');
import { Test } from 'nodeunit';
import ecs = require('../../lib');
import { BinPackResource, BuiltInAttributes, ContainerImage, NetworkMode } from '../../lib';
import { BinPackResource, BuiltInAttributes, ContainerImage, NamespaceType, NetworkMode } from '../../lib';

export = {
"When creating an ECS Service": {
Expand Down Expand Up @@ -606,7 +606,7 @@ export = {
// WHEN
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DnsPrivate
type: NamespaceType.PrivateDns
});

new ecs.Ec2Service(stack, 'Service', {
Expand Down Expand Up @@ -683,7 +683,7 @@ export = {
// WHEN
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DnsPrivate
type: NamespaceType.PrivateDns
});

new ecs.Ec2Service(stack, 'Service', {
Expand Down Expand Up @@ -794,7 +794,7 @@ export = {
// WHEN
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DnsPrivate
type: NamespaceType.PrivateDns
});

new ecs.Ec2Service(stack, 'Service', {
Expand Down Expand Up @@ -869,7 +869,7 @@ export = {
// WHEN
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DnsPrivate
type: NamespaceType.PrivateDns
});

new ecs.Ec2Service(stack, 'Service', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import cloudmap = require('@aws-cdk/aws-servicediscovery');
import cdk = require('@aws-cdk/cdk');
import { Test } from 'nodeunit';
import ecs = require('../../lib');
import { ContainerImage } from '../../lib';
import { ContainerImage, NamespaceType } from '../../lib';

export = {
"When creating a Fargate Service": {
Expand Down Expand Up @@ -281,7 +281,7 @@ export = {
// WHEN
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DnsPrivate
type: NamespaceType.PrivateDns
});

new ecs.FargateService(stack, 'Service', {
Expand Down Expand Up @@ -341,7 +341,7 @@ export = {
// WHEN
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DnsPrivate
type: NamespaceType.PrivateDns
});

new ecs.FargateService(stack, 'Service', {
Expand Down
25 changes: 25 additions & 0 deletions packages/@aws-cdk/aws-ecs/test/test.ecs-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,29 @@ export = {

test.done();
},

"throws if default service discovery namespace added more than once"(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {});

const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
cluster.addCapacity('DefaultAutoScalingGroup', {
instanceType: new ec2.InstanceType('t2.micro'),
});

// WHEN
cluster.addDefaultCloudMapNamespace({
name: "foo.com"
});

// THEN
test.throws(() => {
cluster.addDefaultCloudMapNamespace({
name: "foo.com"
});
}, /Can only add default namespace once./);

test.done();
},
};

0 comments on commit b73d2e9

Please sign in to comment.