summaryrefslogtreecommitdiff
path: root/test/parallel/test-dns-lookup.js
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2019-04-18 14:28:46 -0700
committerRich Trott <rtrott@gmail.com>2019-04-20 19:05:39 -0700
commit7167eb2f12a5070c79d4373a0ac0010e6154c22e (patch)
tree154148bab568f13e94e1fb9aea13f2ad8984f189 /test/parallel/test-dns-lookup.js
parent0fc27f6bc0a5ca8bc2a6458ee61b78906840ea7e (diff)
downloadandroid-node-v8-7167eb2f12a5070c79d4373a0ac0010e6154c22e.tar.gz
android-node-v8-7167eb2f12a5070c79d4373a0ac0010e6154c22e.tar.bz2
android-node-v8-7167eb2f12a5070c79d4373a0ac0010e6154c22e.zip
test: increase coverage for dns.promises.lookup()
Add coverage for uv_getaddrinfo() returning an error. PR-URL: https://github.com/nodejs/node/pull/27299 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/parallel/test-dns-lookup.js')
-rw-r--r--test/parallel/test-dns-lookup.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/test/parallel/test-dns-lookup.js b/test/parallel/test-dns-lookup.js
index 4fdfa1f4c2..92943fd818 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,19 @@ 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.
+assert.rejects(dnsPromises.lookup('example.com'),
+ { code: 'ENOMEM', hostname: 'example.com' });