Skip to content
Closed
Show file tree
Hide file tree
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
22 changes: 8 additions & 14 deletions test/unit/instance-lookup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,35 +322,29 @@ describe('parseBrowserResponse', function() {
sinon.restore();
});

it('test IDN Server name', (done) => {
it('test IDN Server name', () => {
const options = {
server: '本地主机.ad',
instanceName: 'instance',
timeout: 500,
retries: 1
};

new InstanceLookup().instanceLookup(options, () => {
assert.ok(spy.called, 'Failed to call dns.lookup on hostname');
assert.ok(spy.calledWithMatch(punycode.toASCII(options.server)), 'Unexpected hostname passed to dns.lookup');

done();
});
new InstanceLookup().instanceLookup(options, () => {});
assert.ok(spy.called, 'Failed to call dns.lookup on hostname');
assert.ok(spy.calledWithMatch(punycode.toASCII(options.server)), 'Unexpected hostname passed to dns.lookup');
});

it('test ASCII Server name', (done) => {
it('test ASCII Server name', () => {
const options = {
server: 'localhost',
instanceName: 'instance',
timeout: 500,
retries: 1
};

new InstanceLookup().instanceLookup(options, () => {
assert.ok(spy.called, 'Failed to call dns.lookup on hostname');
assert.ok(spy.calledWithMatch(options.server), 'Unexpected hostname passed to dns.lookup');

done();
});
new InstanceLookup().instanceLookup(options, () => {});
assert.ok(spy.called, 'Failed to call dns.lookup on hostname');
assert.ok(spy.calledWithMatch(options.server), 'Unexpected hostname passed to dns.lookup');
});
});
72 changes: 36 additions & 36 deletions test/unit/sender-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,45 +137,45 @@ describe('Sender send to IP address', function() {
});
});

function sendToHostCommonTestSetup(lookupError) {
// Since we're testing Sender class, we just want to verify that the 'send'/'cancel'
// method(s) on the ParallelSendStrategy class are/is being invoked. So we stub out
// the methods to validate they're invoked correctly.
const testStrategy = new ParallelSendStrategy(
this.addresses,
anyPort,
anyRequest
);
const callback = () => { };
this.strategySendStub = sinon.stub(testStrategy, 'send');
this.strategySendStub.withArgs(callback);
this.strategyCancelStub = sinon.stub(testStrategy, 'cancel');
this.strategyCancelStub.withArgs();

this.sender = new Sender(anyHost, anyPort, anyRequest);

// Stub out the lookupAll method to prevent network activity from doing a DNS
// lookup. Succeeds or fails depending on lookupError.
this.lookupAllStub = sinon.stub(this.sender, 'invokeLookupAll');
this.lookupAllStub.callsArgWithAsync(1, lookupError, this.addresses);

// Stub the create strategy method for the test to return a strategy object created
// exactly like the method would but with a few methods stubbed.
this.createStrategyStub = sinon.stub(
this.sender,
'createParallelSendStrategy'
);
this.createStrategyStub
.withArgs(this.addresses, anyPort, anyRequest)
.returns(testStrategy);

this.sender.execute(callback);
}

describe('Sender send to hostnam', function() {
describe('Sender send to hostname', function() {
describe('Send', function() {
let glob;

function sendToHostCommonTestSetup(lookupError) {
// Since we're testing Sender class, we just want to verify that the 'send'/'cancel'
// method(s) on the ParallelSendStrategy class are/is being invoked. So we stub out
// the methods to validate they're invoked correctly.
const testStrategy = new ParallelSendStrategy(
this.addresses,
anyPort,
anyRequest
);
const callback = () => { };
this.strategySendStub = sinon.stub(testStrategy, 'send');
this.strategySendStub.withArgs(callback);
this.strategyCancelStub = sinon.stub(testStrategy, 'cancel');
this.strategyCancelStub.withArgs();

this.sender = new Sender(anyHost, anyPort, anyRequest);

// Stub out the lookupAll method to prevent network activity from doing a DNS
// lookup. Succeeds or fails depending on lookupError.
this.lookupAllStub = sinon.stub(this.sender, 'invokeLookupAll');
this.lookupAllStub.callsArgWithAsync(1, lookupError, this.addresses);

// Stub the create strategy method for the test to return a strategy object created
// exactly like the method would but with a few methods stubbed.
this.createStrategyStub = sinon.stub(
this.sender,
'createParallelSendStrategy'
);
this.createStrategyStub
.withArgs(this.addresses, anyPort, anyRequest)
.returns(testStrategy);

this.sender.execute(callback);
}

beforeEach(function() {
// Set of IP addresses to be returned by stubbed out lookupAll method.
glob = {
Expand Down