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

v4.x: backport test: refactor and fix test-dns #10470

Closed
wants to merge 1 commit 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
30 changes: 17 additions & 13 deletions test/parallel/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const assert = require('assert');
const dns = require('dns');

var existing = dns.getServers();
assert(existing.length);
assert(existing.length > 0);

function noop() {}

Expand All @@ -15,7 +15,8 @@ var goog = [
];
assert.doesNotThrow(function() { dns.setServers(goog); });
assert.deepEqual(dns.getServers(), goog);
assert.throws(function() { dns.setServers(['foobar']); });
assert.throws(function() { dns.setServers(['foobar']); },
/^Error: IP address is not properly formatted: foobar$/);
assert.deepEqual(dns.getServers(), goog);

var goog6 = [
Expand Down Expand Up @@ -50,25 +51,28 @@ assert.throws(function() {
}, 'Unexpected error');

// dns.lookup should accept falsey and string values
const errorReg =
/^TypeError: invalid arguments: hostname must be a string or falsey$/;

assert.throws(function() {
dns.lookup({}, noop);
}, 'invalid arguments: hostname must be a string or falsey');
}, errorReg);

assert.throws(function() {
dns.lookup([], noop);
}, 'invalid arguments: hostname must be a string or falsey');
}, errorReg);

assert.throws(function() {
dns.lookup(true, noop);
}, 'invalid arguments: hostname must be a string or falsey');
}, errorReg);

assert.throws(function() {
dns.lookup(1, noop);
}, 'invalid arguments: hostname must be a string or falsey');
}, errorReg);

assert.throws(function() {
dns.lookup(noop, noop);
}, 'invalid arguments: hostname must be a string or falsey');
}, errorReg);

assert.doesNotThrow(function() {
dns.lookup('', noop);
Expand Down Expand Up @@ -102,15 +106,15 @@ assert.doesNotThrow(function() {
assert.throws(function() {
dns.lookup('www.google.com', { hints: (dns.V4MAPPED | dns.ADDRCONFIG) + 1 },
noop);
});
}, /^TypeError: invalid argument: hints must use valid flags$/);

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

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

assert.doesNotThrow(function() {
dns.lookup('www.google.com', 6, noop);
Expand Down Expand Up @@ -148,15 +152,15 @@ assert.doesNotThrow(function() {

assert.throws(function() {
dns.lookupService('0.0.0.0');
}, /invalid arguments/);
}, /^Error: invalid arguments$/);

assert.throws(function() {
dns.lookupService('fasdfdsaf', 0, noop);
}, /host needs to be a valid IP address/);
}, /^TypeError: host needs to be a valid IP address$/);

assert.throws(function() {
dns.lookupService('0.0.0.0', '0', noop);
}, /port argument must be a number, got "0"/);
}, /^TypeError: port argument must be a number, got "0"$/);

assert.doesNotThrow(function() {
dns.lookupService('0.0.0.0', 0, noop);
Expand Down