From 55fa3ec511e478424b425f605d3fb5ac41946a47 Mon Sep 17 00:00:00 2001 From: go-to-k <24818752+go-to-k@users.noreply.github.com> Date: Sun, 18 Feb 2024 01:56:49 +0900 Subject: [PATCH] add unit tests --- .../aws-codepipeline/test/triggers.test.ts | 308 +++++++++++++++++- 1 file changed, 305 insertions(+), 3 deletions(-) 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 335667f0d17a4..5b31cff65a0e5 100644 --- a/packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts +++ b/packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts @@ -28,7 +28,7 @@ describe('triggers', () => { }); }); - test('can specify triggers', () => { + test('can specify triggers with tags', () => { const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', { pipelineType: codepipeline.PipelineType.V2, triggers: [{ @@ -62,6 +62,80 @@ describe('triggers', () => { }); }); + test('can specify triggers with branches', () => { + const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', { + pipelineType: codepipeline.PipelineType.V2, + triggers: [{ + providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION, + gitConfiguration: { + sourceAction, + pushFilter: [{ + branchesExcludes: ['exclude1', 'exclude2'], + branchesIncludes: ['include1', 'include2'], + }], + }, + }], + }); + + testPipelineSetup(pipeline, [sourceAction], [buildAction]); + + Template.fromStack(stack).hasResourceProperties('AWS::CodePipeline::Pipeline', { + PipelineType: 'V2', + Triggers: [{ + GitConfiguration: { + SourceActionName: 'CodeStarConnectionsSourceAction', + Push: [{ + Branches: { + Excludes: ['exclude1', 'exclude2'], + Includes: ['include1', 'include2'], + }, + }], + }, + ProviderType: 'CodeStarSourceConnection', + }], + }); + }); + + test('can specify triggers with branches and file paths', () => { + const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', { + pipelineType: codepipeline.PipelineType.V2, + triggers: [{ + providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION, + gitConfiguration: { + sourceAction, + pushFilter: [{ + branchesExcludes: ['exclude1', 'exclude2'], + branchesIncludes: ['include1', 'include2'], + filePathsExcludes: ['exclude1', 'exclude2'], + filePathsIncludes: ['include1', 'include2'], + }], + }, + }], + }); + + testPipelineSetup(pipeline, [sourceAction], [buildAction]); + + Template.fromStack(stack).hasResourceProperties('AWS::CodePipeline::Pipeline', { + PipelineType: 'V2', + Triggers: [{ + GitConfiguration: { + SourceActionName: 'CodeStarConnectionsSourceAction', + Push: [{ + Branches: { + Excludes: ['exclude1', 'exclude2'], + Includes: ['include1', 'include2'], + }, + FilePaths: { + Excludes: ['exclude1', 'exclude2'], + Includes: ['include1', 'include2'], + }, + }], + }, + ProviderType: 'CodeStarSourceConnection', + }], + }); + }); + test('can specify multiple triggers', () => { const sourceArtifact2 = new codepipeline.Artifact(); const sourceAction2 = new CodeStarConnectionsSourceAction({ @@ -232,7 +306,155 @@ describe('triggers', () => { }); }); - test('throw if length of excludes is greater than 8', () => { + test('empty branchesExcludes for trigger is set to undefined', () => { + const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', { + pipelineType: codepipeline.PipelineType.V2, + triggers: [{ + providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION, + gitConfiguration: { + sourceAction, + pushFilter: [{ + branchesExcludes: [], + branchesIncludes: ['include1', 'include2'], + }], + }, + }], + }); + + testPipelineSetup(pipeline, [sourceAction], [buildAction]); + + Template.fromStack(stack).hasResourceProperties('AWS::CodePipeline::Pipeline', { + PipelineType: 'V2', + Triggers: [{ + GitConfiguration: { + SourceActionName: 'CodeStarConnectionsSourceAction', + Push: [{ + Branches: { + Excludes: Match.absent(), + Includes: ['include1', 'include2'], + }, + }], + }, + ProviderType: 'CodeStarSourceConnection', + }], + }); + }); + + test('empty branchesIncludes for trigger is set to undefined', () => { + const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', { + pipelineType: codepipeline.PipelineType.V2, + triggers: [{ + providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION, + gitConfiguration: { + sourceAction, + pushFilter: [{ + branchesExcludes: ['excluded1', 'excluded2'], + branchesIncludes: [], + }], + }, + }], + }); + + testPipelineSetup(pipeline, [sourceAction], [buildAction]); + + Template.fromStack(stack).hasResourceProperties('AWS::CodePipeline::Pipeline', { + PipelineType: 'V2', + Triggers: [{ + GitConfiguration: { + SourceActionName: 'CodeStarConnectionsSourceAction', + Push: [{ + Branches: { + Excludes: ['excluded1', 'excluded2'], + Includes: Match.absent(), + }, + }], + }, + ProviderType: 'CodeStarSourceConnection', + }], + }); + }); + + test('empty filePathsExcludes for trigger is set to undefined', () => { + const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', { + pipelineType: codepipeline.PipelineType.V2, + triggers: [{ + providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION, + gitConfiguration: { + sourceAction, + pushFilter: [{ + branchesExcludes: ['exclude1', 'exclude2'], + branchesIncludes: ['include1', 'include2'], + filePathsExcludes: [], + filePathsIncludes: ['include1', 'include2'], + }], + }, + }], + }); + + testPipelineSetup(pipeline, [sourceAction], [buildAction]); + + Template.fromStack(stack).hasResourceProperties('AWS::CodePipeline::Pipeline', { + PipelineType: 'V2', + Triggers: [{ + GitConfiguration: { + SourceActionName: 'CodeStarConnectionsSourceAction', + Push: [{ + Branches: { + Excludes: ['exclude1', 'exclude2'], + Includes: ['include1', 'include2'], + }, + FilePaths: { + Excludes: Match.absent(), + Includes: ['include1', 'include2'], + }, + }], + }, + ProviderType: 'CodeStarSourceConnection', + }], + }); + }); + + test('empty filePathsIncludes for trigger is set to undefined', () => { + const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', { + pipelineType: codepipeline.PipelineType.V2, + triggers: [{ + providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION, + gitConfiguration: { + sourceAction, + pushFilter: [{ + branchesExcludes: ['exclude1', 'exclude2'], + branchesIncludes: ['include1', 'include2'], + filePathsExcludes: ['exclude1', 'exclude2'], + filePathsIncludes: [], + }], + }, + }], + }); + + testPipelineSetup(pipeline, [sourceAction], [buildAction]); + + Template.fromStack(stack).hasResourceProperties('AWS::CodePipeline::Pipeline', { + PipelineType: 'V2', + Triggers: [{ + GitConfiguration: { + SourceActionName: 'CodeStarConnectionsSourceAction', + Push: [{ + Branches: { + Excludes: ['exclude1', 'exclude2'], + Includes: ['include1', 'include2'], + }, + FilePaths: { + Excludes: ['exclude1', 'exclude2'], + Includes: Match.absent(), + }, + }], + }, + ProviderType: 'CodeStarSourceConnection', + }], + }); + }); + + test('throw if length of tagsExcludes is greater than 8', () => { expect(() => { new codepipeline.Pipeline(stack, 'Pipeline', { pipelineType: codepipeline.PipelineType.V2, @@ -250,7 +472,7 @@ describe('triggers', () => { }).toThrow(/maximum length of tagsExcludes in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/); }); - test('throw if length of excludes is greater than 8', () => { + test('throw if length of tagsIncludes is greater than 8', () => { expect(() => { new codepipeline.Pipeline(stack, 'Pipeline', { pipelineType: codepipeline.PipelineType.V2, @@ -268,6 +490,86 @@ describe('triggers', () => { }).toThrow(/maximum length of tagsIncludes in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/); }); + test('throw if length of branchesExcludes is greater than 8', () => { + expect(() => { + new codepipeline.Pipeline(stack, 'Pipeline', { + pipelineType: codepipeline.PipelineType.V2, + triggers: [{ + providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION, + gitConfiguration: { + sourceAction, + pushFilter: [{ + branchesExcludes: ['exclude1', 'exclude2', 'exclude3', 'exclude4', 'exclude5', 'exclude6', 'exclude7', 'exclude8', 'exclude9'], + branchesIncludes: ['include1', 'include2'], + }], + }, + }], + }); + }).toThrow(/maximum length of branchesExcludes in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/); + }); + + test('throw if length of branchesIncludes is greater than 8', () => { + expect(() => { + new codepipeline.Pipeline(stack, 'Pipeline', { + pipelineType: codepipeline.PipelineType.V2, + triggers: [{ + providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION, + gitConfiguration: { + sourceAction, + pushFilter: [{ + branchesExcludes: ['exclude1', 'exclude2'], + branchesIncludes: ['include1', 'include2', 'include3', 'include4', 'include5', 'include6', 'include7', 'include8', 'include9'], + }], + }, + }], + }); + }).toThrow(/maximum length of branchesIncludes in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/); + }); + + test('throw if length of filePathsExcludes is greater than 8', () => { + expect(() => { + new codepipeline.Pipeline(stack, 'Pipeline', { + pipelineType: codepipeline.PipelineType.V2, + triggers: [{ + providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION, + gitConfiguration: { + sourceAction, + pushFilter: [{ + branchesExcludes: ['exclude1', 'exclude2'], + branchesIncludes: ['include1', 'include2'], + filePathsExcludes: ['exclude1', 'exclude2', 'exclude3', 'exclude4', 'exclude5', 'exclude6', 'exclude7', 'exclude8', 'exclude9'], + filePathsIncludes: ['include1', 'include2'], + }], + }, + }], + }); + }).toThrow(/maximum length of filePathsExcludes in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/); + }); + + test('throw if length of filePathsIncludes is greater than 8', () => { + expect(() => { + new codepipeline.Pipeline(stack, 'Pipeline', { + pipelineType: codepipeline.PipelineType.V2, + triggers: [{ + providerType: codepipeline.ProviderType.CODE_STAR_SOURCE_CONNECTION, + gitConfiguration: { + sourceAction, + pushFilter: [{ + branchesExcludes: ['exclude1', 'exclude2'], + branchesIncludes: ['include1', 'include2'], + filePathsExcludes: ['exclude1', 'exclude2'], + filePathsIncludes: ['include1', 'include2', 'include3', 'include4', 'include5', 'include6', 'include7', 'include8', 'include9'], + }], + }, + }], + }); + }).toThrow(/maximum length of filePathsIncludes in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/); + }); + + // TODO: implements and add tests + // 1. tags and branches (with filePaths) are mutually exclusive + // 2. filePaths without branches is not allowed + test('empty pushFilter for trigger is set to undefined', () => { const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', { pipelineType: codepipeline.PipelineType.V2,