Skip to content

Commit dd62773

Browse files
committed
change unit tests
add unit test
1 parent 74820d8 commit dd62773

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

packages/aws-cdk-lib/aws-codepipeline/lib/trigger.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,14 @@ export class Trigger {
166166
}
167167

168168
pushFilter?.forEach(filter => {
169+
if (!filter.branchesExcludes && !filter.branchesIncludes && (filter.filePathsExcludes || filter.filePathsIncludes)) {
170+
throw new Error(`cannot specify filePaths without branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`);
171+
}
169172
if ((filter.tagsExcludes || filter.tagsIncludes) && (filter.branchesExcludes || filter.branchesIncludes)) {
170173
throw new Error(`cannot specify both tags and branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`);
171174
}
172-
if (!filter.branchesExcludes && !filter.branchesIncludes && (filter.filePathsExcludes || filter.filePathsIncludes)) {
173-
throw new Error(`cannot specify filePaths without branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`);
175+
if (!filter.tagsExcludes && !filter.tagsIncludes && !filter.branchesExcludes && !filter.branchesIncludes) {
176+
throw new Error(`must specify either tags or branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`);
174177
}
175178
if (filter.tagsExcludes && filter.tagsExcludes.length > 8) {
176179
throw new Error(`maximum length of tagsExcludes in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}' is 8, got ${filter.tagsExcludes.length}`);

packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,21 @@ describe('triggers', () => {
584584
}).toThrow(/cannot specify both tags and branches in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction'/);
585585
});
586586

587+
test('throw if neither tags nor branches are specified in pushFilter', () => {
588+
expect(() => {
589+
new codepipeline.Pipeline(stack, 'Pipeline', {
590+
pipelineType: codepipeline.PipelineType.V2,
591+
triggers: [{
592+
providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
593+
gitConfiguration: {
594+
sourceAction,
595+
pushFilter: [{}],
596+
},
597+
}],
598+
});
599+
}).toThrow(/must specify either tags or branches in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction'/);
600+
});
601+
587602
test('throw if filePaths without branches is specified in pushFilter', () => {
588603
expect(() => {
589604
new codepipeline.Pipeline(stack, 'Pipeline', {

0 commit comments

Comments
 (0)