From ca89e769f185dacbcaeea543eab83c48b595ea1a Mon Sep 17 00:00:00 2001 From: Braden Mars Date: Mon, 21 Aug 2023 01:08:45 -0500 Subject: [PATCH] test(stacks.api): add test suite for cache stack Signed-off-by: Braden Mars --- packages/stacks/api/test/cache-stack.spec.ts | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 packages/stacks/api/test/cache-stack.spec.ts diff --git a/packages/stacks/api/test/cache-stack.spec.ts b/packages/stacks/api/test/cache-stack.spec.ts new file mode 100644 index 00000000..41a66d13 --- /dev/null +++ b/packages/stacks/api/test/cache-stack.spec.ts @@ -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((ctx) => { + ctx.app = new App() + const vpcStack = new Stack(ctx.app, 'test-vpc') + ctx.vpc = new Vpc(vpcStack, 'test-vpc') + }) + + test('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('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() + }) +})