-
Notifications
You must be signed in to change notification settings - Fork 1
feat: DB v2 custom db tests #97
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
Open
mandryllo
wants to merge
6
commits into
feat/db-v2-tests
Choose a base branch
from
feat/custom-db-v2-tests
base: feat/db-v2-tests
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6f9884f
Add custom db tests
mandryllo b0d1817
Merge branch 'feat/db-v2-tests' into feat/custom-db-v2-tests
mandryllo 8f7df17
Cleanup
mandryllo 39160de
Merge branch 'feat/db-v2-tests' into feat/custom-db-v2-tests
mandryllo c7c47fe
Rename custom to configurable
mandryllo 790d762
Cleanup
mandryllo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,145 @@ | ||
| import { | ||
| GetRoleCommand, | ||
| ListAttachedRolePoliciesCommand, | ||
| } from '@aws-sdk/client-iam'; | ||
| import * as assert from 'node:assert'; | ||
| import { DatabaseTestContext } from './test-context'; | ||
| import { it } from 'node:test'; | ||
| import { ListTagsForResourceCommand } from '@aws-sdk/client-rds'; | ||
|
|
||
| export function testConfigurableDb(ctx: DatabaseTestContext) { | ||
| it('should properly configure instance', () => { | ||
| const configurableDb = ctx.outputs.configurableDb.value; | ||
|
|
||
| assert.strictEqual( | ||
| configurableDb.instance.applyImmediately, | ||
| ctx.config.applyImmediately, | ||
| 'Apply immediately argument should be set correctly', | ||
| ); | ||
| assert.strictEqual( | ||
| configurableDb.instance.allowMajorVersionUpgrade, | ||
| ctx.config.allowMajorVersionUpgrade, | ||
| 'Allow major version upgrade argument should be set correctly', | ||
| ); | ||
| assert.strictEqual( | ||
| configurableDb.instance.autoMinorVersionUpgrade, | ||
| ctx.config.autoMinorVersionUpgrade, | ||
| 'Auto minor version upgrade argument should be set correctly', | ||
| ); | ||
| }); | ||
|
|
||
| it('should properly configure password', () => { | ||
| const configurableDb = ctx.outputs.configurableDb.value; | ||
|
|
||
| assert.ok(configurableDb.password, 'Password should exist'); | ||
| assert.strictEqual( | ||
| configurableDb.instance.masterUserPassword, | ||
| ctx.config.dbPassword, | ||
| 'Master user password should be set correctly', | ||
| ); | ||
| }); | ||
|
|
||
| it('should properly configure storage', () => { | ||
| const configurableDb = ctx.outputs.configurableDb.value; | ||
|
|
||
| assert.strictEqual( | ||
| configurableDb.instance.allocatedStorage, | ||
| ctx.config.allocatedStorage.toString(), | ||
| 'Allocated storage argument should be set correctly', | ||
| ); | ||
| assert.strictEqual( | ||
| configurableDb.instance.maxAllocatedStorage, | ||
| ctx.config.maxAllocatedStorage, | ||
| 'Max allocated storage argument should be set correctly', | ||
| ); | ||
| }); | ||
|
|
||
| it('should properly configure monitoring options', () => { | ||
| const configurableDb = ctx.outputs.configurableDb.value; | ||
|
|
||
| assert.strictEqual( | ||
| configurableDb.instance.enablePerformanceInsights, | ||
| true, | ||
| 'Performance insights should be enabled', | ||
| ); | ||
| assert.strictEqual( | ||
| configurableDb.instance.performanceInsightsRetentionPeriod, | ||
| 7, | ||
| 'Performance insights retention period should be set correctly', | ||
| ); | ||
| assert.strictEqual( | ||
| configurableDb.instance.monitoringInterval, | ||
| 60, | ||
| 'Monitoring interval should be set correctly', | ||
| ); | ||
| assert.ok( | ||
| configurableDb.instance.monitoringRoleArn, | ||
| 'Monitoring role ARN should exist', | ||
| ); | ||
| }); | ||
|
|
||
| it('should create monitoring IAM role and attach correct policy', async () => { | ||
| const configurableDb = ctx.outputs.configurableDb.value; | ||
| const roleName = configurableDb.monitoringRole.name; | ||
|
|
||
| const roleCommand = new GetRoleCommand({ | ||
| RoleName: roleName, | ||
| }); | ||
| const { Role } = await ctx.clients.iam.send(roleCommand); | ||
| assert.ok(Role, 'Monitoring IAM role should exist'); | ||
|
|
||
| const policyCommand = new ListAttachedRolePoliciesCommand({ | ||
| RoleName: roleName, | ||
| }); | ||
| const { AttachedPolicies } = await ctx.clients.iam.send(policyCommand); | ||
| assert.ok( | ||
| AttachedPolicies && AttachedPolicies.length > 0, | ||
| 'Attached policies should exist', | ||
| ); | ||
| const [attachedPolicy] = AttachedPolicies; | ||
| assert.strictEqual( | ||
| attachedPolicy.PolicyArn, | ||
| 'arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole', | ||
| 'Monitoring IAM role should have correct policy attached', | ||
| ); | ||
| }); | ||
|
|
||
| it('should properly configure kms', () => { | ||
| const configurableDb = ctx.outputs.configurableDb.value; | ||
| const kms = ctx.outputs.kms.value; | ||
|
|
||
| assert.ok(configurableDb.kmsKeyId, 'Kms key id should exist'); | ||
| assert.strictEqual( | ||
| configurableDb.instance.kmsKeyId, | ||
| kms.arn, | ||
| 'Kms key id should be set correctly', | ||
| ); | ||
| }); | ||
|
|
||
| it('should properly configure parameter group', () => { | ||
| const configurableDb = ctx.outputs.configurableDb.value; | ||
| const paramGroup = ctx.outputs.paramGroup.value; | ||
|
|
||
| assert.strictEqual( | ||
| configurableDb.instance.dbParameterGroupName, | ||
| paramGroup.name, | ||
| 'Parameter group name should be set correctly', | ||
| ); | ||
| }); | ||
|
|
||
| it('should properly configure tags', async () => { | ||
| const configurableDb = ctx.outputs.configurableDb.value; | ||
|
|
||
| const command = new ListTagsForResourceCommand({ | ||
| ResourceName: configurableDb.instance.dbInstanceArn, | ||
| }); | ||
| const { TagList } = await ctx.clients.rds.send(command); | ||
| assert.ok(TagList && TagList.length > 0, 'Tags should exist'); | ||
|
|
||
| Object.entries(ctx.config.tags).map(([Key, Value]) => { | ||
| const tag = TagList.find(tag => tag.Key === Key); | ||
mandryllo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert.ok(tag, `${Key} tag should exist`); | ||
| assert.strictEqual(tag.Value, Value, `${Key} tag should set correctly`); | ||
| }); | ||
| }); | ||
| } | ||
This file contains hidden or 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 hidden or 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,3 +1,16 @@ | ||
| import * as pulumi from '@pulumi/pulumi'; | ||
|
|
||
| export const appName = 'db-test'; | ||
| export const stackName = pulumi.getStack(); | ||
| export const tags = { | ||
| Project: appName, | ||
| Environment: stackName, | ||
| }; | ||
| export const dbName = 'dbname'; | ||
| export const dbUsername = 'dbusername'; | ||
| export const dbPassword = 'dbpassword'; | ||
| export const applyImmediately = true; | ||
| export const allowMajorVersionUpgrade = true; | ||
| export const autoMinorVersionUpgrade = false; | ||
| export const allocatedStorage = 10; | ||
| export const maxAllocatedStorage = 50; |
This file contains hidden or 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,17 +1,58 @@ | ||
| import { appName, dbName, dbUsername } from './config'; | ||
| import { next as studion } from '@studion/infra-code-blocks'; | ||
| import * as aws from '@pulumi/aws'; | ||
| import * as config from './config'; | ||
| import { DatabaseBuilder } from '../../../dist/v2/components/database/builder'; | ||
| import { next as studion } from '@studion/infra-code-blocks'; | ||
|
|
||
| const vpc = new studion.Vpc(`${config.appName}-vpc`, {}); | ||
|
|
||
| const defaultDb = new DatabaseBuilder(`${config.appName}-default-db`) | ||
| .withInstance({ | ||
| dbName: config.dbName, | ||
| }) | ||
| .withCredentials({ | ||
| username: config.dbUsername, | ||
| }) | ||
| .withVpc(vpc.vpc) | ||
| .build(); | ||
|
|
||
| const kms = new aws.kms.Key(`${config.appName}-kms-key`, { | ||
| description: `${config.appName} RDS encryption key`, | ||
| customerMasterKeySpec: 'SYMMETRIC_DEFAULT', | ||
| isEnabled: true, | ||
| keyUsage: 'ENCRYPT_DECRYPT', | ||
| multiRegion: false, | ||
| enableKeyRotation: true, | ||
| tags: config.tags, | ||
| }); | ||
|
|
||
| const vpc = new studion.Vpc(`${appName}-vpc`, {}); | ||
| const paramGroup = new aws.rds.ParameterGroup( | ||
| `${config.appName}-parameter-group`, | ||
| { | ||
| family: 'postgres17', | ||
| tags: config.tags, | ||
| }, | ||
| ); | ||
|
|
||
| const defaultDb = new DatabaseBuilder(`${appName}-default-db`) | ||
| const configurableDb = new DatabaseBuilder(`${config.appName}-configurable-db`) | ||
| .withInstance({ | ||
| dbName, | ||
| dbName: config.dbName, | ||
| applyImmediately: config.applyImmediately, | ||
| allowMajorVersionUpgrade: config.allowMajorVersionUpgrade, | ||
| autoMinorVersionUpgrade: config.autoMinorVersionUpgrade, | ||
| }) | ||
| .withCredentials({ | ||
| username: dbUsername, | ||
| username: config.dbUsername, | ||
| password: config.dbPassword, | ||
| }) | ||
| .withStorage({ | ||
| allocatedStorage: config.allocatedStorage, | ||
| maxAllocatedStorage: config.maxAllocatedStorage, | ||
| }) | ||
| .withVpc(vpc.vpc) | ||
| .withMonitoring() | ||
| .withKms(kms.arn) | ||
| .withParameterGroup(paramGroup.name) | ||
| .withTags(config.tags) | ||
| .build(); | ||
|
|
||
| export { vpc, defaultDb }; | ||
| export { vpc, defaultDb, kms, paramGroup, configurableDb }; |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.