GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: add common.dns.errorLookupMock · nodejs/node@34af494

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/common
    • README.md
    • dns.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/common/README.md‎

Copy file name to clipboardExpand all lines: test/common/README.md
+20-1Lines changed: 20 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,26 @@ called before the callback is invoked.
404404

405405
## DNS Module
406406

407-
The `DNS` module provides a naïve DNS parser/serializer.
407+
The `DNS` module provides utilities related to the `dns` built-in module.
408+
409+
### errorLookupMock(code, syscall)
410+
411+
* `code` [<String>] Defaults to `dns.mockedErrorCode`.
412+
* `syscall` [<String>] Defaults to `dns.mockedSysCall`.
413+
* return [<Function>]
414+
415+
416+
A mock for the `lookup` option of `net.connect()` that would result in an error
417+
with the `code` and the `syscall` specified. Returns a function that has the
418+
same signature as `dns.lookup()`.
419+
420+
### mockedErrorCode
421+
422+
The default `code` of errors generated by `errorLookupMock`.
423+
424+
### mockedSysCall
425+
426+
The default `syscall` of errors generated by `errorLookupMock`.
408427

409428
### readDomainFromPacket(buffer, offset)
410429

Collapse file

‎test/common/dns.js‎

Copy file name to clipboardExpand all lines: test/common/dns.js
+23-3Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* eslint-disable required-modules */
22
'use strict';
33

4-
// Naïve DNS parser/serializer.
5-
64
const assert = require('assert');
75
const os = require('os');
86

@@ -22,6 +20,8 @@ const classes = {
2220
IN: 1
2321
};
2422

23+
// Naïve DNS parser/serializer.
24+
2525
function readDomainFromPacket(buffer, offset) {
2626
assert.ok(offset < buffer.length);
2727
const length = buffer[offset];
@@ -287,6 +287,26 @@ function writeDNSPacket(parsed) {
287287
}));
288288
}
289289

290+
const mockedErrorCode = 'ENOTFOUND';
291+
const mockedSysCall = 'getaddrinfo';
292+
293+
function errorLookupMock(code = mockedErrorCode, syscall = mockedSysCall) {
294+
return function lookupWithError(host, dnsopts, cb) {
295+
const err = new Error(`${syscall} ${code} ${host}`);
296+
err.code = code;
297+
err.errno = code;
298+
err.syscall = syscall;
299+
err.hostname = host;
300+
cb(err);
301+
};
302+
}
303+
290304
module.exports = {
291-
types, classes, writeDNSPacket, parseDNSPacket
305+
types,
306+
classes,
307+
writeDNSPacket,
308+
parseDNSPacket,
309+
errorLookupMock,
310+
mockedErrorCode,
311+
mockedSysCall
292312
};

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.