/
codebuild-step.test.ts
168 lines (148 loc) · 4.9 KB
/
codebuild-step.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import { Template, Match } from '@aws-cdk/assertions';
import { Duration, Stack } from '@aws-cdk/core';
import * as cdkp from '../../lib';
import { PIPELINE_ENV, TestApp, ModernTestGitHubNpmPipeline, AppWithOutput } from '../testhelpers';
let app: TestApp;
let pipelineStack: Stack;
beforeEach(() => {
app = new TestApp();
pipelineStack = new Stack(app, 'PipelineStack', { env: PIPELINE_ENV });
});
afterEach(() => {
app.cleanup();
});
test('additionalinputs creates the right commands', () => {
// WHEN
new cdkp.CodePipeline(pipelineStack, 'Pipeline', {
synth: new cdkp.CodeBuildStep('Synth', {
commands: ['/bin/true'],
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'),
additionalInputs: {
'some/deep/directory': cdkp.CodePipelineSource.gitHub('test2/test2', 'main'),
},
}),
});
// THEN
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodeBuild::Project', {
Source: {
BuildSpec: Match.serializedJson(Match.objectLike({
phases: {
install: {
commands: [
'[ ! -d "some/deep/directory" ] || { echo \'additionalInputs: "some/deep/directory" must not exist yet. If you want to merge multiple artifacts, use a "cp" command.\'; exit 1; } && mkdir -p -- "some/deep" && ln -s -- "$CODEBUILD_SRC_DIR_test2_test2_Source" "some/deep/directory"',
],
},
},
})),
},
});
});
test('CodeBuild projects have a description', () => {
new cdkp.CodePipeline(pipelineStack, 'Pipeline', {
synth: new cdkp.CodeBuildStep('Synth', {
commands: ['/bin/true'],
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'),
}),
});
// THEN
Template.fromStack(pipelineStack).hasResourceProperties(
'AWS::CodeBuild::Project',
{
Description: 'Pipeline step PipelineStack/Pipeline/Build/Synth',
},
);
});
test('long duration steps are supported', () => {
// WHEN
new cdkp.CodePipeline(pipelineStack, 'Pipeline', {
synth: new cdkp.CodeBuildStep('Synth', {
commands: ['/bin/true'],
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'),
additionalInputs: {
'some/deep/directory': cdkp.CodePipelineSource.gitHub('test2/test2', 'main'),
},
timeout: Duration.minutes(180),
}),
});
// THEN
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodeBuild::Project', {
TimeoutInMinutes: 180,
});
});
test('timeout can be configured as part of defaults', () => {
// WHEN
new cdkp.CodePipeline(pipelineStack, 'Pipeline', {
synth: new cdkp.CodeBuildStep('Synth', {
commands: ['/bin/true'],
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'),
additionalInputs: {
'some/deep/directory': cdkp.CodePipelineSource.gitHub('test2/test2', 'main'),
},
}),
codeBuildDefaults: {
timeout: Duration.minutes(180),
},
});
// THEN
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodeBuild::Project', {
TimeoutInMinutes: 180,
});
});
test('timeout from defaults can be overridden', () => {
// WHEN
new cdkp.CodePipeline(pipelineStack, 'Pipeline', {
synth: new cdkp.CodeBuildStep('Synth', {
commands: ['/bin/true'],
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'),
additionalInputs: {
'some/deep/directory': cdkp.CodePipelineSource.gitHub('test2/test2', 'main'),
},
timeout: Duration.minutes(888),
}),
codeBuildDefaults: {
timeout: Duration.minutes(180),
},
});
// THEN
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodeBuild::Project', {
TimeoutInMinutes: 888,
});
});
test('envFromOutputs works even with very long stage and stack names', () => {
const pipeline = new ModernTestGitHubNpmPipeline(pipelineStack, 'Cdk');
const myApp = new AppWithOutput(app, 'Alpha'.repeat(20), {
stackId: 'Stack'.repeat(20),
});
pipeline.addStage(myApp, {
post: [
new cdkp.ShellStep('Approve', {
commands: ['/bin/true'],
envFromCfnOutputs: {
THE_OUTPUT: myApp.theOutput,
},
}),
],
});
// THEN - did not throw an error about identifier lengths
});
test('variable namespace is set in CodeBuildStep', () => {
// WHEN
const pipeline = new ModernTestGitHubNpmPipeline(pipelineStack, 'Cdk');
const myApp = new AppWithOutput(app, 'VariableNamespaceApp');
const step1 = new cdkp.CodeBuildStep('Synth', {
commands: ['/bin/true'],
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'),
variablesNamespace: 'CodeBuildStep-namespace',
});
const step2 = new cdkp.ShellStep('Approve', {
commands: ['/bin/true'],
variablesNamespace: 'ShellStep-namespace',
});
pipeline.addStage(myApp, {
pre: [step1],
post: [step2],
});
// THEN
expect(step1.variable('test')).toEqual('#{CodeBuildStep-namespace.test}');
expect(step2.variable('test')).toEqual('#{ShellStep-namespace.test}');
});