Skip to content

Commit e61bbda

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 <daniel.bevenius@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 117e991 commit e61bbda

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
@@ -83,9 +83,7 @@ TEST(async function test_resolve4_ttl(done) {
8383
function validateResult(result) {
8484
assert.ok(result.length > 0);
8585

86-
for (let i = 0; i < result.length; i++) {
87-
const item = result[i];
88-
assert.ok(item);
86+
for (const item of result) {
8987
assert.strictEqual(typeof item, 'object');
9088
assert.strictEqual(typeof item.ttl, 'number');
9189
assert.strictEqual(typeof item.address, 'string');
@@ -113,9 +111,7 @@ TEST(async function test_resolve6_ttl(done) {
113111
function validateResult(result) {
114112
assert.ok(result.length > 0);
115113

116-
for (let i = 0; i < result.length; i++) {
117-
const item = result[i];
118-
assert.ok(item);
114+
for (const item of result) {
119115
assert.strictEqual(typeof item, 'object');
120116
assert.strictEqual(typeof item.ttl, 'number');
121117
assert.strictEqual(typeof item.address, 'string');
@@ -143,9 +139,7 @@ TEST(async function test_resolveMx(done) {
143139
function validateResult(result) {
144140
assert.ok(result.length > 0);
145141

146-
for (let i = 0; i < result.length; i++) {
147-
const item = result[i];
148-
assert.ok(item);
142+
for (const item of result) {
149143
assert.strictEqual(typeof item, 'object');
150144
assert.ok(item.exchange);
151145
assert.strictEqual(typeof item.exchange, 'string');
@@ -185,9 +179,7 @@ TEST(async function test_resolveNs(done) {
185179
function validateResult(result) {
186180
assert.ok(result.length > 0);
187181

188-
for (let i = 0; i < result.length; i++) {
189-
const item = result[i];
190-
182+
for (const item of result) {
191183
assert.ok(item);
192184
assert.strictEqual(typeof item, 'string');
193185
}
@@ -225,14 +217,10 @@ TEST(async function test_resolveSrv(done) {
225217
function validateResult(result) {
226218
assert.ok(result.length > 0);
227219

228-
for (let i = 0; i < result.length; i++) {
229-
const item = result[i];
230-
assert.ok(item);
220+
for (const item of result) {
231221
assert.strictEqual(typeof item, 'object');
232-
233222
assert.ok(item.name);
234223
assert.strictEqual(typeof item.name, 'string');
235-
236224
assert.strictEqual(typeof item.port, 'number');
237225
assert.strictEqual(typeof item.priority, 'number');
238226
assert.strictEqual(typeof item.weight, 'number');
@@ -271,8 +259,7 @@ TEST(async function test_resolvePtr(done) {
271259
function validateResult(result) {
272260
assert.ok(result.length > 0);
273261

274-
for (let i = 0; i < result.length; i++) {
275-
const item = result[i];
262+
for (const item of result) {
276263
assert.ok(item);
277264
assert.strictEqual(typeof item, 'string');
278265
}
@@ -310,9 +297,7 @@ TEST(async function test_resolveNaptr(done) {
310297
function validateResult(result) {
311298
assert.ok(result.length > 0);
312299

313-
for (let i = 0; i < result.length; i++) {
314-
const item = result[i];
315-
assert.ok(item);
300+
for (const item of result) {
316301
assert.strictEqual(typeof item, 'object');
317302
assert.strictEqual(typeof item.flags, 'string');
318303
assert.strictEqual(typeof item.service, 'string');
@@ -353,7 +338,6 @@ TEST(function test_resolveNaptr_failure(done) {
353338

354339
TEST(async function test_resolveSoa(done) {
355340
function validateResult(result) {
356-
assert.ok(result);
357341
assert.strictEqual(typeof result, 'object');
358342
assert.strictEqual(typeof result.nsname, 'string');
359343
assert.ok(result.nsname.length > 0);
@@ -403,10 +387,9 @@ TEST(async function test_resolveCname(done) {
403387
function validateResult(result) {
404388
assert.ok(result.length > 0);
405389

406-
for (let i = 0; i < result.length; i++) {
407-
const name = result[i];
408-
assert.ok(name);
409-
assert.strictEqual(typeof name, 'string');
390+
for (const item of result) {
391+
assert.ok(item);
392+
assert.strictEqual(typeof item, 'string');
410393
}
411394
}
412395

@@ -480,7 +463,7 @@ TEST(function test_lookup_failure(done) {
480463
.then(common.mustNotCall())
481464
.catch(common.expectsError({ errno: dns.NOTFOUND }));
482465

483-
const req = dns.lookup(addresses.INVALID_HOST, 4, (err, ip, family) => {
466+
const req = dns.lookup(addresses.INVALID_HOST, 4, (err) => {
484467
assert.ok(err instanceof Error);
485468
assert.strictEqual(err.errno, dns.NOTFOUND);
486469
assert.strictEqual(err.errno, 'ENOTFOUND');
@@ -548,7 +531,7 @@ TEST(function test_lookup_ip_promise(done) {
548531
TEST(async function test_lookup_null_all(done) {
549532
assert.deepStrictEqual(await dnsPromises.lookup(null, { all: true }), []);
550533

551-
const req = dns.lookup(null, { all: true }, function(err, ips, family) {
534+
const req = dns.lookup(null, { all: true }, (err, ips) => {
552535
assert.ifError(err);
553536
assert.ok(Array.isArray(ips));
554537
assert.strictEqual(ips.length, 0);
@@ -594,7 +577,7 @@ TEST(function test_lookupservice_invalid(done) {
594577
.then(common.mustNotCall())
595578
.catch(common.expectsError({ code: 'ENOTFOUND' }));
596579

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

0 commit comments

Comments
 (0)