feat: add connection and ssh zod schemas

This commit is contained in:
smartass
2026-06-11 23:03:43 +05:00
parent 80ba44f1ce
commit 040d9288e3
2 changed files with 88 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
import { describe, expect, it } from 'vitest'
import { connectionConfigSchema, defaultPort } from '../../../src/config/types.js'
describe('connectionConfigSchema', () => {
const minimal = {
name: 'lab-pg',
type: 'postgres',
host: 'localhost',
user: 'postgres'
}
it('accepts minimal config and applies defaults', () => {
const parsed = connectionConfigSchema.parse(minimal)
expect(parsed.readonly).toBe(false)
expect(parsed.port).toBeUndefined()
expect(parsed.ssh).toBeUndefined()
})
it('accepts full config with ssh and defaults ssh port to 22', () => {
const parsed = connectionConfigSchema.parse({
...minimal,
port: 5433,
password: 'secret',
database: 'app',
readonly: true,
ssh: { host: 'bastion', user: 'root', privateKeyPath: '~/.ssh/id_ed25519' }
})
expect(parsed.ssh?.port).toBe(22)
expect(parsed.readonly).toBe(true)
})
it('rejects bad name characters', () => {
expect(() => connectionConfigSchema.parse({ ...minimal, name: 'bad name!' })).toThrow()
})
it('rejects unknown engine type', () => {
expect(() => connectionConfigSchema.parse({ ...minimal, type: 'oracle' })).toThrow()
})
it('rejects empty host', () => {
expect(() => connectionConfigSchema.parse({ ...minimal, host: '' })).toThrow()
})
})
describe('defaultPort', () => {
it('returns 5432 for postgres and 3306 for mysql', () => {
expect(defaultPort('postgres')).toBe(5432)
expect(defaultPort('mysql')).toBe(3306)
})
})