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: refactor and fix test-dns #9811

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
46 changes: 24 additions & 22 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');

const existing = dns.getServers();
assert(existing.length);
assert(existing.length > 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this change? I don't get it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it less confusing that way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks.


// Verify that setServers() handles arrays with holes and other oddities
assert.doesNotThrow(() => {
Expand Down Expand Up @@ -42,7 +42,8 @@ const goog = [
];
assert.doesNotThrow(() => dns.setServers(goog));
assert.deepStrictEqual(dns.getServers(), goog);
assert.throws(() => dns.setServers(['foobar']));
assert.throws(() => dns.setServers(['foobar']),
/^Error: IP address is not properly formatted: foobar$/);
assert.deepStrictEqual(dns.getServers(), goog);

const goog6 = [
Expand Down Expand Up @@ -77,20 +78,18 @@ assert.throws(() => {
}, 'Unexpected error');

// dns.lookup should accept falsey and string values
assert.throws(() => dns.lookup({}, noop),
'invalid arguments: hostname must be a string or falsey');
const errorReg =
/^TypeError: Invalid arguments: hostname must be a string or falsey$/;

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

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

assert.throws(() => dns.lookup(1, noop),
'invalid arguments: hostname must be a string or falsey');
assert.throws(() => dns.lookup(true, noop), errorReg);

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

assert.throws(() => dns.lookup(noop, noop), errorReg);

assert.doesNotThrow(() => dns.lookup('', noop));

Expand All @@ -114,13 +113,13 @@ assert.doesNotThrow(() => dns.lookup(NaN, noop));
assert.throws(() => {
dns.lookup('www.google.com', { hints: (dns.V4MAPPED | dns.ADDRCONFIG) + 1 },
noop);
});
}, /^TypeError: Invalid argument: hints must use valid flags$/);

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

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

assert.doesNotThrow(() => dns.lookup('www.google.com', 6, noop));

Expand All @@ -143,26 +142,29 @@ assert.doesNotThrow(() => {
}, noop);
});

assert.throws(() => dns.lookupService('0.0.0.0'), /Invalid arguments/);
assert.throws(() => dns.lookupService('0.0.0.0'),
/^Error: Invalid arguments$/);

assert.throws(() => dns.lookupService('fasdfdsaf', 0, noop),
/"host" argument needs to be a valid IP address/);
/^TypeError: "host" argument needs to be a valid IP address$/);

assert.doesNotThrow(() => dns.lookupService('0.0.0.0', '0', noop));

assert.doesNotThrow(() => dns.lookupService('0.0.0.0', 0, noop));

assert.throws(() => dns.lookupService('0.0.0.0', null, noop),
/"port" should be >= 0 and < 65536, got "null"/);
/^TypeError: "port" should be >= 0 and < 65536, got "null"$/);

assert.throws(() => dns.lookupService('0.0.0.0', undefined, noop),
/"port" should be >= 0 and < 65536, got "undefined"/);
assert.throws(
() => dns.lookupService('0.0.0.0', undefined, noop),
/^TypeError: "port" should be >= 0 and < 65536, got "undefined"$/
);

assert.throws(() => dns.lookupService('0.0.0.0', 65538, noop),
/"port" should be >= 0 and < 65536, got "65538"/);
/^TypeError: "port" should be >= 0 and < 65536, got "65538"$/);

assert.throws(() => dns.lookupService('0.0.0.0', 'test', noop),
/"port" should be >= 0 and < 65536, got "test"/);
/^TypeError: "port" should be >= 0 and < 65536, got "test"$/);

assert.throws(() => dns.lookupService('0.0.0.0', 80, null),
/^TypeError: "callback" argument must be a function$/);