keepmoving
keepmoving

Reputation: 2043

How to write Junit for CDK stage

I am newbie in cdk. I have requirement to create the SQS infra on deployment. For that following is piece of code and its works fine in env.

export class TestStage extends cdk.Stage {
  
  constructor(scope: cdk.Construct, id: string, props: TestProps) {
    super(scope, id);

    const stgStack = new cdk.Stack(this, 'TestStage', {
      description: 'This test environment.',
    });

    let list: string[] = data.sqs;

    list.forEach(queueName => {
      let sqsId = 'CreateSQS_' + queueName;
       const queue = new TestPattern(stgStack, sqsId, queueName);
       console.log(sqsQueue);
    });
  }
}

Now I want to write the unit test for this so that before executing code in env I can make sure things are good. Following is unit test code where I want to verify newly created sqs is added in stage or not. But don't know I can I do that.

test('Test Stage ', () => {

const app = new App();

let testStage = new TestStage (app, 'test-stage', {
  desc: "test"  
});

const testSqsStage = new Stack(testStage, 'TestStack');

const template = Template.fromStack(testSqsStage);
console.log(testSqsStage);

});

can someone help me on this?

Upvotes: 1

Views: 324

Answers (1)

fedonev
fedonev

Reputation: 25669

I want to verify newly created sqs is added in stage or not

// Assert the expected number of Queues:
template.resourceCountIs('AWS::SQS::Queue', data.sqs.length);

Upvotes: 2

Related Questions