36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
|
|
// Tests for VyOS install option parsing.
|
||
|
|
|
||
|
|
import { describe, it, expect } from "vitest";
|
||
|
|
import { parseVlan } from "../src/commands/install.js";
|
||
|
|
|
||
|
|
describe("parseVlan", () => {
|
||
|
|
it("parses id and CIDR", () => {
|
||
|
|
expect(parseVlan("10:10.0.10.1/24")).toEqual([{ id: 10, address: "10.0.10.1/24" }]);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("accumulates across repeated flags", () => {
|
||
|
|
const first = parseVlan("10:10.0.10.1/24");
|
||
|
|
const both = parseVlan("20:10.0.20.1/24", first);
|
||
|
|
expect(both).toHaveLength(2);
|
||
|
|
expect(both[1]).toEqual({ id: 20, address: "10.0.20.1/24" });
|
||
|
|
});
|
||
|
|
|
||
|
|
it("keeps a description, including one containing colons", () => {
|
||
|
|
expect(parseVlan("30:10.0.30.1/24:mgmt:secondary")).toEqual([
|
||
|
|
{ id: 30, address: "10.0.30.1/24", description: "mgmt:secondary" },
|
||
|
|
]);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("rejects an address that is not CIDR", () => {
|
||
|
|
// A bare address would produce a VyOS config that fails to commit on first
|
||
|
|
// boot, long after the operator has stopped watching.
|
||
|
|
expect(() => parseVlan("10:10.0.10.1")).toThrow(/CIDR/);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("rejects out-of-range and non-numeric VLAN ids", () => {
|
||
|
|
expect(() => parseVlan("0:10.0.10.1/24")).toThrow(/1-4094/);
|
||
|
|
expect(() => parseVlan("4095:10.0.10.1/24")).toThrow(/1-4094/);
|
||
|
|
expect(() => parseVlan("abc:10.0.10.1/24")).toThrow(/1-4094/);
|
||
|
|
});
|
||
|
|
});
|