Skip to content

Commit

Permalink
Improve initialization, add test for absent
Browse files Browse the repository at this point in the history
  • Loading branch information
msambol committed Apr 6, 2024
1 parent fd3537b commit 0ea9435
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ taskDefinition.addContainer('container', {

## Docker labels

You can add labels to the container with the `dockerLabels` prop or `addDockerLabel`:
You can add labels to the container with the `dockerLabels` property or with the `addDockerLabel` method:

```ts
declare const taskDefinition: ecs.TaskDefinition;
Expand Down
6 changes: 1 addition & 5 deletions packages/aws-cdk-lib/aws-ecs/lib/container-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,7 @@ export class ContainerDefinition extends Construct {
}
}

if (props.dockerLabels) {
this.dockerLabels = { ...props.dockerLabels };
} else {
this.dockerLabels = {};
}
this.dockerLabels = { ...props.dockerLabels };

if (props.environment) {
this.environment = { ...props.environment };
Expand Down
21 changes: 21 additions & 0 deletions packages/aws-cdk-lib/aws-ecs/test/container-definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,27 @@ describe('container definition', () => {
});
});

test('docker labels should be absent if not supplied', () => {
// GIVEN
const stack = new cdk.Stack();
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef');

// WHEN
taskDefinition.addContainer('cont', {
image: ecs.ContainerImage.fromRegistry('test'),
memoryLimitMiB: 1024,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', {
ContainerDefinitions: [
Match.objectLike({
DockerLabels: Match.absent(),
}),
],
});
});

test('can add environment variables to the container definition', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit 0ea9435

Please sign in to comment.