Skip to content
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
test: refactor and fix test-dns
* More precise length assertion.
* Fix incorrect use of string instead of RegExp in `throws` assertions.
* Add missing RegExp to `throws` assertions.

PR-URL: #9811
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
targos committed Dec 27, 2016
commit c34703e4d161dbf733d0bebe3d61882cd5d0b3a9
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