import assert from "node:assert/strict" import { generateVxlanRsc, quoteRosString } from "./vxlan-export" import type { VxlanTunnel } from "./data" assert.equal(quoteRosString('edge "one"\\$value\r\n\t'), '"edge \\"one\\"\\\\\\$value\\0D\\0A\\09"') const tunnel: VxlanTunnel = { id: "1-*1", serverId: "1", name: 'vx "edge" $name\n/system reboot', vni: 200, port: 0, dstPort: 4789, vtepIp: "192.0.2.1", remoteVteps: ["198.51.100.1"], l2mtu: 1500, arpProxy: false, arpMode: "reply-only", macLearning: false, comment: 'note "quoted"\\$value\n/system reboot', enabled: false, status: "down" } const code = generateVxlanRsc(tunnel, {}) const commands = code.split("\n").filter(line => line.startsWith("/")) assert.equal(commands.length, 2) assert.match(commands[0], /vni=200 port=4789 arp="reply-only" learning=no disabled=yes/) assert.ok(commands[0].includes('local-address="192.0.2.1"')) assert.ok(commands[0].includes('comment="note \\"quoted\\"\\\\\\$value\\0A/system reboot"')) assert.ok(commands[1].includes('interface="vx \\"edge\\" \\$name\\0A/system reboot" remote-ip="198.51.100.1"')) for (const unsupported of ["vtep-mac-address", "arp-proxy=", "mac-learning=", "l2mtu=", "/interface/bridge/port/add", "\n/system reboot"]) assert.ok(!code.includes(unsupported), unsupported) const noLocal = generateVxlanRsc({ ...tunnel, vtepIp: "", arpMode: undefined, arpProxy: true }, {}) assert.ok(!noLocal.includes("local-address=")) assert.ok(noLocal.includes('arp="proxy-arp"')) console.log("vxlan-export: quoted strings, supported properties and no invented bridge passed")