diff --git a/packages/@aws-cdk/aws-sqs/lib/queue-ref.ts b/packages/@aws-cdk/aws-sqs/lib/queue-ref.ts index f8e94acecd35e..55d591881e936 100644 --- a/packages/@aws-cdk/aws-sqs/lib/queue-ref.ts +++ b/packages/@aws-cdk/aws-sqs/lib/queue-ref.ts @@ -11,8 +11,8 @@ export abstract class QueueRef extends cdk.Construct implements s3n.IBucketNotif /** * Import an existing queue */ - public static import(parent: cdk.Construct, name: string, props: QueueRefProps) { - new ImportedQueue(parent, name, props); + public static import(parent: cdk.Construct, name: string, props: QueueRefProps): QueueRef { + return new ImportedQueue(parent, name, props); } /** diff --git a/packages/@aws-cdk/aws-sqs/test/test.sqs.ts b/packages/@aws-cdk/aws-sqs/test/test.sqs.ts index 90a03973e4b82..d6a0b3cdca289 100644 --- a/packages/@aws-cdk/aws-sqs/test/test.sqs.ts +++ b/packages/@aws-cdk/aws-sqs/test/test.sqs.ts @@ -91,12 +91,24 @@ export = { }, 'exporting and importing works'(test: Test) { + // GIVEN const stack = new Stack(); const queue = new sqs.Queue(stack, 'Queue'); + // WHEN const ref = queue.export(); + const imports = sqs.QueueRef.import(stack, 'Imported', ref); - sqs.QueueRef.import(stack, 'Imported', ref); + // THEN + + // "import" returns a a QueueRef bound to `Fn::ImportValue`s. + test.deepEqual(resolve(imports.queueArn), { 'Fn::ImportValue': 'QueueQueueArn8CF496D5' }); + test.deepEqual(resolve(imports.queueUrl), { 'Fn::ImportValue': 'QueueQueueUrlC30FF916' }); + + // the exporting stack has Outputs for QueueARN and QueueURL + const outputs = stack.toCloudFormation().Outputs; + test.deepEqual(outputs.QueueQueueArn8CF496D5, { Value: { 'Fn::GetAtt': [ 'Queue4A7E3555', 'Arn' ] }, Export: { Name: 'QueueQueueArn8CF496D5' } }); + test.deepEqual(outputs.QueueQueueUrlC30FF916, { Value: { Ref: 'Queue4A7E3555' }, Export: { Name: 'QueueQueueUrlC30FF916' } }); test.done(); },