Skip to content

Commit 4b2302e

Browse files
author
Niranjan Jayakar
committed
pipelines - using capture
1 parent 091b20c commit 4b2302e

File tree

3 files changed

+219
-166
lines changed

3 files changed

+219
-166
lines changed

Diff for: packages/@aws-cdk/pipelines/test/codepipeline/codepipeline-sources.test.ts

+37-38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { anything, arrayWith, Capture, objectLike } from '@aws-cdk/assert-internal';
2-
import '@aws-cdk/assert-internal/jest';
1+
import { Capture, Match, Template } from '@aws-cdk/assertions';
32
import * as ccommit from '@aws-cdk/aws-codecommit';
43
import { CodeCommitTrigger, GitHubTrigger } from '@aws-cdk/aws-codepipeline-actions';
54
import { AnyPrincipal, Role } from '@aws-cdk/aws-iam';
@@ -28,18 +27,18 @@ test('CodeCommit source handles tokenized names correctly', () => {
2827
input: cdkp.CodePipelineSource.codeCommit(repo, 'main'),
2928
});
3029

31-
expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', {
32-
Stages: arrayWith({
30+
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', {
31+
Stages: Match.arrayWith([{
3332
Name: 'Source',
3433
Actions: [
35-
objectLike({
36-
Configuration: objectLike({
37-
RepositoryName: { 'Fn::GetAtt': [anything(), 'Name'] },
34+
Match.objectLike({
35+
Configuration: Match.objectLike({
36+
RepositoryName: { 'Fn::GetAtt': [Match.anyValue(), 'Name'] },
3837
}),
39-
Name: { 'Fn::GetAtt': [anything(), 'Name'] },
38+
Name: { 'Fn::GetAtt': [Match.anyValue(), 'Name'] },
4039
}),
4140
],
42-
}),
41+
}]),
4342
});
4443
});
4544

@@ -58,20 +57,20 @@ test('CodeCommit source honors all valid properties', () => {
5857
}),
5958
});
6059

61-
expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', {
62-
Stages: arrayWith({
60+
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', {
61+
Stages: Match.arrayWith([{
6362
Name: 'Source',
6463
Actions: [
65-
objectLike({
66-
Configuration: objectLike({
64+
Match.objectLike({
65+
Configuration: Match.objectLike({
6766
BranchName: 'main',
6867
PollForSourceChanges: true,
6968
OutputArtifactFormat: 'CODEBUILD_CLONE_REF',
7069
}),
71-
RoleArn: { 'Fn::GetAtt': [anything(), 'Arn'] },
70+
RoleArn: { 'Fn::GetAtt': [Match.anyValue(), 'Arn'] },
7271
}),
7372
],
74-
}),
73+
}]),
7574
});
7675
});
7776

@@ -81,19 +80,19 @@ test('S3 source handles tokenized names correctly', () => {
8180
input: cdkp.CodePipelineSource.s3(buckit, 'thefile.zip'),
8281
});
8382

84-
expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', {
85-
Stages: arrayWith({
83+
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', {
84+
Stages: Match.arrayWith([{
8685
Name: 'Source',
8786
Actions: [
88-
objectLike({
89-
Configuration: objectLike({
90-
S3Bucket: { Ref: anything() },
87+
Match.objectLike({
88+
Configuration: Match.objectLike({
89+
S3Bucket: { Ref: Match.anyValue() },
9190
S3ObjectKey: 'thefile.zip',
9291
}),
93-
Name: { Ref: anything() },
92+
Name: { Ref: Match.anyValue() },
9493
}),
9594
],
96-
}),
95+
}]),
9796
});
9897
});
9998

@@ -105,12 +104,12 @@ test('GitHub source honors all valid properties', () => {
105104
}),
106105
});
107106

108-
expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', {
109-
Stages: arrayWith({
107+
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', {
108+
Stages: Match.arrayWith([{
110109
Name: 'Source',
111110
Actions: [
112-
objectLike({
113-
Configuration: objectLike({
111+
Match.objectLike({
112+
Configuration: Match.objectLike({
114113
Owner: 'owner',
115114
Repo: 'repo',
116115
Branch: 'main',
@@ -120,7 +119,7 @@ test('GitHub source honors all valid properties', () => {
120119
Name: 'owner_repo',
121120
}),
122121
],
123-
}),
122+
}]),
124123
});
125124
});
126125

@@ -145,17 +144,17 @@ test('Dashes in repo names are removed from artifact names', () => {
145144
input: cdkp.CodePipelineSource.gitHub('owner/my-repo', 'main'),
146145
});
147146

148-
expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', {
149-
Stages: arrayWith({
147+
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', {
148+
Stages: Match.arrayWith([{
150149
Name: 'Source',
151150
Actions: [
152-
objectLike({
151+
Match.objectLike({
153152
OutputArtifacts: [
154153
{ Name: 'owner_my_repo_Source' },
155154
],
156155
}),
157156
],
158-
}),
157+
}]),
159158
});
160159
});
161160

@@ -164,19 +163,19 @@ test('artifact names are never longer than 128 characters', () => {
164163
input: cdkp.CodePipelineSource.gitHub('owner/' + 'my-repo'.repeat(100), 'main'),
165164
});
166165

167-
const artifactId = Capture.aString();
168-
expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', {
169-
Stages: arrayWith({
166+
const artifactId = new Capture();
167+
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', {
168+
Stages: Match.arrayWith([{
170169
Name: 'Source',
171170
Actions: [
172-
objectLike({
171+
Match.objectLike({
173172
OutputArtifacts: [
174-
{ Name: artifactId.capture() },
173+
{ Name: artifactId },
175174
],
176175
}),
177176
],
178-
}),
177+
}]),
179178
});
180179

181-
expect(artifactId.capturedValue.length).toBeLessThanOrEqual(128);
180+
expect(artifactId.asString().length).toBeLessThanOrEqual(128);
182181
});

0 commit comments

Comments
 (0)