Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: increase coverage for dns.promises.lookup() #27299

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions test/parallel/test-dns-lookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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' });