-
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
base: feat/db-v2-tests
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| 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 testCustomDb(ctx: DatabaseTestContext) { | ||
|
Contributor
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. Name of this suite doesn't tell much. What actually is being tested here are various configuration options, so renaming |
||
| it('should properly configure instance', () => { | ||
| const customDb = ctx.outputs.customDb.value; | ||
|
|
||
| assert.strictEqual( | ||
| customDb.instance.applyImmediately, | ||
| ctx.config.applyImmediately, | ||
| 'Apply immediately argument should be set correctly', | ||
| ); | ||
| assert.strictEqual( | ||
| customDb.instance.allowMajorVersionUpgrade, | ||
| ctx.config.allowMajorVersionUpgrade, | ||
| 'Allow major version upgrade argument should be set correctly', | ||
| ); | ||
| assert.strictEqual( | ||
| customDb.instance.autoMinorVersionUpgrade, | ||
| ctx.config.autoMinorVersionUpgrade, | ||
| 'Auto minor version upgrade argument should be set correctly', | ||
| ); | ||
| }); | ||
|
|
||
| it('should properly configure password', () => { | ||
| const customDb = ctx.outputs.customDb.value; | ||
|
|
||
| assert.ok(customDb.password, 'Password should exist'); | ||
| assert.strictEqual( | ||
| customDb.instance.masterUserPassword, | ||
| ctx.config.dbPassword, | ||
| 'Master user password should be set correctly', | ||
| ); | ||
| }); | ||
|
|
||
| it('should properly configure storage', () => { | ||
| const customDb = ctx.outputs.customDb.value; | ||
|
|
||
| assert.strictEqual( | ||
| customDb.instance.allocatedStorage, | ||
| ctx.config.allocatedStorage.toString(), | ||
| 'Allocated storage argument should be set correctly', | ||
| ); | ||
| assert.strictEqual( | ||
| customDb.instance.maxAllocatedStorage, | ||
| ctx.config.maxAllocatedStorage, | ||
| 'Max allocated storage argument should be set correctly', | ||
| ); | ||
| }); | ||
|
|
||
| it('should properly configure monitoring options', () => { | ||
| const customDb = ctx.outputs.customDb.value; | ||
|
|
||
| assert.strictEqual( | ||
| customDb.instance.enablePerformanceInsights, | ||
| true, | ||
| 'Performance insights should be enabled', | ||
| ); | ||
| assert.strictEqual( | ||
| customDb.instance.performanceInsightsRetentionPeriod, | ||
| 7, | ||
| 'Performance insights retention period should be set correctly', | ||
| ); | ||
| assert.strictEqual( | ||
| customDb.instance.monitoringInterval, | ||
| 60, | ||
| 'Monitoring interval should be set correctly', | ||
| ); | ||
| assert.ok( | ||
| customDb.instance.monitoringRoleArn, | ||
| 'Monitoring role ARN should exist', | ||
| ); | ||
| }); | ||
|
|
||
| it('should create monitoring IAM role and attach correct policy', async () => { | ||
| const customDb = ctx.outputs.customDb.value; | ||
| const roleName = customDb.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 customDb = ctx.outputs.customDb.value; | ||
| const kms = ctx.outputs.kms.value; | ||
|
|
||
| assert.ok(customDb.kmsKeyId, 'Kms key id should exist'); | ||
| assert.strictEqual( | ||
| customDb.instance.kmsKeyId, | ||
| kms.arn, | ||
| 'Kms key id should be set correctly', | ||
| ); | ||
| }); | ||
|
|
||
| it('should properly configure parameter group', () => { | ||
| const customDb = ctx.outputs.customDb.value; | ||
| const paramGroup = ctx.outputs.paramGroup.value; | ||
|
|
||
| assert.strictEqual( | ||
| customDb.instance.dbParameterGroupName, | ||
| paramGroup.name, | ||
| 'Parameter group name should be set correctly', | ||
| ); | ||
| }); | ||
|
|
||
| it('should properly configure tags', async () => { | ||
| const customDb = ctx.outputs.customDb.value; | ||
|
|
||
| const command = new ListTagsForResourceCommand({ | ||
| ResourceName: customDb.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); | ||
|
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. tag implicitly has |
||
| assert.ok(tag, `${Key} tag should exist`); | ||
| assert.strictEqual(tag.Value, Value, `${Key} tag should set correctly`); | ||
| }); | ||
| }); | ||
| } | ||
| 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; |
| 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`) | ||
| .withInstance({ | ||
| dbName: config.dbName, | ||
| }) | ||
| .withCredentials({ | ||
| username: config.dbUsername, | ||
| }) | ||
| .withVpc(vpc.vpc) | ||
| .build(); | ||
|
|
||
| const kms = new aws.kms.Key(`${config.appName}-kms`, { | ||
| 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`) | ||
| const customDb = new DatabaseBuilder(`${config.appName}-custom`) | ||
| .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, customDb }; |
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.
I feel like we are missing real integration tests here using
Describecommands like we do in other tests. Also we are not actually testing if we can connect to the db like we do for example inupstashorelasticachetests.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.
I will add this to the previous PR also 👍