Files
MikrotikManager/lib/ospf-cost.test.ts

19 lines
1.1 KiB
TypeScript

import assert from "node:assert/strict"
import { test } from "node:test"
import { buildOspfCostIndex, ospfCostKey } from "./ospf-cost"
const iface = { serverId: 1, interface: "ether1", areaId: "0.0.0.0", cost: 7 }
test("neighbor cost is scoped to device, interface and area", () => {
const index = buildOspfCostIndex([iface, { ...iface, areaId: "0.0.0.1", cost: 42 }, { ...iface, serverId: 2, cost: 9 }])
assert.equal(index.get(ospfCostKey(1,"ether1","0.0.0.0")), 7)
assert.equal(index.get(ospfCostKey(1,"ether1","0.0.0.1")), 42)
assert.equal(index.get(ospfCostKey(2,"ether1","0.0.0.0")), 9)
assert.equal(index.get(ospfCostKey(3,"ether1","0.0.0.0")), undefined)
})
test("conflicting or invalid template costs do not choose a fabricated value", () => {
const key = ospfCostKey(1,"ether1","0.0.0.0")
assert.equal(buildOspfCostIndex([iface, iface]).get(key), 7)
assert.equal(buildOspfCostIndex([{ ...iface, cost: 0 }]).get(key), 0)
assert.equal(buildOspfCostIndex([iface, { ...iface, cost: 42 }, iface]).get(key), null)
for (const cost of [null, -1, 65536, 1.5]) assert.equal(buildOspfCostIndex([{ ...iface, cost }]).get(key), null)
})