Files
MikrotikManager/backend/src/services/vxlan-live.test.ts
T

67 lines
2.1 KiB
TypeScript

import assert from "node:assert/strict"
import { mapVxlanRow, pollVxlanServers } from "./vxlan-live.js"
const server = {
id: 7,
name: "mt-msk",
host: "10.0.0.1",
site: "MSK",
country: "RU",
} as Parameters<typeof mapVxlanRow>[0]
const row = mapVxlanRow(
server,
{
".id": "*3",
name: "vxlan-10",
vni: "10010",
port: "8472",
"local-address": "10.0.0.1",
running: "true",
disabled: "false",
l2mtu: "1500",
"mac-learning": "true",
"arp-proxy": "true",
comment: "overlay",
},
[
{ interface: "vxlan-10", "remote-ip": "10.0.1.1" },
{ interface: "other", "remote-ip": "1.1.1.1" },
{ interface: "vxlan-10", "remote-ip": "10.0.2.1" },
],
0,
)
assert.equal(row.serverId, "7")
assert.equal(row.vni, 10010)
assert.equal(row.dstPort, 8472)
assert.equal(row.status, "up")
assert.equal(row.enabled, true)
assert.deepEqual(row.remoteVteps, ["10.0.1.1", "10.0.2.1"])
assert.equal(row.vtepIp, "10.0.0.1")
console.log("vxlan-live.test.ts: ok")
const mixed = await pollVxlanServers([server, { ...server, id: 8, name: "failed" }], async s => {
if (s.id === 8) throw new Error("device unavailable")
return [row]
})
assert.deepEqual(mixed.tunnels, [row])
assert.deepEqual(mixed.failures, [{ serverId: "8", serverName: "failed", error: "device unavailable" }])
const empty = await pollVxlanServers([server], async () => [])
assert.deepEqual(empty, { tunnels: [], failures: [] })
const failed = await pollVxlanServers([server], async () => { throw new Error("all failed") })
assert.equal(failed.tunnels.length, 0)
assert.equal(failed.failures.length, 1)
console.log("vxlan polling: mixed/empty/all-failed ok")
for (const arp of ["disabled", "enabled", "local-proxy-arp", "proxy-arp", "reply-only"] as const) {
const mapped = mapVxlanRow(server, { ".id": "*4", name: "vx", arp, learning: "no" }, [], 0)
assert.equal(mapped.arpMode, arp)
assert.equal(mapped.arpProxy, arp === "proxy-arp" || arp === "local-proxy-arp")
assert.equal(mapped.macLearning, false)
}
console.log("vxlan: exact ARP modes and RouterOS no-learning passed")
assert.equal(mapVxlanRow(server, { arp: "enabled", "arp-proxy": "true" }, [], 0).arpProxy, false)