| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9d65724 commit 4e789a3
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -419,7 +419,26 @@ called before the callback is invoked. | |||
| 419 | 419 | ||
| 420 | 420 | ## DNS Module | |
| 421 | 421 | ||
| 422 | - The `DNS` module provides a naïve DNS parser/serializer. | ||
| 422 | + The `DNS` module provides utilities related to the `dns` built-in module. | ||
| 423 | + | ||
| 424 | + ### errorLookupMock(code, syscall) | ||
| 425 | + | ||
| 426 | + * `code` [<String>] Defaults to `dns.mockedErrorCode`. | ||
| 427 | + * `syscall` [<String>] Defaults to `dns.mockedSysCall`. | ||
| 428 | + * return [<Function>] | ||
| 429 | + | ||
| 430 | + | ||
| 431 | + A mock for the `lookup` option of `net.connect()` that would result in an error | ||
| 432 | + with the `code` and the `syscall` specified. Returns a function that has the | ||
| 433 | + same signature as `dns.lookup()`. | ||
| 434 | + | ||
| 435 | + ### mockedErrorCode | ||
| 436 | + | ||
| 437 | + The default `code` of errors generated by `errorLookupMock`. | ||
| 438 | + | ||
| 439 | + ### mockedSysCall | ||
| 440 | + | ||
| 441 | + The default `syscall` of errors generated by `errorLookupMock`. | ||
| 423 | 442 | ||
| 424 | 443 | ### readDomainFromPacket(buffer, offset) | |
| 425 | 444 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,6 @@ | |||
| 1 | 1 | /* eslint-disable required-modules */ | |
| 2 | 2 | 'use strict'; | |
| 3 | 3 | ||
| 4 | - // Naïve DNS parser/serializer. | ||
| 5 | - | ||
| 6 | 4 | const assert = require('assert'); | |
| 7 | 5 | const os = require('os'); | |
| 8 | 6 | ||
@@ -22,6 +20,8 @@ const classes = { | |||
| 22 | 20 | IN: 1 | |
| 23 | 21 | }; | |
| 24 | 22 | ||
| 23 | + // Naïve DNS parser/serializer. | ||
| 24 | + | ||
| 25 | 25 | function readDomainFromPacket(buffer, offset) { | |
| 26 | 26 | assert.ok(offset < buffer.length); | |
| 27 | 27 | const length = buffer[offset]; | |
@@ -287,6 +287,26 @@ function writeDNSPacket(parsed) { | |||
| 287 | 287 | })); | |
| 288 | 288 | } | |
| 289 | 289 | ||
| 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 | + | ||
| 290 | 304 | module.exports = { | |
| 291 | - types, classes, writeDNSPacket, parseDNSPacket | ||
| 305 | + types, | ||
| 306 | + classes, | ||
| 307 | + writeDNSPacket, | ||
| 308 | + parseDNSPacket, | ||
| 309 | + errorLookupMock, | ||
| 310 | + mockedErrorCode, | ||
| 311 | + mockedSysCall | ||
| 292 | 312 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments