Skip to content

Commit

Permalink
chore(rds): use nodeunit-shim (#13077)
Browse files Browse the repository at this point in the history
Use `jest` for RDS tests, as I plan to add data-driven tests.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Feb 16, 2021
1 parent 5f0ee88 commit 355fed8
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 41 deletions.
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-rds/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ nyc.config.js
*.snk
!.eslintrc.js

junit.xml
junit.xml
!jest.config.js
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-rds/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ tsconfig.json
# exclude cdk artifacts
**/cdk.out
junit.xml
test/
test/
jest.config.js
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-rds/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const baseConfig = require('cdk-build-tools/config/jest.config');
module.exports = baseConfig;
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-rds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
},
"cdk-build": {
"cloudformation": "AWS::RDS",
"jest": true,
"env": {
"AWSLINT_BASE_CONSTRUCT": true
}
Expand All @@ -73,12 +74,11 @@
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-events-targets": "0.0.0",
"@aws-cdk/aws-lambda": "0.0.0",
"@types/nodeunit": "^0.0.31",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
"nodeunit": "^0.11.3",
"pkglint": "0.0.0"
"pkglint": "0.0.0",
"nodeunit-shim": "0.0.0"
},
"dependencies": {
"@aws-cdk/aws-cloudwatch": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { AuroraEngineVersion, AuroraMysqlEngineVersion, AuroraPostgresEngineVersion, DatabaseClusterEngine } from '../lib';

export = {
nodeunitShim({
"default parameterGroupFamily for versionless Aurora cluster engine is 'aurora5.6'"(test: Test) {
// GIVEN
const engine = DatabaseClusterEngine.AURORA;
Expand Down Expand Up @@ -115,4 +115,4 @@ export = {
test.deepEqual(DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_9_6_9 }).supportedLogTypes, ['postgresql']);
test.done();
},
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import * as kms from '@aws-cdk/aws-kms';
import * as logs from '@aws-cdk/aws-logs';
import * as s3 from '@aws-cdk/aws-s3';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import {
AuroraEngineVersion, AuroraMysqlEngineVersion, AuroraPostgresEngineVersion, CfnDBCluster, Credentials, DatabaseCluster,
DatabaseClusterEngine, DatabaseClusterFromSnapshot, ParameterGroup, PerformanceInsightRetention, SubnetGroup,
} from '../lib';

export = {
nodeunitShim({
'creating a Cluster also creates 2 DB Instances'(test: Test) {
// GIVEN
const stack = testStack();
Expand Down Expand Up @@ -1838,7 +1838,7 @@ export = {

test.done();
},
};
});

function testStack() {
const stack = new cdk.Stack(undefined, undefined, { env: { account: '12345', region: 'us-test-1' } });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { CfnResource, Stack } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { DatabaseSecret } from '../lib';
import { DEFAULT_PASSWORD_EXCLUDE_CHARS } from '../lib/private/util';

export = {
nodeunitShim({
'create a database secret'(test: Test) {
// GIVEN
const stack = new Stack();
Expand Down Expand Up @@ -110,7 +110,7 @@ export = {

test.done();
},
};
});

function getSecretLogicalId(dbSecret: DatabaseSecret, stack: Stack): string {
const cfnSecret = dbSecret.node.defaultChild as CfnResource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { ABSENT, expect, haveResource, ResourcePart } from '@aws-cdk/assert';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { ServerlessCluster, DatabaseClusterEngine, ParameterGroup, Credentials } from '../lib';

export = {
nodeunitShim({
'can create a Serverless Cluster using an existing secret from secretmanager'(test: Test) {
// GIVEN
const stack = testStack();
Expand Down Expand Up @@ -47,7 +47,7 @@ export = {

test.done();
},
};
});

function testStack() {
const stack = new cdk.Stack(undefined, undefined, { env: { account: '12345', region: 'us-test-1' } });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect, haveResourceLike } from '@aws-cdk/assert';
import * as iam from '@aws-cdk/aws-iam';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import * as rds from '../lib';

export = {
nodeunitShim({
'default parameterGroupFamily for versionless MariaDB instance engine is not defined'(test: Test) {
const engine = rds.DatabaseInstanceEngine.MARIADB;

Expand Down Expand Up @@ -284,4 +284,4 @@ export = {
test.done();
},
},
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import * as lambda from '@aws-cdk/aws-lambda';
import * as logs from '@aws-cdk/aws-logs';
import * as s3 from '@aws-cdk/aws-s3';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import * as rds from '../lib';

let stack: cdk.Stack;
let vpc: ec2.Vpc;

export = {
nodeunitShim({
'setUp'(cb: () => void) {
stack = new cdk.Stack();
vpc = new ec2.Vpc(stack, 'VPC');
Expand Down Expand Up @@ -1242,4 +1242,4 @@ export = {

test.done();
},
};
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect, haveResource } from '@aws-cdk/assert';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { DatabaseInstanceEngine, OptionGroup, OracleEngineVersion, OracleLegacyEngineVersion } from '../lib';

export = {
nodeunitShim({
'create an option group'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down Expand Up @@ -160,4 +160,4 @@ export = {

test.done();
},
};
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { countResources, expect, haveResource } from '@aws-cdk/assert';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { DatabaseClusterEngine, ParameterGroup } from '../lib';

export = {
nodeunitShim({
"does not create a parameter group if it wasn't bound to a cluster or instance"(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down Expand Up @@ -126,4 +126,4 @@ export = {

test.done();
},
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import * as ec2 from '@aws-cdk/aws-ec2';
import { AccountPrincipal, Role } from '@aws-cdk/aws-iam';
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import * as rds from '../lib';

let stack: cdk.Stack;
let vpc: ec2.IVpc;

export = {
nodeunitShim({
'setUp'(cb: () => void) {
stack = new cdk.Stack();
vpc = new ec2.Vpc(stack, 'VPC');
Expand Down Expand Up @@ -321,4 +321,4 @@ export = {

test.done();
},
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import * as ec2 from '@aws-cdk/aws-ec2';
import * as iam from '@aws-cdk/aws-iam';
import * as kms from '@aws-cdk/aws-kms';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { AuroraPostgresEngineVersion, ServerlessCluster, DatabaseClusterEngine, ParameterGroup, AuroraCapacityUnit, DatabaseSecret } from '../lib';

export = {
nodeunitShim({
'can create a Serverless Cluster with Aurora Postgres database engine'(test: Test) {
// GIVEN
const stack = testStack();
Expand Down Expand Up @@ -818,7 +818,7 @@ export = {

test.done();
},
};
});


function testStack() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect, haveResourceLike } from '@aws-cdk/assert';
import * as core from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import * as rds from '../../lib';

export = {
nodeunitShim({
'SQL Server instance engine': {
"has ParameterGroup family ending in '11.0' for major version 11"(test: Test) {
const stack = new core.Stack();
Expand Down Expand Up @@ -43,4 +43,4 @@ export = {
test.done();
},
},
};
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect, haveResource } from '@aws-cdk/assert';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import { nodeunitShim, Test } from 'nodeunit-shim';
import * as rds from '../lib';

let stack: cdk.Stack;
let vpc: ec2.IVpc;

export = {
nodeunitShim({
'setUp'(cb: () => void) {
stack = new cdk.Stack();
vpc = new ec2.Vpc(stack, 'VPC');
Expand Down Expand Up @@ -95,4 +95,4 @@ export = {
test.done();
},

};
});

0 comments on commit 355fed8

Please sign in to comment.