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 <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
Trott authored and codebytere committed Feb 17, 2020
1 parent 98f3028 commit c34872e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/parallel/test-dns-resolve-promises.js
Original file line number Diff line number Diff line change
@@ -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 c34872e

Please sign in to comment.