Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, test } from 'vitest'

import { CreateDiskStorageSchema } from './DiskManagement.schema'
import {
calculateBaselineIopsForComputeSize,
calculateComputeSizeRequiredForIops,
Expand Down Expand Up @@ -147,6 +148,18 @@ describe('DiskManagement.utils.ts:calculateIOPSPrice', () => {
expect(result.oldPrice).toBe('357.00')
expect(result.newPrice).toBe('595.00')
})
test('includes IOPS charges for read replicas', () => {
const result = calculateIOPSPrice({
oldStorageType: DiskType.GP3,
oldProvisionedIOPS: 3000,
newStorageType: DiskType.GP3,
newProvisionedIOPS: 5000,
numReplicas: 2,
})

expect(result.oldPrice).toBe('0.00')
expect(result.newPrice).toBe('144.00')
})
})

describe('DiskManagement.utils.ts:calculateThroughputPrice', () => {
Expand All @@ -168,4 +181,109 @@ describe('DiskManagement.utils.ts:calculateThroughputPrice', () => {
expect(result.oldPrice).toBe('0.00')
expect(result.newPrice).toBe('0.00')
})
test('includes throughput charges for read replicas', () => {
const result = calculateThroughputPrice({
storageType: DiskType.GP3,
oldThroughput: 125,
newThroughput: 150,
numReplicas: 2,
})

expect(result.oldPrice).toBe('0.00')
expect(result.newPrice).toBe('7.13')
})
})

describe('CreateDiskStorageSchema', () => {
const validGp3Config = {
storageType: DiskType.GP3,
totalSize: 8,
provisionedIOPS: 3000,
throughput: 125,
computeSize: 'ci_large' as const,
growthPercent: null,
minIncrementGb: null,
maxSizeGb: null,
}

test('enforces the GP3 500 IOPS per GB limit', () => {
const schema = CreateDiskStorageSchema({
defaultTotalSize: 8,
cloudProvider: 'AWS',
isSpendCapEnabled: false,
})

const result = schema.safeParse({
...validGp3Config,
provisionedIOPS: 6000,
})

expect(result.success).toBe(false)
if (result.success) return

expect(result.error.issues).toContainEqual(
expect.objectContaining({
path: ['provisionedIOPS'],
message: 'Larger Disk size of at least 12 GB required. Current max is 4,000 IOPS.',
})
)
})

test('allows a legacy disk below 8 GB when its size is unchanged', () => {
const schema = CreateDiskStorageSchema({
defaultTotalSize: 2,
cloudProvider: 'AWS',
isSpendCapEnabled: false,
})

expect(
schema.safeParse({
...validGp3Config,
totalSize: 2,
}).success
).toBe(true)
})

test('prevents disk growth above 8 GB while spend cap is enabled', () => {
const schema = CreateDiskStorageSchema({
defaultTotalSize: 8,
cloudProvider: 'AWS',
isSpendCapEnabled: true,
})

const result = schema.safeParse({
...validGp3Config,
totalSize: 10,
})

expect(result.success).toBe(false)
if (result.success) return

expect(result.error.issues).toContainEqual(
expect.objectContaining({
path: ['totalSize'],
message: 'Disable spend cap to increase disk above 8 GB.',
})
)
})

test.each(['FLY', 'AWS_NIMBUS', 'AWS_K8S'] as const)(
'skips platform disk constraints for %s projects',
(cloudProvider) => {
const schema = CreateDiskStorageSchema({
defaultTotalSize: 8,
cloudProvider,
isSpendCapEnabled: true,
})

expect(
schema.safeParse({
...validGp3Config,
totalSize: 1,
provisionedIOPS: 100_000,
throughput: 10_000,
}).success
).toBe(true)
}
)
})
Loading
Loading