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 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.