Skip to content

Commit

Permalink
integ test for CDK migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
Hogan Bobertz committed Sep 19, 2023
1 parent 8a40589 commit dde924e
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 440 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"AWSTemplateFormatVersion" : "2010-09-09",

"Description" : "AWS CloudFormation Sample Template DynamoDB_Table: This template demonstrates the creation of a DynamoDB table. **WARNING** This template creates an Amazon DynamoDB table. You will be billed for the AWS resources used if you create a stack from this template.",

"Parameters" : {
"HashKeyElementName" : {
"Description" : "HashType PrimaryKey Name",
"Type" : "String",
"AllowedPattern" : "[a-zA-Z0-9]*",
"MinLength": "1",
"MaxLength": "2048",
"ConstraintDescription" : "must contain only alphanumberic characters"
},

"HashKeyElementType" : {
"Description" : "HashType PrimaryKey Type",
"Type" : "String",
"Default" : "S",
"AllowedPattern" : "[S|N]",
"MinLength": "1",
"MaxLength": "1",
"ConstraintDescription" : "must be either S or N"
},

"ReadCapacityUnits" : {
"Description" : "Provisioned read throughput",
"Type" : "Number",
"Default" : "5",
"MinValue": "5",
"MaxValue": "10000",
"ConstraintDescription" : "must be between 5 and 10000"
},

"WriteCapacityUnits" : {
"Description" : "Provisioned write throughput",
"Type" : "Number",
"Default" : "10",
"MinValue": "5",
"MaxValue": "10000",
"ConstraintDescription" : "must be between 5 and 10000"
}
},

"Resources" : {
"myDynamoDBTable" : {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"AttributeDefinitions": [ {
"AttributeName" : {"Ref" : "HashKeyElementName"},
"AttributeType" : {"Ref" : "HashKeyElementType"}
} ],
"KeySchema": [
{ "AttributeName": {"Ref" : "HashKeyElementName"}, "KeyType": "HASH" }
],
"ProvisionedThroughput" : {
"ReadCapacityUnits" : {"Ref" : "ReadCapacityUnits"},
"WriteCapacityUnits" : {"Ref" : "WriteCapacityUnits"}
}
}
}
},

"Outputs" : {
"TableName" : {
"Value" : {"Ref" : "myDynamoDBTable"},
"Description" : "Table name of the newly created DynamoDB table"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { promises as fs, existsSync } from 'fs';
import * as os from 'os';
import * as path from 'path';
import { integTest, cloneDirectory, shell, withDefaultFixture, retry, sleep, randomInteger, withSamIntegrationFixture, RESOURCES_DIR, withTemporaryDirectory, ShellHelper, withPackages } from '../../lib';
import { integTest, cloneDirectory, shell, withDefaultFixture, retry, sleep, randomInteger, withSamIntegrationFixture, RESOURCES_DIR } from '../../lib';

jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime

Expand Down Expand Up @@ -50,31 +50,6 @@ integTest('VPC Lookup', withDefaultFixture(async (fixture) => {
await fixture.cdkDeploy('import-vpc', { modEnv: { ENABLE_VPC_TESTING: 'IMPORT' } });
}));

integTest(
'cdk migrate typescript',
withTemporaryDirectory(
withPackages(async (context) => {

const tempShell = ShellHelper.fromContext(context);
await context.packages.makeCliAvailable();

const tempPath = path.resolve(context.integTestDir);
const inputFile = path.join(__dirname, 'template.txt');

await tempShell.shell([
'cdk',
'migrate',
'-l',
'typescript',
'--from-path',
inputFile,
'--output-path',
tempPath,
]);
}),
),
);

// testing a construct with a builtin Nodejs Lambda Function.
// In this case we are testing the s3.Bucket construct with the
// autoDeleteObjects prop set to true, which creates a Lambda backed
Expand Down Expand Up @@ -596,6 +571,35 @@ integTest('deploy with role', withDefaultFixture(async (fixture) => {
}
}));

integTest(
'cdk migrate typescript',
withDefaultFixture(async (fixture) => {
const tempPath = path.join(fixture.integTestDir);

const inputFile = path.join(__dirname, '../../resources/templates/', 'ddbStack.json');

await fixture.cdk([
'migrate',
'--language',
'typescript',
'--stack-name',
'migrate-stack',
'--from-path',
inputFile.toString(),
'--output-path',
tempPath.toString(),
]);
const stackArn = await fixture.cdk([
'deploy',
'migrate-stack'
])
const response = await fixture.aws.cloudFormation('describeStacks', {
StackName: stackArn,
});
expect(response.Stacks?.[0].StackStatus).toEqual('CREATE_COMPLETE');
}),
);

integTest('cdk diff', withDefaultFixture(async (fixture) => {
const diff1 = await fixture.cdk(['diff', fixture.fullStackName('test-1')]);
expect(diff1).toContain('AWS::SNS::Topic');
Expand Down
Loading

0 comments on commit dde924e

Please sign in to comment.