Skip to content

Commit

Permalink
test: improve internet/test-dns
Browse files Browse the repository at this point in the history
* change 'for' loop to 'for of' loop
* remove unused parameters passed to functions
* remove unnecessary 'assert.ok'

PR-URL: #24927
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
IlarionHalushka authored and BethGriggs committed Feb 20, 2019
1 parent 11287f8 commit 71a435e
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions test/internet/test-dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ TEST(async function test_resolve4_ttl(done) {
function validateResult(result) {
assert.ok(result.length > 0);

for (let i = 0; i < result.length; i++) {
const item = result[i];
assert.ok(item);
for (const item of result) {
assert.strictEqual(typeof item, 'object');
assert.strictEqual(typeof item.ttl, 'number');
assert.strictEqual(typeof item.address, 'string');
Expand Down Expand Up @@ -111,9 +109,7 @@ TEST(async function test_resolve6_ttl(done) {
function validateResult(result) {
assert.ok(result.length > 0);

for (let i = 0; i < result.length; i++) {
const item = result[i];
assert.ok(item);
for (const item of result) {
assert.strictEqual(typeof item, 'object');
assert.strictEqual(typeof item.ttl, 'number');
assert.strictEqual(typeof item.address, 'string');
Expand Down Expand Up @@ -141,9 +137,7 @@ TEST(async function test_resolveMx(done) {
function validateResult(result) {
assert.ok(result.length > 0);

for (let i = 0; i < result.length; i++) {
const item = result[i];
assert.ok(item);
for (const item of result) {
assert.strictEqual(typeof item, 'object');
assert.ok(item.exchange);
assert.strictEqual(typeof item.exchange, 'string');
Expand Down Expand Up @@ -183,9 +177,7 @@ TEST(async function test_resolveNs(done) {
function validateResult(result) {
assert.ok(result.length > 0);

for (let i = 0; i < result.length; i++) {
const item = result[i];

for (const item of result) {
assert.ok(item);
assert.strictEqual(typeof item, 'string');
}
Expand Down Expand Up @@ -223,14 +215,10 @@ TEST(async function test_resolveSrv(done) {
function validateResult(result) {
assert.ok(result.length > 0);

for (let i = 0; i < result.length; i++) {
const item = result[i];
assert.ok(item);
for (const item of result) {
assert.strictEqual(typeof item, 'object');

assert.ok(item.name);
assert.strictEqual(typeof item.name, 'string');

assert.strictEqual(typeof item.port, 'number');
assert.strictEqual(typeof item.priority, 'number');
assert.strictEqual(typeof item.weight, 'number');
Expand Down Expand Up @@ -269,8 +257,7 @@ TEST(async function test_resolvePtr(done) {
function validateResult(result) {
assert.ok(result.length > 0);

for (let i = 0; i < result.length; i++) {
const item = result[i];
for (const item of result) {
assert.ok(item);
assert.strictEqual(typeof item, 'string');
}
Expand Down Expand Up @@ -308,9 +295,7 @@ TEST(async function test_resolveNaptr(done) {
function validateResult(result) {
assert.ok(result.length > 0);

for (let i = 0; i < result.length; i++) {
const item = result[i];
assert.ok(item);
for (const item of result) {
assert.strictEqual(typeof item, 'object');
assert.strictEqual(typeof item.flags, 'string');
assert.strictEqual(typeof item.service, 'string');
Expand Down Expand Up @@ -351,7 +336,6 @@ TEST(function test_resolveNaptr_failure(done) {

TEST(async function test_resolveSoa(done) {
function validateResult(result) {
assert.ok(result);
assert.strictEqual(typeof result, 'object');
assert.strictEqual(typeof result.nsname, 'string');
assert.ok(result.nsname.length > 0);
Expand Down Expand Up @@ -401,10 +385,9 @@ TEST(async function test_resolveCname(done) {
function validateResult(result) {
assert.ok(result.length > 0);

for (let i = 0; i < result.length; i++) {
const name = result[i];
assert.ok(name);
assert.strictEqual(typeof name, 'string');
for (const item of result) {
assert.ok(item);
assert.strictEqual(typeof item, 'string');
}
}

Expand Down Expand Up @@ -478,7 +461,7 @@ TEST(function test_lookup_failure(done) {
.then(common.mustNotCall())
.catch(common.expectsError({ errno: dns.NOTFOUND }));

const req = dns.lookup(addresses.INVALID_HOST, 4, (err, ip, family) => {
const req = dns.lookup(addresses.INVALID_HOST, 4, (err) => {
assert.ok(err instanceof Error);
assert.strictEqual(err.errno, dns.NOTFOUND);
assert.strictEqual(err.errno, 'ENOTFOUND');
Expand Down Expand Up @@ -546,7 +529,7 @@ TEST(function test_lookup_ip_promise(done) {
TEST(async function test_lookup_null_all(done) {
assert.deepStrictEqual(await dnsPromises.lookup(null, { all: true }), []);

const req = dns.lookup(null, { all: true }, function(err, ips, family) {
const req = dns.lookup(null, { all: true }, (err, ips) => {
assert.ifError(err);
assert.ok(Array.isArray(ips));
assert.strictEqual(ips.length, 0);
Expand Down Expand Up @@ -592,7 +575,7 @@ TEST(function test_lookupservice_invalid(done) {
.then(common.mustNotCall())
.catch(common.expectsError({ code: 'ENOTFOUND' }));

const req = dns.lookupService('1.2.3.4', 80, function(err, host, service) {
const req = dns.lookupService('1.2.3.4', 80, (err) => {
assert(err instanceof Error);
assert.strictEqual(err.code, 'ENOTFOUND');
assert.ok(/1\.2\.3\.4/.test(err.message));
Expand Down

0 comments on commit 71a435e

Please sign in to comment.