Skip to content

test: split out hints from test-dns #5992

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions test/parallel/test-dns-lookup-hints-family.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
require('../common');
const assert = require('assert');

const dns = require('dns');

function noop() {}

dns.setServers([]);

assert.doesNotThrow(function() {
dns.lookup('www.google.com', {
family: 4,
hints: 0
}, noop);
});

assert.doesNotThrow(function() {
dns.lookup('www.google.com', {
family: 6,
hints: dns.ADDRCONFIG
}, noop);
});
51 changes: 51 additions & 0 deletions test/parallel/test-dns-lookup-hints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict';
require('../common');
const assert = require('assert');

const dns = require('dns');

function noop() {}

dns.setServers([]);

/*
* Make sure that dns.lookup throws if hints does not represent a valid flag.
* (dns.V4MAPPED | dns.ADDRCONFIG) + 1 is invalid because:
* - it's different from dns.V4MAPPED and dns.ADDRCONFIG.
* - it's different from them bitwise ored.
* - it's different from 0.
* - it's an odd number different than 1, and thus is invalid, because
* flags are either === 1 or even.
*/
assert.throws(function() {
dns.lookup('www.google.com', { hints: (dns.V4MAPPED | dns.ADDRCONFIG) + 1 },
noop);
});

assert.throws(function() {
dns.lookup('www.google.com');
}, 'invalid arguments: callback must be passed');

assert.throws(function() {
dns.lookup('www.google.com', 4);
}, 'invalid arguments: callback must be passed');

assert.doesNotThrow(function() {
dns.lookup('www.google.com', 6, noop);
});

assert.doesNotThrow(function() {
dns.lookup('www.google.com', {}, noop);
});

assert.doesNotThrow(function() {
dns.lookup('www.google.com', {
hints: dns.V4MAPPED
}, noop);
});

assert.doesNotThrow(function() {
dns.lookup('www.google.com', {
hints: dns.ADDRCONFIG | dns.V4MAPPED
}, noop);
});
56 changes: 0 additions & 56 deletions test/parallel/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,62 +90,6 @@ assert.doesNotThrow(function() {
dns.lookup(NaN, noop);
});

/*
* Make sure that dns.lookup throws if hints does not represent a valid flag.
* (dns.V4MAPPED | dns.ADDRCONFIG) + 1 is invalid because:
* - it's different from dns.V4MAPPED and dns.ADDRCONFIG.
* - it's different from them bitwise ored.
* - it's different from 0.
* - it's an odd number different than 1, and thus is invalid, because
* flags are either === 1 or even.
*/
assert.throws(function() {
dns.lookup('www.google.com', { hints: (dns.V4MAPPED | dns.ADDRCONFIG) + 1 },
noop);
});

assert.throws(function() {
dns.lookup('www.google.com');
}, 'invalid arguments: callback must be passed');

assert.throws(function() {
dns.lookup('www.google.com', 4);
}, 'invalid arguments: callback must be passed');

assert.doesNotThrow(function() {
dns.lookup('www.google.com', 6, noop);
});

assert.doesNotThrow(function() {
dns.lookup('www.google.com', {}, noop);
});

assert.doesNotThrow(function() {
dns.lookup('www.google.com', {
family: 4,
hints: 0
}, noop);
});

assert.doesNotThrow(function() {
dns.lookup('www.google.com', {
family: 6,
hints: dns.ADDRCONFIG
}, noop);
});

assert.doesNotThrow(function() {
dns.lookup('www.google.com', {
hints: dns.V4MAPPED
}, noop);
});

assert.doesNotThrow(function() {
dns.lookup('www.google.com', {
hints: dns.ADDRCONFIG | dns.V4MAPPED
}, noop);
});

assert.throws(function() {
dns.lookupService('0.0.0.0');
}, /Invalid arguments/);
Expand Down