From 71a435e8b4393b8cf70222f750b7546cf9f4314c Mon Sep 17 00:00:00 2001 From: Ilarion Halushka Date: Sun, 9 Dec 2018 21:16:07 +0200 Subject: [PATCH] test: improve internet/test-dns * change 'for' loop to 'for of' loop * remove unused parameters passed to functions * remove unnecessary 'assert.ok' PR-URL: https://github.com/nodejs/node/pull/24927 Reviewed-By: Daniel Bevenius Reviewed-By: Ruben Bridgewater --- test/internet/test-dns.js | 43 ++++++++++++--------------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js index e4d863a77d5e7a..5d907ca6cb5980 100644 --- a/test/internet/test-dns.js +++ b/test/internet/test-dns.js @@ -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'); @@ -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'); @@ -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'); @@ -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'); } @@ -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'); @@ -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'); } @@ -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'); @@ -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); @@ -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'); } } @@ -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'); @@ -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); @@ -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));