diff options
author | Ilarion Halushka <hilarion.galushka@gmail.com> | 2018-12-09 21:16:07 +0200 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-12-12 07:15:07 -0800 |
commit | a0bdeb553068d844dbe6005f0080620f1d0a673f (patch) | |
tree | 9bc7dc71cc7ec60d5d0136e2fa942e473c9775cd /test/internet | |
parent | f194b7f6261b065726b2850582b4969059b64fa1 (diff) | |
download | node-new-a0bdeb553068d844dbe6005f0080620f1d0a673f.tar.gz |
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 <daniel.bevenius@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/internet')
-rw-r--r-- | test/internet/test-dns.js | 43 |
1 files changed, 13 insertions, 30 deletions
diff --git a/test/internet/test-dns.js b/test/internet/test-dns.js index 1f6639b2d5..3d331fd196 100644 --- a/test/internet/test-dns.js +++ b/test/internet/test-dns.js @@ -83,9 +83,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'); @@ -113,9 +111,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'); @@ -143,9 +139,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'); @@ -185,9 +179,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'); } @@ -225,14 +217,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'); @@ -271,8 +259,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'); } @@ -310,9 +297,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'); @@ -353,7 +338,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); @@ -403,10 +387,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'); } } @@ -480,7 +463,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'); @@ -548,7 +531,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); @@ -594,7 +577,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)); |