From 6453c499b0628e75f63ae8cdfdd473eaf59933d8 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 18 Apr 2019 14:28:46 -0700 Subject: [PATCH 1/3] test: increase coverage for dns.promises.lookup() Add coverage for uv_getaddrinfo() returning an error. --- test/parallel/test-dns-lookup.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-dns-lookup.js b/test/parallel/test-dns-lookup.js index 4fdfa1f4c22712..52ea02bbc41f81 100644 --- a/test/parallel/test-dns-lookup.js +++ b/test/parallel/test-dns-lookup.js @@ -4,12 +4,14 @@ const common = require('../common'); const assert = require('assert'); const { internalBinding } = require('internal/test/binding'); const cares = internalBinding('cares_wrap'); + +// Stub `getaddrinfo` to *always* error. This has to be done before we load the +// `dns` module to guarantee that the `dns` module uses the stub. +cares.getaddrinfo = () => internalBinding('uv').UV_ENOMEM; + const dns = require('dns'); const dnsPromises = dns.promises; -// Stub `getaddrinfo` to *always* error. -cares.getaddrinfo = () => internalBinding('uv').UV_ENOENT; - { const err = { code: 'ERR_INVALID_ARG_TYPE', @@ -144,15 +146,21 @@ dns.lookup('127.0.0.1', { let tickValue = 0; +// Should fail due to stub. dns.lookup('example.com', common.mustCall((error, result, addressType) => { assert(error); assert.strictEqual(tickValue, 1); - assert.strictEqual(error.code, 'ENOENT'); + assert.strictEqual(error.code, 'ENOMEM'); const descriptor = Object.getOwnPropertyDescriptor(error, 'message'); // The error message should be non-enumerable. assert.strictEqual(descriptor.enumerable, false); })); -// Make sure that the error callback is called -// on next tick. +// Make sure that the error callback is called on next tick. tickValue = 1; + +// Should fail due to stub. +dnsPromises.lookup('example.com').then( + common.mustNotCall(), + common.mustCall((error) => { assert.strictEqual(error.code, 'ENOMEM'); }) +); From e53a16cfe2bcb54b4e6d1cabd4bbca0ca1a950fa Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 18 Apr 2019 14:36:09 -0700 Subject: [PATCH 2/3] fixup! test: increase coverage for dns.promises.lookup() --- test/parallel/test-dns-lookup.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-dns-lookup.js b/test/parallel/test-dns-lookup.js index 52ea02bbc41f81..20b3918f1a95cc 100644 --- a/test/parallel/test-dns-lookup.js +++ b/test/parallel/test-dns-lookup.js @@ -162,5 +162,8 @@ tickValue = 1; // Should fail due to stub. dnsPromises.lookup('example.com').then( common.mustNotCall(), - common.mustCall((error) => { assert.strictEqual(error.code, 'ENOMEM'); }) + common.mustCall((error) => { + assert.strictEqual(error.code, 'ENOMEM'); + assert.strictEqual(error.hostname, 'example.com'); + }) ); From 15a200520120ee89c462b2dca46fbd079e4d9a07 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Thu, 18 Apr 2019 19:52:06 -0700 Subject: [PATCH 3/3] fixup! fixup! test: increase coverage for dns.promises.lookup() --- test/parallel/test-dns-lookup.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/test/parallel/test-dns-lookup.js b/test/parallel/test-dns-lookup.js index 20b3918f1a95cc..92943fd818b7e9 100644 --- a/test/parallel/test-dns-lookup.js +++ b/test/parallel/test-dns-lookup.js @@ -160,10 +160,5 @@ dns.lookup('example.com', common.mustCall((error, result, addressType) => { tickValue = 1; // Should fail due to stub. -dnsPromises.lookup('example.com').then( - common.mustNotCall(), - common.mustCall((error) => { - assert.strictEqual(error.code, 'ENOMEM'); - assert.strictEqual(error.hostname, 'example.com'); - }) -); +assert.rejects(dnsPromises.lookup('example.com'), + { code: 'ENOMEM', hostname: 'example.com' });