Skip to content

Commit c21ebb5

Browse files
Elad Ben-IsraelRomainMuller
Elad Ben-Israel
authored andcommitted
fix(aws-sqs): Queue.import() doesn't return a value (#885)
`QueueRef.import` did not return the created `ImportedQueue` object. Added assertions to the relevant test to verify that indeed exports and imports behave as expected. Fixes #879
1 parent 8824356 commit c21ebb5

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Diff for: packages/@aws-cdk/aws-sqs/lib/queue-ref.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export abstract class QueueRef extends cdk.Construct implements s3n.IBucketNotif
1111
/**
1212
* Import an existing queue
1313
*/
14-
public static import(parent: cdk.Construct, name: string, props: QueueRefProps) {
15-
new ImportedQueue(parent, name, props);
14+
public static import(parent: cdk.Construct, name: string, props: QueueRefProps): QueueRef {
15+
return new ImportedQueue(parent, name, props);
1616
}
1717

1818
/**

Diff for: packages/@aws-cdk/aws-sqs/test/test.sqs.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,24 @@ export = {
9191
},
9292

9393
'exporting and importing works'(test: Test) {
94+
// GIVEN
9495
const stack = new Stack();
9596
const queue = new sqs.Queue(stack, 'Queue');
9697

98+
// WHEN
9799
const ref = queue.export();
100+
const imports = sqs.QueueRef.import(stack, 'Imported', ref);
98101

99-
sqs.QueueRef.import(stack, 'Imported', ref);
102+
// THEN
103+
104+
// "import" returns a a QueueRef bound to `Fn::ImportValue`s.
105+
test.deepEqual(resolve(imports.queueArn), { 'Fn::ImportValue': 'QueueQueueArn8CF496D5' });
106+
test.deepEqual(resolve(imports.queueUrl), { 'Fn::ImportValue': 'QueueQueueUrlC30FF916' });
107+
108+
// the exporting stack has Outputs for QueueARN and QueueURL
109+
const outputs = stack.toCloudFormation().Outputs;
110+
test.deepEqual(outputs.QueueQueueArn8CF496D5, { Value: { 'Fn::GetAtt': [ 'Queue4A7E3555', 'Arn' ] }, Export: { Name: 'QueueQueueArn8CF496D5' } });
111+
test.deepEqual(outputs.QueueQueueUrlC30FF916, { Value: { Ref: 'Queue4A7E3555' }, Export: { Name: 'QueueQueueUrlC30FF916' } });
100112

101113
test.done();
102114
},

0 commit comments

Comments
 (0)