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

1 file changed

Lines changed: 13 additions & 30 deletions

File tree

‎test/internet/test-dns.js‎

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

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

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

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

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

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

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

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

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

404-
for(leti=0;i<result.length;i++){
405-
constname=result[i];
406-
assert.ok(name);
407-
assert.strictEqual(typeofname,'string');
388+
for(constitemofresult){
389+
assert.ok(item);
390+
assert.strictEqual(typeofitem,'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-
constreq=dns.lookup(addresses.INVALID_HOST,4,(err,ip,family)=>{
464+
constreq=dns.lookup(addresses.INVALID_HOST,4,(err)=>{
482465
assert.ok(errinstanceofError);
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(asyncfunctiontest_lookup_null_all(done){
547530
assert.deepStrictEqual(awaitdnsPromises.lookup(null,{all: true}),[]);
548531

549-
constreq=dns.lookup(null,{all: true},function(err,ips,family){
532+
constreq=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-
constreq=dns.lookupService('1.2.3.4',80,function(err,host,service){
578+
constreq=dns.lookupService('1.2.3.4',80,(err)=>{
596579
assert(errinstanceofError);
597580
assert.strictEqual(err.code,'ENOTFOUND');
598581
assert.ok(/1\.2\.3\.4/.test(err.message));

0 commit comments

Comments
 (0)