Skip to content

Commit

Permalink
test(stacks.api): add test suite for cache stack
Browse files Browse the repository at this point in the history
Signed-off-by: Braden Mars <bradenmars@bradenmars.me>
  • Loading branch information
BradenM committed Aug 21, 2023
1 parent 8185bc5 commit ca89e76
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/stacks/api/test/cache-stack.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { App, Stack } from 'aws-cdk-lib'
import { Template } from 'aws-cdk-lib/assertions'
import { Vpc } from 'aws-cdk-lib/aws-ec2'
import { vi, expect, test, describe, beforeEach } from 'vitest'
import { cacheConfigSchema } from '../src'
import { CacheStack, type CacheProps } from '../src/stacks'

interface TestContext {
app: App
vpc: Vpc
}

describe('CacheStack', () => {
beforeEach<TestContext>((ctx) => {
ctx.app = new App()
const vpcStack = new Stack(ctx.app, 'test-vpc')
ctx.vpc = new Vpc(vpcStack, 'test-vpc')
})

test<TestContext>('renders expected template with defaults', (ctx) => {
const cacheProps = cacheConfigSchema.parse({
enabled: true,
})
const stack = new CacheStack(ctx.app, 'test-cache', {
vpc: ctx.vpc,
...cacheProps,
})
const template = Template.fromStack(stack)
expect(template.toJSON()).toMatchSnapshot()
})

test<TestContext>('renders expected template with cluster mode', (ctx) => {
const cacheProps = cacheConfigSchema.parse({
enabled: true,
clusterMode: true,
replicas: 3,
memoryAutoscalingTarget: 60,
})
const stack = new CacheStack(ctx.app, 'test-cache', {
vpc: ctx.vpc,
...cacheProps,
})
const template = Template.fromStack(stack)
expect(template.toJSON()).toMatchSnapshot()
})
})

0 comments on commit ca89e76

Please sign in to comment.