| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5c835c5 commit e794c0c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,18 +1,16 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const dns = require('dns'); | |
| 5 | 5 | const net = require('net'); | |
| 6 | 6 | const isIPv4 = net.isIPv4; | |
| 7 | 7 | ||
| 8 | - let expected = 0; | ||
| 9 | - let completed = 0; | ||
| 10 | 8 | let running = false; | |
| 11 | 9 | const queue = []; | |
| 12 | 10 | ||
| 13 | 11 | function TEST(f) { | |
| 14 | 12 | function next() { | |
| 15 | - var f = queue.shift(); | ||
| 13 | + const f = queue.shift(); | ||
| 16 | 14 | if (f) { | |
| 17 | 15 | running = true; | |
| 18 | 16 | console.log(f.name); | |
@@ -22,11 +20,9 @@ function TEST(f) { | |||
| 22 | 20 | ||
| 23 | 21 | function done() { | |
| 24 | 22 | running = false; | |
| 25 | - completed++; | ||
| 26 | 23 | process.nextTick(next); | |
| 27 | 24 | } | |
| 28 | 25 | ||
| 29 | - expected++; | ||
| 30 | 26 | queue.push(f); | |
| 31 | 27 | ||
| 32 | 28 | if (!running) { | |
@@ -39,149 +35,150 @@ function checkWrap(req) { | |||
| 39 | 35 | } | |
| 40 | 36 | ||
| 41 | 37 | TEST(function test_resolve4(done) { | |
| 42 | - var req = dns.resolve4('www.google.com', function(err, ips) { | ||
| 43 | - if (err) throw err; | ||
| 38 | + const req = dns.resolve4('www.google.com', | ||
| 39 | + common.mustCall((err, ips) => { | ||
| 40 | + assert.ifError(err); | ||
| 44 | 41 | ||
| 45 | - assert.ok(ips.length > 0); | ||
| 42 | + assert.ok(ips.length > 0); | ||
| 46 | 43 | ||
| 47 | - for (var i = 0; i < ips.length; i++) { | ||
| 48 | - assert.ok(isIPv4(ips[i])); | ||
| 49 | - } | ||
| 44 | + for (let i = 0; i < ips.length; i++) { | ||
| 45 | + assert.ok(isIPv4(ips[i])); | ||
| 46 | + } | ||
| 50 | 47 | ||
| 51 | - done(); | ||
| 52 | - }); | ||
| 48 | + done(); | ||
| 49 | + })); | ||
| 53 | 50 | ||
| 54 | 51 | checkWrap(req); | |
| 55 | 52 | }); | |
| 56 | 53 | ||
| 57 | 54 | TEST(function test_reverse_ipv4(done) { | |
| 58 | - var req = dns.reverse('8.8.8.8', function(err, domains) { | ||
| 59 | - if (err) throw err; | ||
| 55 | + const req = dns.reverse('8.8.8.8', | ||
| 56 | + common.mustCall((err, domains) => { | ||
| 57 | + assert.ifError(err); | ||
| 60 | 58 | ||
| 61 | - assert.ok(domains.length > 0); | ||
| 59 | + assert.ok(domains.length > 0); | ||
| 62 | 60 | ||
| 63 | - for (var i = 0; i < domains.length; i++) { | ||
| 64 | - assert.ok(domains[i]); | ||
| 65 | - assert.ok(typeof domains[i] === 'string'); | ||
| 66 | - } | ||
| 61 | + for (let i = 0; i < domains.length; i++) { | ||
| 62 | + assert.ok(domains[i]); | ||
| 63 | + assert.ok(typeof domains[i] === 'string'); | ||
| 64 | + } | ||
| 67 | 65 | ||
| 68 | - done(); | ||
| 69 | - }); | ||
| 66 | + done(); | ||
| 67 | + })); | ||
| 70 | 68 | ||
| 71 | 69 | checkWrap(req); | |
| 72 | 70 | }); | |
| 73 | 71 | ||
| 74 | 72 | TEST(function test_lookup_ipv4_explicit(done) { | |
| 75 | - var req = dns.lookup('www.google.com', 4, function(err, ip, family) { | ||
| 76 | - if (err) throw err; | ||
| 77 | - assert.ok(net.isIPv4(ip)); | ||
| 78 | - assert.strictEqual(family, 4); | ||
| 73 | + const req = dns.lookup('www.google.com', 4, | ||
| 74 | + common.mustCall((err, ip, family) => { | ||
| 75 | + assert.ifError(err); | ||
| 76 | + assert.ok(net.isIPv4(ip)); | ||
| 77 | + assert.strictEqual(family, 4); | ||
| 79 | 78 | ||
| 80 | - done(); | ||
| 81 | - }); | ||
| 79 | + done(); | ||
| 80 | + })); | ||
| 82 | 81 | ||
| 83 | 82 | checkWrap(req); | |
| 84 | 83 | }); | |
| 85 | 84 | ||
| 86 | 85 | TEST(function test_lookup_ipv4_implicit(done) { | |
| 87 | - var req = dns.lookup('www.google.com', function(err, ip, family) { | ||
| 88 | - if (err) throw err; | ||
| 89 | - assert.ok(net.isIPv4(ip)); | ||
| 90 | - assert.strictEqual(family, 4); | ||
| 86 | + const req = dns.lookup('www.google.com', | ||
| 87 | + common.mustCall((err, ip, family) => { | ||
| 88 | + assert.ifError(err); | ||
| 89 | + assert.ok(net.isIPv4(ip)); | ||
| 90 | + assert.strictEqual(family, 4); | ||
| 91 | 91 | ||
| 92 | - done(); | ||
| 93 | - }); | ||
| 92 | + done(); | ||
| 93 | + })); | ||
| 94 | 94 | ||
| 95 | 95 | checkWrap(req); | |
| 96 | 96 | }); | |
| 97 | 97 | ||
| 98 | 98 | TEST(function test_lookup_ipv4_explicit_object(done) { | |
| 99 | - var req = dns.lookup('www.google.com', { | ||
| 99 | + const req = dns.lookup('www.google.com', { | ||
| 100 | 100 | family: 4 | |
| 101 | - }, function(err, ip, family) { | ||
| 102 | - if (err) throw err; | ||
| 101 | + }, common.mustCall((err, ip, family) => { | ||
| 102 | + assert.ifError(err); | ||
| 103 | 103 | assert.ok(net.isIPv4(ip)); | |
| 104 | 104 | assert.strictEqual(family, 4); | |
| 105 | 105 | ||
| 106 | 106 | done(); | |
| 107 | - }); | ||
| 107 | + })); | ||
| 108 | 108 | ||
| 109 | 109 | checkWrap(req); | |
| 110 | 110 | }); | |
| 111 | 111 | ||
| 112 | 112 | TEST(function test_lookup_ipv4_hint_addrconfig(done) { | |
| 113 | - var req = dns.lookup('www.google.com', { | ||
| 113 | + const req = dns.lookup('www.google.com', { | ||
| 114 | 114 | hints: dns.ADDRCONFIG | |
| 115 | - }, function(err, ip, family) { | ||
| 116 | - if (err) throw err; | ||
| 115 | + }, common.mustCall((err, ip, family) => { | ||
| 116 | + assert.ifError(err); | ||
| 117 | 117 | assert.ok(net.isIPv4(ip)); | |
| 118 | 118 | assert.strictEqual(family, 4); | |
| 119 | 119 | ||
| 120 | 120 | done(); | |
| 121 | - }); | ||
| 121 | + })); | ||
| 122 | 122 | ||
| 123 | 123 | checkWrap(req); | |
| 124 | 124 | }); | |
| 125 | 125 | ||
| 126 | 126 | TEST(function test_lookup_ip_ipv4(done) { | |
| 127 | - var req = dns.lookup('127.0.0.1', function(err, ip, family) { | ||
| 128 | - if (err) throw err; | ||
| 129 | - assert.strictEqual(ip, '127.0.0.1'); | ||
| 130 | - assert.strictEqual(family, 4); | ||
| 127 | + const req = dns.lookup('127.0.0.1', | ||
| 128 | + common.mustCall((err, ip, family) => { | ||
| 129 | + assert.ifError(err); | ||
| 130 | + assert.strictEqual(ip, '127.0.0.1'); | ||
| 131 | + assert.strictEqual(family, 4); | ||
| 131 | 132 | ||
| 132 | - done(); | ||
| 133 | - }); | ||
| 133 | + done(); | ||
| 134 | + })); | ||
| 134 | 135 | ||
| 135 | 136 | checkWrap(req); | |
| 136 | 137 | }); | |
| 137 | 138 | ||
| 138 | 139 | TEST(function test_lookup_localhost_ipv4(done) { | |
| 139 | - var req = dns.lookup('localhost', 4, function(err, ip, family) { | ||
| 140 | - if (err) throw err; | ||
| 141 | - assert.strictEqual(ip, '127.0.0.1'); | ||
| 142 | - assert.strictEqual(family, 4); | ||
| 140 | + const req = dns.lookup('localhost', 4, | ||
| 141 | + common.mustCall((err, ip, family) => { | ||
| 142 | + assert.ifError(err); | ||
| 143 | + assert.strictEqual(ip, '127.0.0.1'); | ||
| 144 | + assert.strictEqual(family, 4); | ||
| 143 | 145 | ||
| 144 | - done(); | ||
| 145 | - }); | ||
| 146 | + done(); | ||
| 147 | + })); | ||
| 146 | 148 | ||
| 147 | 149 | checkWrap(req); | |
| 148 | 150 | }); | |
| 149 | 151 | ||
| 150 | 152 | TEST(function test_lookup_all_ipv4(done) { | |
| 151 | - var req = dns.lookup( | ||
| 153 | + const req = dns.lookup( | ||
| 152 | 154 | 'www.google.com', | |
| 153 | 155 | {all: true, family: 4}, | |
| 154 | - function(err, ips) { | ||
| 155 | - if (err) throw err; | ||
| 156 | + common.mustCall((err, ips) => { | ||
| 157 | + assert.ifError(err); | ||
| 156 | 158 | assert.ok(Array.isArray(ips)); | |
| 157 | 159 | assert.ok(ips.length > 0); | |
| 158 | 160 | ||
| 159 | - ips.forEach(function(ip) { | ||
| 161 | + ips.forEach((ip) => { | ||
| 160 | 162 | assert.ok(isIPv4(ip.address)); | |
| 161 | 163 | assert.strictEqual(ip.family, 4); | |
| 162 | 164 | }); | |
| 163 | 165 | ||
| 164 | 166 | done(); | |
| 165 | 167 | } | |
| 166 | - ); | ||
| 168 | + )); | ||
| 167 | 169 | ||
| 168 | 170 | checkWrap(req); | |
| 169 | 171 | }); | |
| 170 | 172 | ||
| 171 | 173 | TEST(function test_lookupservice_ip_ipv4(done) { | |
| 172 | - var req = dns.lookupService('127.0.0.1', 80, function(err, host, service) { | ||
| 173 | - if (err) throw err; | ||
| 174 | - assert.equal(typeof host, 'string'); | ||
| 175 | - assert(host); | ||
| 176 | - assert(['http', 'www', '80'].includes(service)); | ||
| 177 | - done(); | ||
| 178 | - }); | ||
| 174 | + const req = dns.lookupService('127.0.0.1', 80, | ||
| 175 | + common.mustCall((err, host, service) => { | ||
| 176 | + assert.ifError(err); | ||
| 177 | + assert.strictEqual(typeof host, 'string'); | ||
| 178 | + assert(host); | ||
| 179 | + assert(['http', 'www', '80'].includes(service)); | ||
| 180 | + done(); | ||
| 181 | + })); | ||
| 179 | 182 | ||
| 180 | 183 | checkWrap(req); | |
| 181 | 184 | }); | |
| 182 | - | ||
| 183 | - process.on('exit', function() { | ||
| 184 | - console.log(completed + ' tests completed'); | ||
| 185 | - assert.equal(running, false); | ||
| 186 | - assert.strictEqual(expected, completed); | ||
| 187 | - }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments