Skip to content

Commit

Permalink
fix(aws-sqs): Queue.import() doesn't return a value
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
Elad Ben-Israel committed Oct 10, 2018
1 parent 56f0b4e commit c0aaf97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-sqs/lib/queue-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
14 changes: 13 additions & 1 deletion packages/@aws-cdk/aws-sqs/test/test.sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
Expand Down

0 comments on commit c0aaf97

Please sign in to comment.