Skip to content

Commit

Permalink
chore: add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSun90 committed Aug 7, 2024
1 parent 03e08dc commit 0c4be16
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions test/unit/connector-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Mitm = require('mitm');
const sinon = require('sinon');
const url = require('node:url');
const dns = require('dns');
const assert = require('chai').assert;

const {
Expand All @@ -25,7 +25,7 @@ describe('lookupAllAddresses', function() {
}

assert.isOk(lookup.called, 'Failed to call `lookup` function for hostname');
assert.isOk(lookup.calledWithMatch(url.domainToASCII(server)), 'Unexpected hostname passed to `lookup`');
assert.isOk(lookup.calledWithMatch('xn--tiq21tzznxb.ad'), 'Unexpected hostname passed to `lookup`');
});

it('test ASCII Server name', async function() {
Expand All @@ -45,6 +45,21 @@ describe('lookupAllAddresses', function() {
assert.isOk(lookup.called, 'Failed to call `lookup` function for hostname');
assert.isOk(lookup.calledWithMatch(server), 'Unexpected hostname passed to `lookup`');
});

it('test invalid ASCII Server name', async function() {
const server = 'http:wrong';
const controller = new AbortController();

let actualError;
try {
await lookupAllAddresses(server, dns.lookup, controller.signal);
} catch (err) {
actualError = err;
}

assert.instanceOf(actualError, Error);
assert.strictEqual(actualError.message, 'getaddrinfo ENOTFOUND http:wrong');
});
});

describe('connectInSequence', function() {
Expand Down

0 comments on commit 0c4be16

Please sign in to comment.