import assert from "node:assert/strict" import { bgpPrefixRows } from "./bgp-prefix-model.js" const row = { ".id": "*b", "routing-table": "lab", "dst-address": "192.0.2.0/24", bgp: "true", dynamic: "true", distance: "0", password: "NEVER_PREFIX_SECRET" } assert.deepEqual(bgpPrefixRows([row], "lab", 4), [{ id: "*b", family: 4, table: "lab", prefix: "192.0.2.0/24", active: null, distance: 0 }]) assert.equal(bgpPrefixRows([{ ...row, active: "false" }], "lab", 4)[0].active, false) assert.equal(bgpPrefixRows([{ ...row, active: "true", distance: "20" }], "lab", 4)[0].active, true) assert.equal(bgpPrefixRows([{ ...row, "dst-address": "fd00::1/128" }], "lab", 6).length, 1) assert.deepEqual(bgpPrefixRows([{ ...row, "routing-table": "other", "dst-address": "invalid" }, { ...row, ".id": "*c", bgp: undefined, connect: "true" }], "lab", 4), []) for (const change of [{ dynamic: undefined }, { dynamic: "false" }, { static: "true" }, { "dst-address": "192.0.2.0/33" }, { "dst-address": "::1/128" }, { bgp: undefined }, { "routing-table": undefined }]) assert.throws(() => bgpPrefixRows([{ ...row, ...change }], "lab", 4)) assert.throws(() => bgpPrefixRows([row, row], "lab", 4)) assert.throws(() => bgpPrefixRows(Array.from({ length: 10001 }, (_, index) => ({ ...row, ".id": "*" + index })), "lab", 4)) console.log("BGP prefixes: native provenance, known zero/unknown active, bounded complete source, v4/v6, duplicate/ambiguous rejection and private field omission")