Skip to content

Commit e3300f0

Browse files
authored
chore(pipes-targets): remove dependency with pipes-sources (#31986)
Update the integration test cases for both pipes-sources and pipes-targets modules to add comments explained why we use TestTarget, and TestSource instead of using real classes, and this to avoid the circular dependencies, as we need to depend on each module on the other so we can implement these test cases. These Test classes should be replaced before graduating the pipes alpha modules.
1 parent 5137e38 commit e3300f0

12 files changed

+176
-27
lines changed

packages/@aws-cdk/aws-pipes-sources-alpha/test/integ.dynamodb.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const table = new ddb.TableV2(stack, 'MyTable', {
1717
const dlqQueue = new cdk.aws_sqs.Queue(stack, 'DlqQueue');
1818
const targetQueue = new cdk.aws_sqs.Queue(stack, 'TargetQueue');
1919

20+
// When this module is promoted from alpha, TestTarget should
21+
// be replaced with SqsTarget from @aws-cdk/aws-pipes-targets-alpha
2022
class TestTarget implements ITarget {
2123
targetArn: string;
2224

packages/@aws-cdk/aws-pipes-sources-alpha/test/integ.kinesis.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const stack = new cdk.Stack(app, 'aws-cdk-pipes-sources-kinesis');
99
const sourceKinesisStream = new cdk.aws_kinesis.Stream(stack, 'SourceKinesisStream');
1010
const targetQueue = new cdk.aws_sqs.Queue(stack, 'TargetQueue');
1111

12+
// When this module is promoted from alpha, TestTarget should
13+
// be replaced with SqsTarget from @aws-cdk/aws-pipes-targets-alpha
1214
class TestTarget implements ITarget {
1315
targetArn: string;
1416

packages/@aws-cdk/aws-pipes-sources-alpha/test/integ.sqs.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const stack = new cdk.Stack(app, 'aws-cdk-pipes-sources-sqs');
99
const sourceQueue = new cdk.aws_sqs.Queue(stack, 'SourceQueue');
1010
const targetQueue = new cdk.aws_sqs.Queue(stack, 'TargetQueue');
1111

12+
// When this module is promoted from alpha, TestTarget should
13+
// be replaced with SqsTarget from @aws-cdk/aws-pipes-targets-alpha
1214
class TestTarget implements ITarget {
1315
targetArn: string;
1416
inputTransformation: InputTransformation = InputTransformation.fromEventPath('$.body');

packages/@aws-cdk/aws-pipes-targets-alpha/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@
8989
"aws-cdk-lib": "0.0.0",
9090
"constructs": "^10.0.0",
9191
"@aws-cdk/aws-pipes-alpha": "0.0.0",
92-
"@aws-cdk/integ-tests-alpha": "0.0.0",
93-
"@aws-cdk/aws-pipes-sources-alpha": "0.0.0"
92+
"@aws-cdk/integ-tests-alpha": "0.0.0"
9493
},
9594
"dependencies": {},
9695
"peerDependencies": {

packages/@aws-cdk/aws-pipes-targets-alpha/test/integ.api-destination.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Pipe } from '@aws-cdk/aws-pipes-alpha';
2-
import { SqsSource } from '@aws-cdk/aws-pipes-sources-alpha';
1+
import { IPipe, ISource, Pipe, SourceConfig } from '@aws-cdk/aws-pipes-alpha';
32
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha';
43
import * as cdk from 'aws-cdk-lib';
54
import * as apigwv2 from 'aws-cdk-lib/aws-apigatewayv2';
@@ -19,6 +18,25 @@ const sourceQueue = new cdk.aws_sqs.Queue(stack, 'SourceQueue');
1918
* --> API Gateway HTTP API --> Lambda function
2019
*/
2120

21+
// When this module is promoted from alpha, TestSource should
22+
// be replaced with SqsSource from @aws-cdk/aws-pipes-sources-alpha
23+
class TestSource implements ISource {
24+
sourceArn: string;
25+
sourceParameters = undefined;
26+
constructor(private readonly queue: cdk.aws_sqs.Queue) {
27+
this.queue = queue;
28+
this.sourceArn = queue.queueArn;
29+
}
30+
bind(_pipe: IPipe): SourceConfig {
31+
return {
32+
sourceParameters: this.sourceParameters,
33+
};
34+
}
35+
grantRead(pipeRole: cdk.aws_iam.IRole): void {
36+
this.queue.grantConsumeMessages(pipeRole);
37+
}
38+
}
39+
2240
const fn = new lambda.Function(stack, 'ConnectHandler', {
2341
runtime: lambda.Runtime.NODEJS_LATEST,
2442
handler: 'index.handler',
@@ -53,7 +71,7 @@ const destination = new cdk.aws_events.ApiDestination(stack, 'MyDestination', {
5371
});
5472

5573
new Pipe(stack, 'Pipe', {
56-
source: new SqsSource(sourceQueue),
74+
source: new TestSource(sourceQueue),
5775
target: new ApiDestinationTarget(destination, {
5876
headerParameters: {
5977
'x-header': 'myheader',

packages/@aws-cdk/aws-pipes-targets-alpha/test/integ.cloudwatch-logs.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { InputTransformation, Pipe } from '@aws-cdk/aws-pipes-alpha';
2-
import { SqsSource } from '@aws-cdk/aws-pipes-sources-alpha';
1+
import { InputTransformation, IPipe, ISource, Pipe, SourceConfig } from '@aws-cdk/aws-pipes-alpha';
32
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha';
43
import * as cdk from 'aws-cdk-lib';
54
import { CloudWatchLogsTarget } from '../lib';
@@ -18,13 +17,32 @@ const targetLogGroup = new cdk.aws_logs.LogGroup(stack, 'TargetLogGroup');
1817
const logStreamName = 'Mexico';
1918
const body = 'Cozumel';
2019

20+
// When this module is promoted from alpha, TestSource should
21+
// be replaced with SqsSource from @aws-cdk/aws-pipes-sources-alpha
22+
class TestSource implements ISource {
23+
sourceArn: string;
24+
sourceParameters = undefined;
25+
constructor(private readonly queue: cdk.aws_sqs.Queue) {
26+
this.queue = queue;
27+
this.sourceArn = queue.queueArn;
28+
}
29+
bind(_pipe: IPipe): SourceConfig {
30+
return {
31+
sourceParameters: this.sourceParameters,
32+
};
33+
}
34+
grantRead(pipeRole: cdk.aws_iam.IRole): void {
35+
this.queue.grantConsumeMessages(pipeRole);
36+
}
37+
}
38+
2139
new cdk.aws_logs.LogStream(stack, 'TargetLogStream', {
2240
logGroup: targetLogGroup,
2341
logStreamName: logStreamName,
2442
});
2543

2644
new Pipe(stack, 'Pipe', {
27-
source: new SqsSource(sourceQueue),
45+
source: new TestSource(sourceQueue),
2846
target: new CloudWatchLogsTarget(targetLogGroup, {
2947
logStreamName,
3048
inputTransformation: InputTransformation.fromEventPath('$.body'),

packages/@aws-cdk/aws-pipes-targets-alpha/test/integ.event-bridge.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Pipe } from '@aws-cdk/aws-pipes-alpha';
2-
import { SqsSource } from '@aws-cdk/aws-pipes-sources-alpha';
1+
import { IPipe, ISource, Pipe, SourceConfig } from '@aws-cdk/aws-pipes-alpha';
32
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha';
43
import * as cdk from 'aws-cdk-lib';
54
import { EventBridgeTarget } from '../lib/event-bridge';
@@ -9,8 +8,27 @@ const stack = new cdk.Stack(app, 'aws-cdk-pipes-targets-event-bridge');
98
const sourceQueue = new cdk.aws_sqs.Queue(stack, 'SourceQueue');
109
const targetEventBus = new cdk.aws_events.EventBus(stack, 'TargetEventBus');
1110

11+
// When this module is promoted from alpha, TestSource should
12+
// be replaced with SqsSource from @aws-cdk/aws-pipes-sources-alpha
13+
class TestSource implements ISource {
14+
sourceArn: string;
15+
sourceParameters = undefined;
16+
constructor(private readonly queue: cdk.aws_sqs.Queue) {
17+
this.queue = queue;
18+
this.sourceArn = queue.queueArn;
19+
}
20+
bind(_pipe: IPipe): SourceConfig {
21+
return {
22+
sourceParameters: this.sourceParameters,
23+
};
24+
}
25+
grantRead(pipeRole: cdk.aws_iam.IRole): void {
26+
this.queue.grantConsumeMessages(pipeRole);
27+
}
28+
}
29+
1230
new Pipe(stack, 'Pipe', {
13-
source: new SqsSource(sourceQueue),
31+
source: new TestSource(sourceQueue),
1432
target: new EventBridgeTarget(targetEventBus, {}),
1533
});
1634

packages/@aws-cdk/aws-pipes-targets-alpha/test/integ.kinesis.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Pipe } from '@aws-cdk/aws-pipes-alpha';
2-
import { SqsSource } from '@aws-cdk/aws-pipes-sources-alpha';
1+
import { IPipe, ISource, Pipe, SourceConfig } from '@aws-cdk/aws-pipes-alpha';
32
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
43
import * as cdk from 'aws-cdk-lib';
54
import { KinesisTarget } from '../lib/kinesis';
@@ -9,8 +8,27 @@ const stack = new cdk.Stack(app, 'aws-cdk-pipes-targets-kinesis');
98
const sourceQueue = new cdk.aws_sqs.Queue(stack, 'SourceQueue');
109
const targetStream = new cdk.aws_kinesis.Stream(stack, 'TargetStream');
1110

11+
// When this module is promoted from alpha, TestSource should
12+
// be replaced with SqsSource from @aws-cdk/aws-pipes-sources-alpha
13+
class TestSource implements ISource {
14+
sourceArn: string;
15+
sourceParameters = undefined;
16+
constructor(private readonly queue: cdk.aws_sqs.Queue) {
17+
this.queue = queue;
18+
this.sourceArn = queue.queueArn;
19+
}
20+
bind(_pipe: IPipe): SourceConfig {
21+
return {
22+
sourceParameters: this.sourceParameters,
23+
};
24+
}
25+
grantRead(pipeRole: cdk.aws_iam.IRole): void {
26+
this.queue.grantConsumeMessages(pipeRole);
27+
}
28+
}
29+
1230
new Pipe(stack, 'Pipe', {
13-
source: new SqsSource(sourceQueue),
31+
source: new TestSource(sourceQueue),
1432
target: new KinesisTarget(targetStream, {
1533
partitionKey: 'pk',
1634
}),

packages/@aws-cdk/aws-pipes-targets-alpha/test/integ.lambda.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { randomUUID } from 'crypto';
22
import * as path from 'path';
3-
import { Pipe } from '@aws-cdk/aws-pipes-alpha';
4-
import { SqsSource } from '@aws-cdk/aws-pipes-sources-alpha';
3+
import { IPipe, ISource, Pipe, SourceConfig } from '@aws-cdk/aws-pipes-alpha';
54
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha';
65
import * as cdk from 'aws-cdk-lib';
76
import * as iam from 'aws-cdk-lib/aws-iam';
@@ -20,6 +19,25 @@ const app = new cdk.App();
2019
const stack = new cdk.Stack(app, 'aws-cdk-pipes-lambda-target');
2120
const sourceQueue = new cdk.aws_sqs.Queue(stack, 'SourceQueue');
2221

22+
// When this module is promoted from alpha, TestSource should
23+
// be replaced with SqsSource from @aws-cdk/aws-pipes-sources-alpha
24+
class TestSource implements ISource {
25+
sourceArn: string;
26+
sourceParameters = undefined;
27+
constructor(private readonly queue: cdk.aws_sqs.Queue) {
28+
this.queue = queue;
29+
this.sourceArn = queue.queueArn;
30+
}
31+
bind(_pipe: IPipe): SourceConfig {
32+
return {
33+
sourceParameters: this.sourceParameters,
34+
};
35+
}
36+
grantRead(pipeRole: cdk.aws_iam.IRole): void {
37+
this.queue.grantConsumeMessages(pipeRole);
38+
}
39+
}
40+
2341
const functionName = 'TestCdkPipesTargetLambdaFunction';
2442
const targetFunction = new lambda.Function(stack, 'TargetLambdaFunction', {
2543
code: lambda.AssetCode.fromAsset(
@@ -40,7 +58,7 @@ targetFunction.addToRolePolicy(
4058
);
4159

4260
new Pipe(stack, 'Pipe', {
43-
source: new SqsSource(sourceQueue),
61+
source: new TestSource(sourceQueue),
4462
target: new LambdaFunction(targetFunction, {}),
4563
});
4664

packages/@aws-cdk/aws-pipes-targets-alpha/test/integ.sagemaker.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { Pipe } from '@aws-cdk/aws-pipes-alpha';
2-
// eslint-disable-next-line import/no-extraneous-dependencies
3-
import { SqsSource } from '@aws-cdk/aws-pipes-sources-alpha';
1+
import { IPipe, ISource, Pipe, SourceConfig } from '@aws-cdk/aws-pipes-alpha';
42
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha';
53
import * as cdk from 'aws-cdk-lib';
64
import * as iam from 'aws-cdk-lib/aws-iam';
@@ -20,6 +18,25 @@ const app = new cdk.App();
2018
const stack = new cdk.Stack(app, 'aws-cdk-pipes-targets-sagemaker');
2119
const sourceQueue = new cdk.aws_sqs.Queue(stack, 'SourceQueue');
2220

21+
// When this module is promoted from alpha, TestSource should
22+
// be replaced with SqsSource from @aws-cdk/aws-pipes-sources-alpha
23+
class TestSource implements ISource {
24+
sourceArn: string;
25+
sourceParameters = undefined;
26+
constructor(private readonly queue: cdk.aws_sqs.Queue) {
27+
this.queue = queue;
28+
this.sourceArn = queue.queueArn;
29+
}
30+
bind(_pipe: IPipe): SourceConfig {
31+
return {
32+
sourceParameters: this.sourceParameters,
33+
};
34+
}
35+
grantRead(pipeRole: cdk.aws_iam.IRole): void {
36+
this.queue.grantConsumeMessages(pipeRole);
37+
}
38+
}
39+
2340
interface FakePipelineProps {
2441
readonly pipelineName: string;
2542
}
@@ -122,7 +139,7 @@ const targetPipeline = new FakePipeline(stack, 'Pipeline', {
122139
});
123140

124141
new Pipe(stack, 'Pipe', {
125-
source: new SqsSource(sourceQueue),
142+
source: new TestSource(sourceQueue),
126143
target: new SageMakerTarget(targetPipeline, {
127144
pipelineParameters: {
128145
foor: 'bar',

packages/@aws-cdk/aws-pipes-targets-alpha/test/integ.sqs.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { randomUUID } from 'crypto';
2-
import { InputTransformation, Pipe } from '@aws-cdk/aws-pipes-alpha';
3-
import { SqsSource } from '@aws-cdk/aws-pipes-sources-alpha';
2+
import { InputTransformation, IPipe, ISource, Pipe, SourceConfig } from '@aws-cdk/aws-pipes-alpha';
43
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha';
54
import * as cdk from 'aws-cdk-lib';
65
import { SqsTarget } from '../lib';
@@ -10,8 +9,27 @@ const stack = new cdk.Stack(app, 'aws-cdk-pipes-targets');
109
const sourceQueue = new cdk.aws_sqs.Queue(stack, 'SourceQueue');
1110
const targetQueue = new cdk.aws_sqs.Queue(stack, 'TargetQueue');
1211

12+
// When this module is promoted from alpha, TestSource should
13+
// be replaced with SqsSource from @aws-cdk/aws-pipes-sources-alpha
14+
class TestSource implements ISource {
15+
sourceArn: string;
16+
sourceParameters = undefined;
17+
constructor(private readonly queue: cdk.aws_sqs.Queue) {
18+
this.queue = queue;
19+
this.sourceArn = queue.queueArn;
20+
}
21+
bind(_pipe: IPipe): SourceConfig {
22+
return {
23+
sourceParameters: this.sourceParameters,
24+
};
25+
}
26+
grantRead(pipeRole: cdk.aws_iam.IRole): void {
27+
this.queue.grantConsumeMessages(pipeRole);
28+
}
29+
}
30+
1331
new Pipe(stack, 'Pipe', {
14-
source: new SqsSource(sourceQueue),
32+
source: new TestSource(sourceQueue),
1533
target: new SqsTarget(targetQueue,
1634
{
1735
inputTransformation: InputTransformation.fromEventPath('$.body'),

packages/@aws-cdk/aws-pipes-targets-alpha/test/integ.stepfunctions.ts

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { InputTransformation, Pipe } from '@aws-cdk/aws-pipes-alpha';
2-
import { SqsSource } from '@aws-cdk/aws-pipes-sources-alpha';
1+
import { InputTransformation, IPipe, ISource, Pipe, SourceConfig } from '@aws-cdk/aws-pipes-alpha';
32
import { ExpectedResult, IntegTest } from '@aws-cdk/integ-tests-alpha';
43
import * as cdk from 'aws-cdk-lib';
54
import * as ssm from 'aws-cdk-lib/aws-ssm';
@@ -16,6 +15,26 @@ import { SfnStateMachine } from '../lib/stepfunctions';
1615
const app = new cdk.App();
1716
const stack = new cdk.Stack(app, 'aws-cdk-pipes-sfn-target');
1817
const sourceQueue = new cdk.aws_sqs.Queue(stack, 'SourceQueue');
18+
19+
// When this module is promoted from alpha, TestSource should
20+
// be replaced with SqsSource from @aws-cdk/aws-pipes-sources-alpha
21+
class TestSource implements ISource {
22+
sourceArn: string;
23+
sourceParameters = undefined;
24+
constructor(private readonly queue: cdk.aws_sqs.Queue) {
25+
this.queue = queue;
26+
this.sourceArn = queue.queueArn;
27+
}
28+
bind(_pipe: IPipe): SourceConfig {
29+
return {
30+
sourceParameters: this.sourceParameters,
31+
};
32+
}
33+
grantRead(pipeRole: cdk.aws_iam.IRole): void {
34+
this.queue.grantConsumeMessages(pipeRole);
35+
}
36+
}
37+
1938
const parameterName = 'MyPipeParameter';
2039
new ssm.StringParameter(stack, 'MyParameter', {
2140
parameterName,
@@ -38,7 +57,7 @@ const targetStateMachine = new sfn.StateMachine(stack, 'TargetStateMachine', {
3857
});
3958

4059
new Pipe(stack, 'Pipe', {
41-
source: new SqsSource(sourceQueue),
60+
source: new TestSource(sourceQueue),
4261
target: new SfnStateMachine(targetStateMachine,
4362
{
4463
inputTransformation: InputTransformation.fromObject({ body: '<$.body>' }),

0 commit comments

Comments
 (0)