From b2aca1b3d928a1129392385eb2861a13df6c967e Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 7 Feb 2020 05:54:01 -1000 Subject: [PATCH] test,dns: add coverage for dns exception Add test coverage for dns.promises.resolve() handling an exception from c-ares. Refs: https://coverage.nodejs.org/coverage-d213f21c72f77da6/lib/internal/dns/promises.js.html#L198 PR-URL: https://github.com/nodejs/node/pull/31678 Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig Reviewed-By: David Carlier Reviewed-By: Ruben Bridgewater --- test/parallel/test-dns-resolve-promises.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/parallel/test-dns-resolve-promises.js diff --git a/test/parallel/test-dns-resolve-promises.js b/test/parallel/test-dns-resolve-promises.js new file mode 100644 index 00000000000000..783ed2a709edb6 --- /dev/null +++ b/test/parallel/test-dns-resolve-promises.js @@ -0,0 +1,20 @@ +// Flags: --expose-internals +'use strict'; +require('../common'); +const assert = require('assert'); +const { internalBinding } = require('internal/test/binding'); +const cares = internalBinding('cares_wrap'); +const { UV_EPERM } = internalBinding('uv'); +const dnsPromises = require('dns').promises; + +// Stub cares to force an error so we can test DNS error code path. +cares.ChannelWrap.prototype.queryA = () => UV_EPERM; + +assert.rejects( + dnsPromises.resolve('example.org'), + { + code: 'EPERM', + syscall: 'queryA', + hostname: 'example.org' + } +);