Skip to content

Commit

Permalink
fix build error
Browse files Browse the repository at this point in the history
  • Loading branch information
atsushi-ishibashi committed Feb 25, 2020
1 parent 99ecc57 commit fba4573
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 86 deletions.
46 changes: 14 additions & 32 deletions packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,29 +265,22 @@ export interface IBaseService extends IService {
/**
* The properties to import from the service.
*/
export interface BaseServiceAttributes {
export interface ImportedBaseServiceProps {
/**
* The cluster that hosts the service.
*/
readonly cluster: ICluster;

/**
* The service ARN.
*
* @default - generated from serviceName
*/
readonly serviceArn?: string;

/**
* The name of the service.
*
* @default - generated from serviceArn
*/
readonly serviceName?: string;
readonly serviceName: string;
}

/**
* A Service that has been imported
*
* @resource AWS::ECS::Service
*/
export class ImportedBaseService extends Resource implements IBaseService {
/**
Expand All @@ -308,30 +301,19 @@ export class ImportedBaseService extends Resource implements IBaseService {
/**
* Constructs a new instance of the ImportedBaseService class.
*/
constructor(scope: Construct, id: string, props: BaseServiceAttributes) {
constructor(scope: Construct, id: string, props: ImportedBaseServiceProps) {
super(scope, id);
if ((props.serviceArn && props.serviceName) || (!props.serviceArn && !props.serviceName)) {
throw new Error('You can only specify either serviceArn or serviceName.');
}
const stack = Stack.of(scope);
let name: string;
let arn: string;
if (props.serviceName) {
name = props.serviceName as string;
arn = stack.formatArn({
partition: stack.partition,
service: 'ecs',
region: stack.region,
account: stack.account,
resource: 'service',
resourceName: name,
});
} else {
arn = props.serviceArn as string;
name = stack.parseArn(arn).resourceName as string;
}
const arn: string = stack.formatArn({
partition: stack.partition,
service: 'ecs',
region: stack.region,
account: stack.account,
resource: 'service',
resourceName: props.serviceName,
});
this.serviceArn = arn;
this.serviceName = name;
this.serviceName = props.serviceName;
this.cluster = props.cluster;
}
}
Expand Down
60 changes: 6 additions & 54 deletions packages/@aws-cdk/aws-ecs/test/base/test.base-service.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,23 @@
import * as ecs from '@aws-cdk/aws-ecs';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { Cluster } from '../../lib';
import { ImportedBaseService } from '../../lib/base/base-service';

export = {
'BaseService': {
'can be imported by serviceArn'(test: Test) {
BaseService: {
'can be imported'(test: Test) {
const stack = new cdk.Stack();
const cluster = new ecs.Cluster(stack, 'Cluster', {
const cluster = new Cluster(stack, 'Cluster', {
clusterName: 'cluster',
})

test.doesNotThrow(() => {
new ImportedBaseService(stack, 'BaseService', {
serviceArn: 'arn:aws:ecs:us-west-2:123456789012:service/my-http-service',
cluster: cluster,
});
});

test.done();
},

'can be imported by serviceName'(test: Test) {
const stack = new cdk.Stack();
const cluster = new ecs.Cluster(stack, 'Cluster', {
clusterName: 'cluster',
})

test.doesNotThrow(() => {
new ImportedBaseService(stack, 'BaseService', {
new ImportedBaseService(stack, 'FargateService', {
serviceName: 'my-http-service',
cluster: cluster,
cluster,
});
});

test.done();
},

'throws an exception if neither serviceName nor serviceArn were provided'(test: Test) {
const stack = new cdk.Stack();
const cluster = new ecs.Cluster(stack, 'Cluster', {
clusterName: 'cluster',
})

test.throws(() => {
new ImportedBaseService(stack, 'BaseService', {
cluster: cluster,
});
}, /only specify either serviceArn or serviceName/);

test.done();
},

'throws an exception if both serviceName and serviceArn were provided'(test: Test) {
const stack = new cdk.Stack();
const cluster = new ecs.Cluster(stack, 'Cluster', {
clusterName: 'cluster',
})

test.throws(() => {
new ImportedBaseService(stack, 'BaseService', {
serviceArn: 'arn:aws:ecs:us-west-2:123456789012:service/my-http-service',
serviceName: 'my-http-service',
cluster: cluster,
});
}, /only specify either serviceArn or serviceName/);

test.done();
},
},
Expand Down

0 comments on commit fba4573

Please sign in to comment.