Skip to content

Commit

Permalink
change unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k committed Feb 25, 2024
1 parent 74820d8 commit 8f0d1ce
Show file tree
Hide file tree
Showing 2 changed files with 21 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
16 changes: 16 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 All @@ -593,6 +608,7 @@ describe('triggers', () => {
gitConfiguration: {
sourceAction,
pushFilter: [{
tagsExcludes: ['exclude1', 'exclude2'],
filePathsExcludes: ['exclude1', 'exclude2'],
}],
},
Expand Down

0 comments on commit 8f0d1ce

Please sign in to comment.