Skip to content

Commit

Permalink
test,dns: add coverage for dns exception
Browse files Browse the repository at this point in the history
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: #31678
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
Trott authored and codebytere committed Mar 30, 2020
1 parent fbc0bd9 commit 99cfab2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 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'
}
);

0 comments on commit 99cfab2

Please sign in to comment.