config.test.ts60 lines · main
| 1 | import { afterAll, expect, test } from 'vitest' |
| 2 | |
| 3 | import pgMeta from '../src/index' |
| 4 | import { cleanupRoot, createTestDatabase } from './db/utils' |
| 5 | |
| 6 | afterAll(async () => { |
| 7 | await cleanupRoot() |
| 8 | }) |
| 9 | |
| 10 | const withTestDatabase = ( |
| 11 | name: string, |
| 12 | fn: (db: Awaited<ReturnType<typeof createTestDatabase>>) => Promise<void> |
| 13 | ) => { |
| 14 | test(name, async () => { |
| 15 | const db = await createTestDatabase() |
| 16 | try { |
| 17 | await fn(db) |
| 18 | } finally { |
| 19 | await db.cleanup() |
| 20 | } |
| 21 | }) |
| 22 | } |
| 23 | |
| 24 | withTestDatabase('list config', async ({ executeQuery }) => { |
| 25 | const { sql, zod } = pgMeta.config.list() |
| 26 | const res = zod.parse(await executeQuery(sql)) |
| 27 | |
| 28 | // Test for a known config value |
| 29 | const autovacuumConfig = res.find(({ name }) => name === 'autovacuum') |
| 30 | expect(autovacuumConfig).toMatchInlineSnapshot(` |
| 31 | { |
| 32 | "boot_val": "on", |
| 33 | "category": "Autovacuum", |
| 34 | "context": "sighup", |
| 35 | "enumvals": null, |
| 36 | "extra_desc": null, |
| 37 | "group": "Autovacuum", |
| 38 | "max_val": null, |
| 39 | "min_val": null, |
| 40 | "name": "autovacuum", |
| 41 | "pending_restart": false, |
| 42 | "reset_val": "on", |
| 43 | "setting": "on", |
| 44 | "short_desc": "Starts the autovacuum subprocess.", |
| 45 | "source": "default", |
| 46 | "sourcefile": null, |
| 47 | "sourceline": null, |
| 48 | "subgroup": "", |
| 49 | "unit": null, |
| 50 | "vartype": "bool", |
| 51 | } |
| 52 | `) |
| 53 | }) |
| 54 | |
| 55 | withTestDatabase('list config with pagination', async ({ executeQuery }) => { |
| 56 | const { sql, zod } = pgMeta.config.list({ limit: 5, offset: 0 }) |
| 57 | const res = zod.parse(await executeQuery(sql)) |
| 58 | |
| 59 | expect(res).toHaveLength(5) |
| 60 | }) |