Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/core/posix-node/src/netif.test.ts
1067 views
1
import posix from "./index";
2
3
test("get name of internet interface 1 and verify it has length at least 1", () => {
4
expect(posix.if_indextoname?.(1)?.length).toBeGreaterThan(0);
5
});
6
7
test("getting invalid interface indexes throws", () => {
8
expect(() => {
9
posix.if_indextoname?.(0);
10
}).toThrow();
11
expect(() => {
12
posix.if_indextoname?.(99999);
13
}).toThrow();
14
});
15
16
test("go back and forth between interface 1 representations", () => {
17
const ifname1 = posix.if_indextoname?.(1);
18
if (ifname1 == null) {
19
throw Error("bug");
20
}
21
expect(posix.if_nametoindex?.(ifname1)).toBe(1);
22
});
23
24
test("getting invalid interface names throws", () => {
25
expect(() => {
26
posix.if_nametoindex?.("FUBAR");
27
}).toThrow();
28
expect(() => {
29
posix.if_nametoindex?.("");
30
}).toThrow();
31
});
32
33
test("get all of the interfaces, and do a consistency check", () => {
34
const ni = posix.if_nameindex?.();
35
if (ni == null) {
36
throw Error("bug");
37
}
38
for (const x of ni) {
39
expect(posix.if_indextoname?.(x[0])).toBe(x[1]);
40
expect(posix.if_nametoindex?.(x[1])).toBe(x[0]);
41
}
42
});
43
44