forked from opensearch-project/opensearch-migrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MIGRATIONS-1014: Add unit test cases and minor fixes
Signed-off-by: Tanner Lewis <[email protected]>
- Loading branch information
Showing
6 changed files
with
179 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
deployment/cdk/opensearch-service/test/default-values-test.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"engineVersion": "OS_1.0", | ||
"domainName": "default-test-domain" | ||
"domainName": "sample-cdk-unit-test-domain" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
deployment/cdk/opensearch-service/test/network-stack.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {App} from "aws-cdk-lib"; | ||
import {StackComposer} from "../lib/stack-composer"; | ||
import {NetworkStack} from "../lib/network-stack"; | ||
import {Template} from "aws-cdk-lib/assertions"; | ||
|
||
test('Test vpcEnabled setting that is disabled does not create stack', () => { | ||
const app = new App({ | ||
context: { | ||
vpcEnabled: false | ||
} | ||
}) | ||
|
||
const openSearchStacks = new StackComposer(app, { | ||
env: {account: "test-account", region: "us-east-1"} | ||
}) | ||
|
||
openSearchStacks.stacks.forEach(function(stack) { | ||
expect(!(stack instanceof NetworkStack)) | ||
}) | ||
|
||
}) | ||
|
||
test('Test vpcEnabled setting that is enabled without existing resources creates default VPC resources', () => { | ||
const app = new App({ | ||
context: { | ||
vpcEnabled: true, | ||
// This setting could be left out, but provides clarity into the subnets for this test case | ||
availabilityZoneCount: 2 | ||
} | ||
}) | ||
|
||
const openSearchStacks = new StackComposer(app, { | ||
env: {account: "test-account", region: "us-east-1"} | ||
}) | ||
|
||
const networkStack: NetworkStack = (openSearchStacks.stacks.filter((s) => s instanceof NetworkStack)[0]) as NetworkStack | ||
const networkTemplate = Template.fromStack(networkStack) | ||
|
||
networkTemplate.resourceCountIs("AWS::EC2::VPC", 1) | ||
networkTemplate.resourceCountIs("AWS::EC2::SecurityGroup", 1) | ||
// For each AZ, a private and public subnet is created | ||
networkTemplate.resourceCountIs("AWS::EC2::Subnet", 4) | ||
|
||
const securityGroups = networkStack.domainSecurityGroups | ||
expect(securityGroups.length).toBe(1) | ||
const subnets = networkStack.domainSubnets | ||
expect(subnets).toBe(undefined) | ||
const vpc = networkStack.vpc | ||
expect(vpc.publicSubnets.length).toBe(2) | ||
expect(vpc.privateSubnets.length).toBe(2) | ||
}) |
Oops, something went wrong.