-
Notifications
You must be signed in to change notification settings - Fork 1
feat: DB v2 snapshot db tests #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/custom-db-v2-tests
Are you sure you want to change the base?
Changes from all commits
f83b176
7c0ff49
e273136
3cc7603
c72d00f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import { next as studion } from '@studion/infra-code-blocks'; | |
|
|
||
| const vpc = new studion.Vpc(`${config.appName}-vpc`, {}); | ||
|
|
||
| const defaultDb = new DatabaseBuilder(`${config.appName}-default`) | ||
| const defaultDb = new DatabaseBuilder(`${config.appName}-default-db`) | ||
| .withInstance({ | ||
| dbName: config.dbName, | ||
| }) | ||
|
|
@@ -15,7 +15,7 @@ const defaultDb = new DatabaseBuilder(`${config.appName}-default`) | |
| .withVpc(vpc.vpc) | ||
| .build(); | ||
|
|
||
| const kms = new aws.kms.Key(`${config.appName}-kms`, { | ||
| const kms = new aws.kms.Key(`${config.appName}-kms-key`, { | ||
| description: `${config.appName} RDS encryption key`, | ||
| customerMasterKeySpec: 'SYMMETRIC_DEFAULT', | ||
| isEnabled: true, | ||
|
|
@@ -33,7 +33,7 @@ const paramGroup = new aws.rds.ParameterGroup( | |
| }, | ||
| ); | ||
|
|
||
| const customDb = new DatabaseBuilder(`${config.appName}-custom`) | ||
| const customDb = new DatabaseBuilder(`${config.appName}-custom-db`) | ||
| .withInstance({ | ||
| dbName: config.dbName, | ||
| applyImmediately: config.applyImmediately, | ||
|
|
@@ -55,4 +55,27 @@ const customDb = new DatabaseBuilder(`${config.appName}-custom`) | |
| .withTags(config.tags) | ||
| .build(); | ||
|
|
||
| export { vpc, defaultDb, kms, paramGroup, customDb }; | ||
| const snapshot = defaultDb.instance.dbInstanceIdentifier.apply( | ||
| dbInstanceIdentifier => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (!dbInstanceIdentifier) return; | ||
| return new aws.rds.Snapshot(`${config.appName}-snapshot`, { | ||
| dbInstanceIdentifier: dbInstanceIdentifier, | ||
| dbSnapshotIdentifier: `${config.appName}-snapshot-id`, | ||
| tags: config.tags, | ||
| }); | ||
| }, | ||
| ); | ||
|
|
||
| const snapshotDb = snapshot.apply(snapshot => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (!snapshot) return; | ||
| return new DatabaseBuilder(`${config.appName}-snapshot-db`) | ||
| .withInstance({ | ||
| applyImmediately: true, | ||
| }) | ||
| .withVpc(vpc.vpc) | ||
| .withTags(config.tags) | ||
| .withSnapshot(snapshot.id) | ||
| .build(); | ||
| }); | ||
|
|
||
| export { vpc, defaultDb, kms, paramGroup, customDb, snapshot, snapshotDb }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also add a test to see if we can access the db. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import * as assert from 'node:assert'; | ||
| import { DatabaseTestContext } from './test-context'; | ||
| import { it } from 'node:test'; | ||
|
|
||
| export function testSnapshotDb(ctx: DatabaseTestContext) { | ||
| it('should create and properly configure encrypted snapshot copy', () => { | ||
| const snapshotDb = ctx.outputs.snapshotDb.value; | ||
| const snapshot = ctx.outputs.snapshot.value; | ||
|
|
||
| assert.ok( | ||
| snapshotDb.encryptedSnapshotCopy, | ||
| 'Encrtyped snapshot copy should exist', | ||
| ); | ||
|
|
||
| assert.strictEqual( | ||
| snapshotDb.encryptedSnapshotCopy.sourceDbSnapshotIdentifier, | ||
| snapshot.dbSnapshotArn, | ||
| 'Encrtyped snapshot copy should have correct source db snapshot identifier', | ||
| ); | ||
| assert.strictEqual( | ||
| snapshotDb.encryptedSnapshotCopy.targetDbSnapshotIdentifier, | ||
| `${snapshot.id}-encrypted-copy`, | ||
| 'Encrtyped snapshot copy should have the correct target db snapshot identifier', | ||
| ); | ||
| assert.strictEqual( | ||
| snapshotDb.encryptedSnapshotCopy.kmsKeyId, | ||
| snapshotDb.kmsKeyId, | ||
| 'Encrtyped snapshot copy should have the correct ksm key id', | ||
| ); | ||
| }); | ||
|
|
||
| it('should properly configure instance', () => { | ||
| const snapshotDb = ctx.outputs.snapshotDb.value; | ||
|
|
||
| assert.strictEqual( | ||
| snapshotDb.instance.dbSnapshotIdentifier, | ||
| snapshotDb.encryptedSnapshotCopy.targetDbSnapshotIdentifier, | ||
| 'Db snapshot identifier should be set correctly', | ||
| ); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is here because I changed how databases are named inside this PR (see infrastructure file), as this should be the last PR regarding tests. I can move this to previous PR's if needed