feat(esmole): store, sources, registry, manager, backend binders
This commit is contained in:
1 parent
42712d508c
commit
889e844768
11 files changed
+330
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import type { BackendTarget } from '@dbmole/core'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { EsBackend, EsResponse } from '../../src/es/backend.js'
|
||||
import { createBackend, ping, resolvePort } from '../../src/esBackend.js'
|
||||
import type { ConnectionConfig } from '../../src/schema.js'
|
||||
|
||||
const config = (extra: Partial<ConnectionConfig> = {}): ConnectionConfig => ({
|
||||
name: 'es',
|
||||
type: 'elasticsearch',
|
||||
host: 'es.example.com',
|
||||
scheme: 'https',
|
||||
verifyTls: true,
|
||||
apiKey: 'secret==',
|
||||
readonly: false,
|
||||
...extra
|
||||
})
|
||||
|
||||
const target = (cfg: ConnectionConfig): BackendTarget<ConnectionConfig> => ({
|
||||
config: cfg,
|
||||
connectHost: '127.0.0.1',
|
||||
connectPort: cfg.port ?? 9200,
|
||||
serverName: cfg.host
|
||||
})
|
||||
|
||||
const fakeBackend = (body: unknown): EsBackend => ({
|
||||
request: async (): Promise<EsResponse> => ({ status: 200, body }),
|
||||
dispose: async () => {}
|
||||
})
|
||||
|
||||
describe('resolvePort', () => {
|
||||
it('honours an explicit port', () => {
|
||||
expect(resolvePort(config({ port: 9201 }))).toBe(9201)
|
||||
})
|
||||
|
||||
it('defaults to 9200 when absent', () => {
|
||||
expect(resolvePort(config())).toBe(9200)
|
||||
})
|
||||
})
|
||||
|
||||
describe('createBackend', () => {
|
||||
it('returns a backend with request/dispose and no network on construction', async () => {
|
||||
const backend = createBackend(target(config()))
|
||||
expect(typeof backend.request).toBe('function')
|
||||
expect(typeof backend.dispose).toBe('function')
|
||||
await backend.dispose()
|
||||
})
|
||||
})
|
||||
|
||||
describe('ping', () => {
|
||||
it('reports the ES version when present', async () => {
|
||||
const res = await ping({ backend: fakeBackend({ version: { number: '8.15.0' } }) })
|
||||
expect(res).toEqual({ status: 200, version: '8.15.0' })
|
||||
})
|
||||
|
||||
it('reports null when the version is absent', async () => {
|
||||
const res = await ping({ backend: fakeBackend({}) })
|
||||
expect(res).toEqual({ status: 200, version: null })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user