-
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.
test(stacks.api): add test suite for cache stack
Signed-off-by: Braden Mars <bradenmars@bradenmars.me>
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 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
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() | ||
}) | ||
}) |