From a6af2a7fab85a49044426cac2bdc0408e99f716b Mon Sep 17 00:00:00 2001 From: Masashi Hirano Date: Mon, 17 Sep 2018 17:57:08 +0900 Subject: [PATCH 1/2] test: add tests to check error in dns.lookupService. Added tests to check error in dns.lookupService to increase coverage. --- test/parallel/test-dns-lookupService.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/parallel/test-dns-lookupService.js diff --git a/test/parallel/test-dns-lookupService.js b/test/parallel/test-dns-lookupService.js new file mode 100644 index 00000000000000..7150be1a92add2 --- /dev/null +++ b/test/parallel/test-dns-lookupService.js @@ -0,0 +1,19 @@ +// Flags: --expose-internals +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const { internalBinding } = require('internal/test/binding'); +const cares = internalBinding('cares_wrap'); +const dns = require('dns'); + +// Stub `getnameinfo` to *always* error. +cares.getnameinfo = () => internalBinding('uv').UV_ENOENT; + +assert.throws( + () => dns.lookupService('127.0.0.1', 80, common.mustNotCall()), + { + code: 'ENOENT', + message: 'getnameinfo ENOENT 127.0.0.1', + syscall: 'getnameinfo' + } +); From 81280acad6a7c47932cbb4b2f87ca683d8ae45b0 Mon Sep 17 00:00:00 2001 From: shisama Date: Tue, 18 Sep 2018 15:13:10 +0900 Subject: [PATCH 2/2] test: assign to a variable --- test/parallel/test-dns-lookupService.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-dns-lookupService.js b/test/parallel/test-dns-lookupService.js index 7150be1a92add2..92fce6cbd3f189 100644 --- a/test/parallel/test-dns-lookupService.js +++ b/test/parallel/test-dns-lookupService.js @@ -4,10 +4,11 @@ const common = require('../common'); const assert = require('assert'); const { internalBinding } = require('internal/test/binding'); const cares = internalBinding('cares_wrap'); +const { UV_ENOENT } = internalBinding('uv'); const dns = require('dns'); // Stub `getnameinfo` to *always* error. -cares.getnameinfo = () => internalBinding('uv').UV_ENOENT; +cares.getnameinfo = () => UV_ENOENT; assert.throws( () => dns.lookupService('127.0.0.1', 80, common.mustNotCall()),