import { test } from '@edgeros/tapes' import { createTestClientAndKeys, tearDownTestClient } from './util' import { DBClient, castGrpcErrorMessage, WatchStreamEnded, castGrpcError, type ETCDClientOptions } from '../index' test('client-etcd', async (t) => { t.plan(1) const client = await createTestClientAndKeys() t.equal(await client.get('foo1').string(), 'bar1') await tearDownTestClient(client) t.end() }) // test('client-sqlite', async (t) => { // t.plan(1) // const client = new DBClient({ // sqlite: { // path: '/va/lib/ddp', // }, // }) // await client.init() // client.close() // t.pass('client-sqlite') // t.end() // }) test('client-etcd withConnection non error', async (t) => { const options = { etcd: { hosts: '10.12.0.204:2379', }, } const client = new DBClient(options) await client.init() try { // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- l // @ts-ignore client.dbDriver.client.hosts = [] // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- l // @ts-ignore await client.dbDriver.withConnection('KV', () => { throw new Error() }) } catch (error) { t.pass('client-etcd withConnection non error') } finally { client.close() } t.end() }) test('client-etcd mulit host', async (t) => { const options: ETCDClientOptions = { etcd: { hosts: ['10.12.0.204:2379', '10.12.0.204:2379'], }, } const client = new DBClient(options) await client.init() t.pass('client-etcd mulit host') client.close() t.end() }) test('client-etcd options hosts length 0', async (t) => { const h: string[] = [] const options: ETCDClientOptions = { etcd: { hosts: h, }, } try { const client = new DBClient(options) await client.init() } catch (error) { t.pass('client-etcd options hosts length 0') } t.end() }) test('some alone error', (t) => { castGrpcErrorMessage('like error') // eslint-disable-next-line @typescript-eslint/no-unused-vars -- i const stream = new WatchStreamEnded() castGrpcError(new Error('etcdserver error')) t.pass('some alone error') t.end() })