Skip to content

Commit

Permalink
change unit tests
Browse files Browse the repository at this point in the history
add unit test
  • Loading branch information
go-to-k committed Feb 25, 2024
1 parent 74820d8 commit dd62773
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/aws-cdk-lib/aws-codepipeline/lib/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,14 @@ export class Trigger {
}

pushFilter?.forEach(filter => {
if (!filter.branchesExcludes && !filter.branchesIncludes && (filter.filePathsExcludes || filter.filePathsIncludes)) {
throw new Error(`cannot specify filePaths without branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`);
}
if ((filter.tagsExcludes || filter.tagsIncludes) && (filter.branchesExcludes || filter.branchesIncludes)) {
throw new Error(`cannot specify both tags and branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`);
}
if (!filter.branchesExcludes && !filter.branchesIncludes && (filter.filePathsExcludes || filter.filePathsIncludes)) {
throw new Error(`cannot specify filePaths without branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`);
if (!filter.tagsExcludes && !filter.tagsIncludes && !filter.branchesExcludes && !filter.branchesIncludes) {
throw new Error(`must specify either tags or branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`);
}
if (filter.tagsExcludes && filter.tagsExcludes.length > 8) {
throw new Error(`maximum length of tagsExcludes in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}' is 8, got ${filter.tagsExcludes.length}`);
Expand Down
15 changes: 15 additions & 0 deletions packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,21 @@ describe('triggers', () => {
}).toThrow(/cannot specify both tags and branches in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction'/);
});

test('throw if neither tags nor branches are specified in pushFilter', () => {
expect(() => {
new codepipeline.Pipeline(stack, 'Pipeline', {
pipelineType: codepipeline.PipelineType.V2,
triggers: [{
providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION,
gitConfiguration: {
sourceAction,
pushFilter: [{}],
},
}],
});
}).toThrow(/must specify either tags or branches in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction'/);
});

test('throw if filePaths without branches is specified in pushFilter', () => {
expect(() => {
new codepipeline.Pipeline(stack, 'Pipeline', {
Expand Down

0 comments on commit dd62773

Please sign in to comment.