25 lines
2.4 KiB
TypeScript
25 lines
2.4 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { readStaticBgpConnection } from "./bgp-connection-read.js"
|
|
import type { MikrotikClient } from "./mikrotik.js"
|
|
|
|
let rows: unknown = [{ ".id": "*p", disabled: "false" }], dynamic: unknown = [], disabled: unknown = { ret: "false" }, selection: unknown = [{ ".id": "*p" }], posts = 0
|
|
const client: Pick<MikrotikClient, "get" | "post"> = {
|
|
get: async <T>() => structuredClone(rows) as T,
|
|
post: async <T>(path: string, body: Record<string, string | string[]>) => {
|
|
posts++
|
|
if (path.endsWith("/print")) { assert.deepEqual(body, { ".proplist": ".id,dynamic", ".query": [".id=*p", "-dynamic", "#&"] }); return structuredClone(selection) as T }
|
|
return structuredClone(body["value-name"] === "dynamic" ? dynamic : disabled) as T
|
|
},
|
|
}
|
|
assert.equal((await readStaticBgpConnection(client, "*p")).connection.dynamic, "false")
|
|
rows = [{ ".id": "*p", dynamic: false }]; assert.equal((await readStaticBgpConnection(client, "*p")).connection.disabled, "false")
|
|
for (const value of [true, "true", "yes"]) { rows = [{ ".id": "*p", disabled: "false", dynamic: value }]; await assert.rejects(readStaticBgpConnection(client, "*p"), (error: { code?: string }) => error.code === "STATE_CONFLICT") }
|
|
for (const value of ["?", "", 0, null]) { rows = [{ ".id": "*p", disabled: "false", dynamic: value }]; await assert.rejects(readStaticBgpConnection(client, "*p"), (error: { code?: string }) => error.code === "STATE_UNAVAILABLE") }
|
|
rows = [{ ".id": "*p", disabled: "?", dynamic: "false" }]; await assert.rejects(readStaticBgpConnection(client, "*p"))
|
|
rows = [{ ".id": "*p", disabled: "false" }]; selection = [{ ".id": "*other" }]; await assert.rejects(readStaticBgpConnection(client, "*p"))
|
|
selection = [{ ".id": "*p" }]; dynamic = { ret: false }; await assert.rejects(readStaticBgpConnection(client, "*p"))
|
|
dynamic = { ret: "false" }; assert.equal((await readStaticBgpConnection(client, "*p")).connection.dynamic, "false")
|
|
rows = [{ ".id": "*p", dynamic: "false" }]; disabled = []; await assert.rejects(readStaticBgpConnection(client, "*p"))
|
|
const before = posts; await assert.rejects(readStaticBgpConnection(client, "*missing")); assert.equal(posts, before)
|
|
console.log("Static BGP reader: exact D-flag negative selection, known bool normalization, dynamic vs unknown refusal, missing effective disabled, malformed get/selection and no property reads for a missing peer")
|