summaryrefslogtreecommitdiff
path: root/test/internet/test-dns-ipv6.js
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2018-06-11 14:56:33 -0400
committercjihrig <cjihrig@gmail.com>2018-06-20 13:35:27 -0400
commit7486c4d71060e2ae3e754cf01e8fb02696eacd13 (patch)
tree8b48c47271d474800f1222f729e93f477f3fd395 /test/internet/test-dns-ipv6.js
parentfea3595c2f92beb0d31feb93da1c972cc30e6fec (diff)
downloadnode-new-7486c4d71060e2ae3e754cf01e8fb02696eacd13.tar.gz
dns: add promisified dns module
PR-URL: https://github.com/nodejs/node/pull/21264 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test/internet/test-dns-ipv6.js')
-rw-r--r--test/internet/test-dns-ipv6.js108
1 files changed, 72 insertions, 36 deletions
diff --git a/test/internet/test-dns-ipv6.js b/test/internet/test-dns-ipv6.js
index 8b1a893680..283b182390 100644
--- a/test/internet/test-dns-ipv6.js
+++ b/test/internet/test-dns-ipv6.js
@@ -4,9 +4,12 @@ const { addresses } = require('../common/internet');
if (!common.hasIPv6)
common.skip('this test, no IPv6 support');
+common.crashOnUnhandledRejection();
+
const assert = require('assert');
const dns = require('dns');
const net = require('net');
+const dnsPromises = dns.promises;
const isIPv6 = net.isIPv6;
let running = false;
@@ -38,49 +41,64 @@ function checkWrap(req) {
assert.ok(typeof req === 'object');
}
-TEST(function test_resolve6(done) {
+TEST(async function test_resolve6(done) {
+ function validateResult(res) {
+ assert.ok(res.length > 0);
+
+ for (let i = 0; i < res.length; i++) {
+ assert.ok(isIPv6(res[i]));
+ }
+ }
+
+ validateResult(await dnsPromises.resolve6(addresses.INET6_HOST));
+
const req = dns.resolve6(
addresses.INET6_HOST,
common.mustCall((err, ips) => {
assert.ifError(err);
-
- assert.ok(ips.length > 0);
-
- for (let i = 0; i < ips.length; i++)
- assert.ok(isIPv6(ips[i]));
-
+ validateResult(ips);
done();
}));
checkWrap(req);
});
-TEST(function test_reverse_ipv6(done) {
+TEST(async function test_reverse_ipv6(done) {
+ function validateResult(res) {
+ assert.ok(res.length > 0);
+
+ for (let i = 0; i < res.length; i++) {
+ assert.ok(typeof res[i] === 'string');
+ }
+ }
+
+ validateResult(await dnsPromises.reverse(addresses.INET6_IP));
+
const req = dns.reverse(
addresses.INET6_IP,
common.mustCall((err, domains) => {
assert.ifError(err);
-
- assert.ok(domains.length > 0);
-
- for (let i = 0; i < domains.length; i++)
- assert.ok(typeof domains[i] === 'string');
-
+ validateResult(domains);
done();
}));
checkWrap(req);
});
-TEST(function test_lookup_ipv6_explicit(done) {
+TEST(async function test_lookup_ipv6_explicit(done) {
+ function validateResult(res) {
+ assert.ok(isIPv6(res.address));
+ assert.strictEqual(res.family, 6);
+ }
+
+ validateResult(await dnsPromises.lookup(addresses.INET6_HOST, 6));
+
const req = dns.lookup(
addresses.INET6_HOST,
6,
common.mustCall((err, ip, family) => {
assert.ifError(err);
- assert.ok(isIPv6(ip));
- assert.strictEqual(family, 6);
-
+ validateResult({ address: ip, family });
done();
}));
@@ -101,14 +119,19 @@ TEST(function test_lookup_ipv6_implicit(done) {
});
*/
-TEST(function test_lookup_ipv6_explicit_object(done) {
+TEST(async function test_lookup_ipv6_explicit_object(done) {
+ function validateResult(res) {
+ assert.ok(isIPv6(res.address));
+ assert.strictEqual(res.family, 6);
+ }
+
+ validateResult(await dnsPromises.lookup(addresses.INET6_HOST, { family: 6 }));
+
const req = dns.lookup(addresses.INET6_HOST, {
family: 6
}, common.mustCall((err, ip, family) => {
assert.ifError(err);
- assert.ok(isIPv6(ip));
- assert.strictEqual(family, 6);
-
+ validateResult({ address: ip, family });
done();
}));
@@ -143,35 +166,48 @@ TEST(function test_lookup_ipv6_hint(done) {
checkWrap(req);
});
-TEST(function test_lookup_ip_ipv6(done) {
+TEST(async function test_lookup_ip_ipv6(done) {
+ function validateResult(res) {
+ assert.ok(isIPv6(res.address));
+ assert.strictEqual(res.family, 6);
+ }
+
+ validateResult(await dnsPromises.lookup('::1'));
+
const req = dns.lookup(
'::1',
common.mustCall((err, ip, family) => {
assert.ifError(err);
- assert.ok(isIPv6(ip));
- assert.strictEqual(family, 6);
-
+ validateResult({ address: ip, family });
done();
}));
checkWrap(req);
});
-TEST(function test_lookup_all_ipv6(done) {
+TEST(async function test_lookup_all_ipv6(done) {
+ function validateResult(res) {
+ assert.ok(Array.isArray(res));
+ assert.ok(res.length > 0);
+
+ res.forEach((ip) => {
+ assert.ok(isIPv6(ip.address),
+ `Invalid IPv6: ${ip.address.toString()}`);
+ assert.strictEqual(ip.family, 6);
+ });
+ }
+
+ validateResult(await dnsPromises.lookup(addresses.INET6_HOST, {
+ all: true,
+ family: 6
+ }));
+
const req = dns.lookup(
addresses.INET6_HOST,
{ all: true, family: 6 },
common.mustCall((err, ips) => {
assert.ifError(err);
- assert.ok(Array.isArray(ips));
- assert.ok(ips.length > 0);
-
- ips.forEach((ip) => {
- assert.ok(isIPv6(ip.address),
- `Invalid IPv6: ${ip.address.toString()}`);
- assert.strictEqual(ip.family, 6);
- });
-
+ validateResult(ips);
done();
})
);