Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
go-to-k committed Feb 17, 2024
1 parent 06d2fc9 commit 55fa3ec
Showing 1 changed file with 305 additions and 3 deletions.
308 changes: 305 additions & 3 deletions packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 55fa3ec

Please sign in to comment.