Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: migrate tests to use node:test module for better test structure for C Ares #56033

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 52 additions & 46 deletions test/parallel/test-c-ares.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
const common = require('../common');
const assert = require('assert');

const dns = require('dns');
require('../common');

const { test } = require('node:test');
const assert = require('node:assert');
const dns = require('node:dns');
const dnsPromises = dns.promises;

(async function() {
test('dns promises lookup', async (t) => {
let res;

res = await dnsPromises.lookup(null);
Expand All @@ -40,54 +42,58 @@ const dnsPromises = dns.promises;
res = await dnsPromises.lookup('::1');
assert.strictEqual(res.address, '::1');
assert.strictEqual(res.family, 6);
})().then(common.mustCall());
});

// Try resolution without hostname.
dns.lookup(null, common.mustSucceed((result, addressType) => {
assert.strictEqual(result, null);
assert.strictEqual(addressType, 4);
}));
test('dns callback lookup', (t) => {
dns.lookup(null, (err, result, addressType) => {
assert.strictEqual(err, null);
assert.strictEqual(result, null);
assert.strictEqual(addressType, 4);
});

dns.lookup('127.0.0.1', common.mustSucceed((result, addressType) => {
assert.strictEqual(result, '127.0.0.1');
assert.strictEqual(addressType, 4);
}));
dns.lookup('127.0.0.1', (err, result, addressType) => {
assert.strictEqual(err, null);
assert.strictEqual(result, '127.0.0.1');
assert.strictEqual(addressType, 4);
});

dns.lookup('::1', common.mustSucceed((result, addressType) => {
assert.strictEqual(result, '::1');
assert.strictEqual(addressType, 6);
}));
dns.lookup('::1', (err, result, addressType) => {
assert.strictEqual(err, null);
assert.strictEqual(result, '::1');
assert.strictEqual(addressType, 6);
});
});

[
// Try calling resolve with an unsupported type.
'HI',
// Try calling resolve with an unsupported type that's an object key
'toString',
].forEach((val) => {
const err = {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
message: `The argument 'rrtype' is invalid. Received '${val}'`,
};
test('unsupported rrtype resolves', (t) => {
[
// Try calling resolve with an unsupported type.
'HI',
// Try calling resolve with an unsupported type that's an object key
'toString',
].forEach((val) => {
const err = {
code: 'ERR_INVALID_ARG_VALUE',
name: 'TypeError',
message: `The argument 'rrtype' is invalid. Received '${val}'`,
};

assert.throws(
() => dns.resolve('www.google.com', val),
err
);
assert.throws(
() => dns.resolve('www.google.com', val),
err
);

assert.throws(() => dnsPromises.resolve('www.google.com', val), err);
assert.throws(() => dnsPromises.resolve('www.google.com', val), err);
});
});

// Windows doesn't usually have an entry for localhost 127.0.0.1 in
// C:\Windows\System32\drivers\etc\hosts
// so we disable this test on Windows.
// IBMi reports `ENOTFOUND` when get hostname by address 127.0.0.1
if (!common.isWindows && !common.isIBMi) {
dns.reverse('127.0.0.1', common.mustSucceed((domains) => {
assert.ok(Array.isArray(domains));
}));
test('reverse DNS lookup (non-Windows, non-IBMi)', async (t) => {
if (!process.platform.startsWith('win') && process.platform !== 'aix') {
dns.reverse('127.0.0.1', (err, domains) => {
assert.strictEqual(err, null);
assert.ok(Array.isArray(domains));
});

(async function() {
assert.ok(Array.isArray(await dnsPromises.reverse('127.0.0.1')));
})().then(common.mustCall());
}
const domains = await dnsPromises.reverse('127.0.0.1');
assert.ok(Array.isArray(domains));
}
});
Loading