Skip to content

Commit 8164808

Browse files
author
Cameron Magee
committed
test: multi component support in unit tests
1 parent d926136 commit 8164808

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

src/index.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ export class ImagePipeline extends Construct {
125125

126126
infrastructureConfig.addDependsOn(profile);
127127

128-
// const component = new imagebuilder.CfnComponent(this, 'Component', {
129-
// name: props.componentName,
130-
// platform: props.platform ?? 'Linux',
131-
// version: '1.0.0',
132-
// data: readFileSync(props.componentDocPath).toString(),
133-
// });
134-
135128
const imageRecipe = new imagebuilder.CfnImageRecipe(this, 'ImageRecipe', {
136129
components: [],
137130
name: props.imageRecipe,
@@ -143,7 +136,7 @@ export class ImagePipeline extends Construct {
143136
let component = new imagebuilder.CfnComponent(this, props.componentNames[index], {
144137
name: props.componentNames[index],
145138
platform: props.platform ?? 'Linux',
146-
version: props.componentVersions[index],
139+
version: props.componentVersions[index] ?? '0.0.1',
147140
data: readFileSync(document).toString(),
148141
});
149142

test/imagepipeline.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { ImagePipeline, ImagePipelineProps } from '../src';
55
let template: Template;
66

77
const props: ImagePipelineProps = {
8-
componentDocuments: ['test/test_component_example.yml'],
9-
componentNames: ['TestComponent'],
8+
componentDocuments: ['test/test_component_example.yml', 'test/test_component_example_2.yml'],
9+
componentNames: ['TestComponent', 'TestComponent2'],
1010
componentVersions: ['1.0.0'],
1111
profileName: 'TestProfile',
1212
infraConfigName: 'TestInfrastructureConfig',
@@ -67,7 +67,6 @@ test('Infrastructure Configuration IAM Role and Instance Profile are created', (
6767
});
6868

6969
test('IAM Role contains necessary permission set', () => {
70-
console.log(template.findResources);
7170
template.hasResourceProperties('AWS::IAM::Role',
7271
Match.anyValue());
7372
});
@@ -111,7 +110,7 @@ test.skip('Infrastructure Configuration DependsOn Instance Profile', () => {
111110
});
112111

113112
test('Image Builder Component is created', () => {
114-
template.resourceCountIs('AWS::ImageBuilder::Component', 1);
113+
template.resourceCountIs('AWS::ImageBuilder::Component', props.componentDocuments.length);
115114
});
116115

117116
test('Image Recipe is created', () => {

test/test_component_example_2.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: ComponentExample
2+
description: This is an example component document
3+
schemaVersion: 1.0
4+
5+
phases:
6+
- name: build
7+
steps:
8+
- name: InstallUpdates
9+
action: UpdateOS
10+
- name: DownloadSomeShellScriptFromS3
11+
action: S3Download
12+
inputs:
13+
- source: 's3://some-bucket/some_shell_script.sh'
14+
destination: '/tmp/some_shell_script.sh'
15+
- name: validate
16+
steps:
17+
- name: HelloWorldStep
18+
action: ExecuteBash
19+
inputs:
20+
commands:
21+
- echo "Hello World! Validate."
22+
- name: test
23+
steps:
24+
- name: HelloWorldStep
25+
action: ExecuteBash
26+
inputs:
27+
commands:
28+
- echo "Hello World! Test.

0 commit comments

Comments
 (0)