posix-node
Version:
Missing Posix Functions for Node.js (via a native module written in Zig)
43 lines • 1.53 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = __importDefault(require("./index"));
test("get name of internet interface 1 and verify it has length at least 1", () => {
expect(index_1.default.if_indextoname?.(1)?.length).toBeGreaterThan(0);
});
test("getting invalid interface indexes throws", () => {
expect(() => {
index_1.default.if_indextoname?.(0);
}).toThrow();
expect(() => {
index_1.default.if_indextoname?.(99999);
}).toThrow();
});
test("go back and forth between interface 1 representations", () => {
const ifname1 = index_1.default.if_indextoname?.(1);
if (ifname1 == null) {
throw Error("bug");
}
expect(index_1.default.if_nametoindex?.(ifname1)).toBe(1);
});
test("getting invalid interface names throws", () => {
expect(() => {
index_1.default.if_nametoindex?.("FUBAR");
}).toThrow();
expect(() => {
index_1.default.if_nametoindex?.("");
}).toThrow();
});
test("get all of the interfaces, and do a consistency check", () => {
const ni = index_1.default.if_nameindex?.();
if (ni == null) {
throw Error("bug");
}
for (const x of ni) {
expect(index_1.default.if_indextoname?.(x[0])).toBe(x[1]);
expect(index_1.default.if_nametoindex?.(x[1])).toBe(x[0]);
}
});
//# sourceMappingURL=netif.test.js.map
;