From 8f0d1ce9f758a456882bd017671fe21c4aa2219d Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Sun, 25 Feb 2024 21:24:55 +0900 Subject: [PATCH] change unit tests --- .../aws-cdk-lib/aws-codepipeline/lib/trigger.ts | 7 +++++-- .../aws-codepipeline/test/triggers.test.ts | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/aws-cdk-lib/aws-codepipeline/lib/trigger.ts b/packages/aws-cdk-lib/aws-codepipeline/lib/trigger.ts index 01115ca3b5389..1ae801927b5e0 100644 --- a/packages/aws-cdk-lib/aws-codepipeline/lib/trigger.ts +++ b/packages/aws-cdk-lib/aws-codepipeline/lib/trigger.ts @@ -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}`); diff --git a/packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts b/packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts index 51378dacf7648..a4d5dca2d991b 100644 --- a/packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts +++ b/packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts @@ -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', { @@ -593,6 +608,7 @@ describe('triggers', () => { gitConfiguration: { sourceAction, pushFilter: [{ + tagsExcludes: ['exclude1', 'exclude2'], filePathsExcludes: ['exclude1', 'exclude2'], }], },