From 3a2cfccdd1caa269432120f428fa7f6269d79a82 Mon Sep 17 00:00:00 2001 From: Masashi Hirano Date: Wed, 27 Jun 2018 18:31:25 +0900 Subject: [PATCH 1/2] test: add tests for dnsPromises.lookup Added tests for dnsPromises.lookup to increase coverage and test `onlookup()` and `onlookupall()` methods. --- test/parallel/test-dns-lookup.js | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/test/parallel/test-dns-lookup.js b/test/parallel/test-dns-lookup.js index 99378ce01e918a..18c565bc1500db 100644 --- a/test/parallel/test-dns-lookup.js +++ b/test/parallel/test-dns-lookup.js @@ -1,6 +1,7 @@ // Flags: --expose-internals 'use strict'; const common = require('../common'); +const { addresses } = require('../common/internet'); const assert = require('assert'); const cares = process.binding('cares_wrap'); const dns = require('dns'); @@ -95,6 +96,45 @@ common.expectsError(() => { all: false }); assert.deepStrictEqual(res, { address: '127.0.0.1', family: 4 }); + + res = await dnsPromises.lookup(addresses.INET4_HOST, { + hints: 0, + family: 4, + all: false + }); + assert.strictEqual(res.family, 4); + + res = await dnsPromises.lookup(addresses.INET4_HOST, { + hints: 0, + family: 4, + all: true + }); + assert.ok(res.length > 0); + res.forEach((obj) => { assert.strictEqual(obj.family, 4); }); + + assert.rejects( + dnsPromises.lookup(addresses.INVALID_HOST, { + hints: 0, + family: 0, + all: false + }), + { + code: 'ENOTFOUND', + message: `getaddrinfo ENOTFOUND ${addresses.INVALID_HOST}` + } + ); + + assert.rejects( + dnsPromises.lookup(addresses.INVALID_HOST, { + hints: 0, + family: 0, + all: true + }), + { + code: 'ENOTFOUND', + message: `getaddrinfo ENOTFOUND ${addresses.INVALID_HOST}` + } + ); })(); dns.lookup(false, { From 116f6eb2a22288d3d9eb1f835f564cda1552b405 Mon Sep 17 00:00:00 2001 From: Masashi Hirano Date: Thu, 2 Aug 2018 01:02:24 +0900 Subject: [PATCH 2/2] test: remove tests that require the Internet in test-dns-lookup --- test/parallel/test-dns-lookup.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/test/parallel/test-dns-lookup.js b/test/parallel/test-dns-lookup.js index 18c565bc1500db..b45393718a3ccd 100644 --- a/test/parallel/test-dns-lookup.js +++ b/test/parallel/test-dns-lookup.js @@ -97,21 +97,6 @@ common.expectsError(() => { }); assert.deepStrictEqual(res, { address: '127.0.0.1', family: 4 }); - res = await dnsPromises.lookup(addresses.INET4_HOST, { - hints: 0, - family: 4, - all: false - }); - assert.strictEqual(res.family, 4); - - res = await dnsPromises.lookup(addresses.INET4_HOST, { - hints: 0, - family: 4, - all: true - }); - assert.ok(res.length > 0); - res.forEach((obj) => { assert.strictEqual(obj.family, 4); }); - assert.rejects( dnsPromises.lookup(addresses.INVALID_HOST, { hints: 0,