Skip to content

Commit 3bdff05

Browse files
IlarionHalushkaBethGriggs
authored andcommitted
test: improve internet/test-dns
* change 'for' loop to 'for of' loop * remove unused parameters passed to functions * remove unnecessary 'assert.ok' PR-URL: #24927 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent bb8a65d commit 3bdff05

File tree

1 file changed

+13
-30
lines changed

1 file changed

+13
-30
lines changed

test/internet/test-dns.js

+13-30
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ TEST(async function test_resolve4_ttl(done) {
8181
function validateResult(result) {
8282
assert.ok(result.length > 0);
8383

84-
for (let i = 0; i < result.length; i++) {
85-
const item = result[i];
86-
assert.ok(item);
84+
for (const item of result) {
8785
assert.strictEqual(typeof item, 'object');
8886
assert.strictEqual(typeof item.ttl, 'number');
8987
assert.strictEqual(typeof item.address, 'string');
@@ -111,9 +109,7 @@ TEST(async function test_resolve6_ttl(done) {
111109
function validateResult(result) {
112110
assert.ok(result.length > 0);
113111

114-
for (let i = 0; i < result.length; i++) {
115-
const item = result[i];
116-
assert.ok(item);
112+
for (const item of result) {
117113
assert.strictEqual(typeof item, 'object');
118114
assert.strictEqual(typeof item.ttl, 'number');
119115
assert.strictEqual(typeof item.address, 'string');
@@ -141,9 +137,7 @@ TEST(async function test_resolveMx(done) {
141137
function validateResult(result) {
142138
assert.ok(result.length > 0);
143139

144-
for (let i = 0; i < result.length; i++) {
145-
const item = result[i];
146-
assert.ok(item);
140+
for (const item of result) {
147141
assert.strictEqual(typeof item, 'object');
148142
assert.ok(item.exchange);
149143
assert.strictEqual(typeof item.exchange, 'string');
@@ -183,9 +177,7 @@ TEST(async function test_resolveNs(done) {
183177
function validateResult(result) {
184178
assert.ok(result.length > 0);
185179

186-
for (let i = 0; i < result.length; i++) {
187-
const item = result[i];
188-
180+
for (const item of result) {
189181
assert.ok(item);
190182
assert.strictEqual(typeof item, 'string');
191183
}
@@ -223,14 +215,10 @@ TEST(async function test_resolveSrv(done) {
223215
function validateResult(result) {
224216
assert.ok(result.length > 0);
225217

226-
for (let i = 0; i < result.length; i++) {
227-
const item = result[i];
228-
assert.ok(item);
218+
for (const item of result) {
229219
assert.strictEqual(typeof item, 'object');
230-
231220
assert.ok(item.name);
232221
assert.strictEqual(typeof item.name, 'string');
233-
234222
assert.strictEqual(typeof item.port, 'number');
235223
assert.strictEqual(typeof item.priority, 'number');
236224
assert.strictEqual(typeof item.weight, 'number');
@@ -269,8 +257,7 @@ TEST(async function test_resolvePtr(done) {
269257
function validateResult(result) {
270258
assert.ok(result.length > 0);
271259

272-
for (let i = 0; i < result.length; i++) {
273-
const item = result[i];
260+
for (const item of result) {
274261
assert.ok(item);
275262
assert.strictEqual(typeof item, 'string');
276263
}
@@ -308,9 +295,7 @@ TEST(async function test_resolveNaptr(done) {
308295
function validateResult(result) {
309296
assert.ok(result.length > 0);
310297

311-
for (let i = 0; i < result.length; i++) {
312-
const item = result[i];
313-
assert.ok(item);
298+
for (const item of result) {
314299
assert.strictEqual(typeof item, 'object');
315300
assert.strictEqual(typeof item.flags, 'string');
316301
assert.strictEqual(typeof item.service, 'string');
@@ -351,7 +336,6 @@ TEST(function test_resolveNaptr_failure(done) {
351336

352337
TEST(async function test_resolveSoa(done) {
353338
function validateResult(result) {
354-
assert.ok(result);
355339
assert.strictEqual(typeof result, 'object');
356340
assert.strictEqual(typeof result.nsname, 'string');
357341
assert.ok(result.nsname.length > 0);
@@ -401,10 +385,9 @@ TEST(async function test_resolveCname(done) {
401385
function validateResult(result) {
402386
assert.ok(result.length > 0);
403387

404-
for (let i = 0; i < result.length; i++) {
405-
const name = result[i];
406-
assert.ok(name);
407-
assert.strictEqual(typeof name, 'string');
388+
for (const item of result) {
389+
assert.ok(item);
390+
assert.strictEqual(typeof item, 'string');
408391
}
409392
}
410393

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

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

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

595-
const req = dns.lookupService('1.2.3.4', 80, function(err, host, service) {
578+
const req = dns.lookupService('1.2.3.4', 80, (err) => {
596579
assert(err instanceof Error);
597580
assert.strictEqual(err.code, 'ENOTFOUND');
598581
assert.ok(/1\.2\.3\.4/.test(err.message));

0 commit comments

Comments
 (0)