test(net): add test of getNetworkAddress() (#5963)

This commit is contained in:
Yoshiya Hinosawa 2024-09-12 15:23:26 +09:00 committed by GitHub
parent 93ccb64f09
commit 7d3dd2db03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,12 +8,21 @@ const INTERFACES: Deno.NetworkInterfaceInfo[] = [
{ {
family: "IPv4", family: "IPv4",
name: "lo0", name: "lo0",
address: "127.0.0.1", address: "127.0.0.1", // The interface with the addreess starting with 127 is skipped
netmask: "255.0.0.0", netmask: "255.0.0.0",
scopeid: null, scopeid: null,
cidr: "127.0.0.1/8", cidr: "127.0.0.1/8",
mac: "00:00:00:00:00:00", mac: "00:00:00:00:00:00",
}, },
{
family: "IPv4",
name: "lo",
address: "10.255.255.254",
netmask: "255.255.255.255",
scopeid: null,
cidr: "10.255.255.254/32",
mac: "00:00:00:00:00:00", // The interface with MAC addreess 00:00:00:00:00:00 is skipped
},
{ {
family: "IPv6", family: "IPv6",
name: "lo0", name: "lo0",
@ -69,7 +78,7 @@ Deno.test("getNetworkAddress() works with IPv4", () => {
() => INTERFACES, () => INTERFACES,
); );
const hostname = getNetworkAddress(); const hostname = getNetworkAddress();
assertEquals(hostname, INTERFACES[4]!.address); assertEquals(hostname, INTERFACES[5]!.address);
}); });
Deno.test("getNetworkAddress() returns listenable IPv4 address", () => { Deno.test("getNetworkAddress() returns listenable IPv4 address", () => {
@ -87,7 +96,7 @@ Deno.test("getNetworkAddress() works with IPv6", () => {
() => INTERFACES, () => INTERFACES,
); );
const hostname = getNetworkAddress("IPv6"); const hostname = getNetworkAddress("IPv6");
assertEquals(hostname, INTERFACES[5]!.address); assertEquals(hostname, INTERFACES[6]!.address);
}); });
Deno.test("getNetworkAddress() returns listenable IPv6 address", () => { Deno.test("getNetworkAddress() returns listenable IPv6 address", () => {