| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8f984c3 commit d766f5e
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,89 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const cares = process.binding('cares_wrap'); | ||
| 5 | + const dns = require('dns'); | ||
| 6 | + | ||
| 7 | + // Stub `getaddrinfo` to *always* error. | ||
| 8 | + cares.getaddrinfo = () => process.binding('uv').UV_ENOENT; | ||
| 9 | + | ||
| 10 | + assert.throws(() => { | ||
| 11 | + dns.lookup(1, {}); | ||
| 12 | + }, /^TypeError: Invalid arguments: hostname must be a string or falsey$/); | ||
| 13 | + | ||
| 14 | + assert.throws(() => { | ||
| 15 | + dns.lookup(false, 'cb'); | ||
| 16 | + }, /^TypeError: Invalid arguments: callback must be passed$/); | ||
| 17 | + | ||
| 18 | + assert.throws(() => { | ||
| 19 | + dns.lookup(false, 'options', 'cb'); | ||
| 20 | + }, /^TypeError: Invalid arguments: callback must be passed$/); | ||
| 21 | + | ||
| 22 | + assert.throws(() => { | ||
| 23 | + dns.lookup(false, { | ||
| 24 | + hints: 100, | ||
| 25 | + family: 0, | ||
| 26 | + all: false | ||
| 27 | + }, () => {}); | ||
| 28 | + }, /^TypeError: Invalid argument: hints must use valid flags$/); | ||
| 29 | + | ||
| 30 | + assert.throws(() => { | ||
| 31 | + dns.lookup(false, { | ||
| 32 | + hints: 0, | ||
| 33 | + family: 20, | ||
| 34 | + all: false | ||
| 35 | + }, () => {}); | ||
| 36 | + }, /^TypeError: Invalid argument: family must be 4 or 6$/); | ||
| 37 | + | ||
| 38 | + assert.doesNotThrow(() => { | ||
| 39 | + dns.lookup(false, { | ||
| 40 | + hints: 0, | ||
| 41 | + family: 0, | ||
| 42 | + all: true | ||
| 43 | + }, common.mustCall((error, result, addressType) => { | ||
| 44 | + assert.ifError(error); | ||
| 45 | + assert.deepStrictEqual(result, []); | ||
| 46 | + assert.strictEqual(addressType, undefined); | ||
| 47 | + })); | ||
| 48 | + }); | ||
| 49 | + | ||
| 50 | + assert.doesNotThrow(() => { | ||
| 51 | + dns.lookup('127.0.0.1', { | ||
| 52 | + hints: 0, | ||
| 53 | + family: 4, | ||
| 54 | + all: true | ||
| 55 | + }, common.mustCall((error, result, addressType) => { | ||
| 56 | + assert.ifError(error); | ||
| 57 | + assert.deepStrictEqual(result, [{ | ||
| 58 | + address: '127.0.0.1', | ||
| 59 | + family: 4 | ||
| 60 | + }]); | ||
| 61 | + assert.strictEqual(addressType, undefined); | ||
| 62 | + })); | ||
| 63 | + }); | ||
| 64 | + | ||
| 65 | + assert.doesNotThrow(() => { | ||
| 66 | + dns.lookup('127.0.0.1', { | ||
| 67 | + hints: 0, | ||
| 68 | + family: 4, | ||
| 69 | + all: false | ||
| 70 | + }, common.mustCall((error, result, addressType) => { | ||
| 71 | + assert.ifError(error); | ||
| 72 | + assert.deepStrictEqual(result, '127.0.0.1'); | ||
| 73 | + assert.strictEqual(addressType, 4); | ||
| 74 | + })); | ||
| 75 | + }); | ||
| 76 | + | ||
| 77 | + assert.doesNotThrow(() => { | ||
| 78 | + let tickValue = 0; | ||
| 79 | + | ||
| 80 | + dns.lookup('example.com', common.mustCall((error, result, addressType) => { | ||
| 81 | + assert(error); | ||
| 82 | + assert.strictEqual(tickValue, 1); | ||
| 83 | + assert.strictEqual(error.code, 'ENOENT'); | ||
| 84 | + })); | ||
| 85 | + | ||
| 86 | + // Make sure that the error callback is called | ||
| 87 | + // on next tick. | ||
| 88 | + tickValue = 1; | ||
| 89 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments