UNPKG

posix-node

Version:

Missing Posix Functions for Node.js (via a native module written in Zig)

69 lines (68 loc) 2.52 kB
"use strict"; 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("gethostbyname consistency checks", () => { const hostent = index_1.default.gethostbyname?.("example.com"); if (hostent == null) throw Error("fail"); expect(hostent.h_name).toBe("example.com"); expect(hostent.h_aliases.length).toBe(0); expect(hostent.h_addrtype).toBe(2); expect(hostent.h_length).toBe(4); expect(hostent.h_addr_list.length).toBeGreaterThan(0); expect(hostent.h_addr_list[0]).toContain("."); }); /* Example: > require('.').gethostbyaddr("64.233.187.99") { h_name: 'tj-in-f99.1e100.net', h_addrtype: 2, h_length: 4, h_addr_list: [ '64.233.187.99' ], h_aliases: [ '99.187.233.64.in-addr.arpa' ] } */ test("gethostbyaddr check - v4", () => { const hostent = index_1.default.gethostbyaddr?.("64.233.187.99"); expect(hostent?.h_addr_list[0]).toContain("."); expect(hostent?.h_addrtype).toBe(index_1.default.constants?.AF_INET); }); test("gethostbyaddr check - v6", () => { const hostent = index_1.default.gethostbyaddr?.("2001:4860:4860::8888"); expect(hostent?.h_addr_list[0]).toContain(":"); expect(hostent?.h_addrtype).toBe(index_1.default.constants?.AF_INET6); // behavior depends on OS // expect(hostent?.h_aliases[0]).toContain("8.8.8.8"); }); test("getaddrinfo canonical name", () => { const addrinfo = index_1.default.getaddrinfo?.("example.com", "http", { flags: 2 }); if (addrinfo == null) throw Error("fail"); expect(addrinfo[0]?.ai_canonname).toEqual("example.com"); }); test("getaddrinfo isn't random garbled nonsense", () => { const addrinfo = index_1.default.getaddrinfo?.("example.com", "http", { flags: 2 }); if (addrinfo == null) throw Error("fail"); const addrinfo2 = index_1.default.getaddrinfo?.("example.com", "http", { flags: 2 }); if (addrinfo2 == null) throw Error("fail"); expect(addrinfo).toEqual(addrinfo2); }); // very OS dependent test("getting error messages", () => { expect(index_1.default.gai_strerror?.(0)).toEqual("Unknown error"); }); test("getaddrinfo error code", () => { try { index_1.default.getaddrinfo?.("google.com", "x"); } catch (err) { expect(err.code != null).toBe(true); } }); //# sourceMappingURL=netdb.test.js.map