mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 04:52:26 -05:00
move test case to tests/specs as NPM_CONFIG_REGISTRY is not set in js unit test
This commit is contained in:
parent
69bab0352e
commit
7d3c4ac956
4 changed files with 51 additions and 33 deletions
9
tests/specs/run/resolve_dns_edns0/__test__.jsonc
Normal file
9
tests/specs/run/resolve_dns_edns0/__test__.jsonc
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"tests": {
|
||||||
|
"resolve_dns": {
|
||||||
|
"args": "test --allow-net=127.0.0.1 test.ts",
|
||||||
|
"output": "test.out",
|
||||||
|
"exitCode": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
6
tests/specs/run/resolve_dns_edns0/test.out
Normal file
6
tests/specs/run/resolve_dns_edns0/test.out
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[WILDCARD]
|
||||||
|
running 1 test from ./test.ts
|
||||||
|
EDNS0 enabled ... ok ([WILDCARD]s)
|
||||||
|
|
||||||
|
ok | 1 passed | 0 failed ([WILDCARD]s)
|
||||||
|
|
36
tests/specs/run/resolve_dns_edns0/test.ts
Normal file
36
tests/specs/run/resolve_dns_edns0/test.ts
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||||
|
import dns2 from "npm:dns2@2.1.0";
|
||||||
|
|
||||||
|
Deno.test("EDNS0 enabled", async () => {
|
||||||
|
// With EDNS0 enabled, Deno.resolveDns can handle 44 A records.
|
||||||
|
const NUM_RECORD = 44;
|
||||||
|
const { Packet } = dns2;
|
||||||
|
const server = dns2.createServer({
|
||||||
|
udp: true,
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
handle(request: any, send: any) {
|
||||||
|
const response = Packet.createResponseFromRequest(request);
|
||||||
|
const { name } = request.questions[0];
|
||||||
|
for (const i of [...Array(NUM_RECORD).keys()]) {
|
||||||
|
response.answers.push({
|
||||||
|
name,
|
||||||
|
type: Packet.TYPE.A,
|
||||||
|
class: Packet.CLASS.IN,
|
||||||
|
ttl: 300,
|
||||||
|
address: "1.2.3." + i,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
send(response);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const { udp: { port } } = await server.listen({
|
||||||
|
udp: { port: 0, address: "127.0.0.1", type: "udp4" },
|
||||||
|
});
|
||||||
|
const addr = await Deno.resolveDns("example.com", "A", {
|
||||||
|
nameServer: { ipAddr: "127.0.0.1", port },
|
||||||
|
});
|
||||||
|
if (addr.length !== NUM_RECORD) {
|
||||||
|
throw new Error(`Expected ${NUM_RECORD} records, got ${addr.length}`);
|
||||||
|
}
|
||||||
|
await server.close();
|
||||||
|
});
|
|
@ -9,7 +9,6 @@ import {
|
||||||
execCode2,
|
execCode2,
|
||||||
tmpUnixSocketPath,
|
tmpUnixSocketPath,
|
||||||
} from "./test_util.ts";
|
} from "./test_util.ts";
|
||||||
import dns2 from "npm:dns2@2.1.0";
|
|
||||||
|
|
||||||
// Since these tests may run in parallel, ensure this port is unique to this file
|
// Since these tests may run in parallel, ensure this port is unique to this file
|
||||||
const listenPort = 4503;
|
const listenPort = 4503;
|
||||||
|
@ -1328,35 +1327,3 @@ Deno.test(
|
||||||
// calling [Symbol.dispose] after manual close is a no-op
|
// calling [Symbol.dispose] after manual close is a no-op
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
Deno.test({ permissions: { net: true } }, async function resolveDnsEdns0() {
|
|
||||||
// With EDNS0 enabled, Deno.resolveDns can handle 44 A records.
|
|
||||||
const NUM_RECORD = 44;
|
|
||||||
const { Packet } = dns2;
|
|
||||||
const server = dns2.createServer({
|
|
||||||
udp: true,
|
|
||||||
// deno-lint-ignore no-explicit-any
|
|
||||||
handle(request: any, send: any) {
|
|
||||||
const response = Packet.createResponseFromRequest(request);
|
|
||||||
const { name } = request.questions[0];
|
|
||||||
for (const i of [...Array(NUM_RECORD).keys()]) {
|
|
||||||
response.answers.push({
|
|
||||||
name,
|
|
||||||
type: Packet.TYPE.A,
|
|
||||||
class: Packet.CLASS.IN,
|
|
||||||
ttl: 300,
|
|
||||||
address: "1.2.3." + i,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
send(response);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const { udp: { port } } = await server.listen({
|
|
||||||
udp: { port: 0, address: "127.0.0.1", type: "udp4" },
|
|
||||||
});
|
|
||||||
const addr = await Deno.resolveDns("example.com", "A", {
|
|
||||||
nameServer: { ipAddr: "127.0.0.1", port },
|
|
||||||
});
|
|
||||||
assertEquals(addr.length, NUM_RECORD);
|
|
||||||
await server.close();
|
|
||||||
});
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue