|
1 |
| -import { RFC8252HTTPServer } from './rfc-8252-http-server'; |
| 1 | +import { getAllInterfaces, RFC8252HTTPServer } from './rfc-8252-http-server'; |
2 | 2 | import { expect } from 'chai';
|
3 | 3 | import type { Server as HTTPServer } from 'http';
|
4 | 4 | import { createServer as createHTTPServer } from 'http';
|
@@ -485,4 +485,58 @@ describe('RFC8252HTTPServer', function () {
|
485 | 485 | });
|
486 | 486 | });
|
487 | 487 | });
|
| 488 | + |
| 489 | + context('getAllInterfaces', function () { |
| 490 | + let dnsLookupStub: sinon.SinonStub; |
| 491 | + this.beforeEach(function () { |
| 492 | + dnsLookupStub = sinon.stub(); |
| 493 | + }); |
| 494 | + |
| 495 | + it('filters out exact duplicates', async function () { |
| 496 | + dnsLookupStub.resolves([ |
| 497 | + { address: '127.0.0.1', family: 4 }, |
| 498 | + { address: '127.0.0.1', family: 4 }, |
| 499 | + { address: '[::1]', family: 6 }, |
| 500 | + { address: '[::1]', family: 6 }, |
| 501 | + ]); |
| 502 | + |
| 503 | + const interfaces = await getAllInterfaces('localhost', dnsLookupStub); |
| 504 | + |
| 505 | + expect(interfaces).to.have.lengthOf(2); |
| 506 | + expect(interfaces[0].address).to.equal('127.0.0.1'); |
| 507 | + expect(interfaces[1].address).to.equal('[::1]'); |
| 508 | + expect(interfaces[0].family).to.equal(4); |
| 509 | + expect(interfaces[1].family).to.equal(6); |
| 510 | + }); |
| 511 | + |
| 512 | + it('keeps same addresses, different family', async function () { |
| 513 | + dnsLookupStub.resolves([ |
| 514 | + { address: '127.0.0.1', family: 4 }, |
| 515 | + { address: '127.0.0.1', family: 6 }, |
| 516 | + ]); |
| 517 | + |
| 518 | + const interfaces = await getAllInterfaces('localhost', dnsLookupStub); |
| 519 | + |
| 520 | + expect(interfaces).to.have.lengthOf(2); |
| 521 | + expect(interfaces[0].address).to.equal('127.0.0.1'); |
| 522 | + expect(interfaces[1].address).to.equal('127.0.0.1'); |
| 523 | + expect(interfaces[0].family).to.equal(4); |
| 524 | + expect(interfaces[1].family).to.equal(6); |
| 525 | + }); |
| 526 | + |
| 527 | + it('keeps same familes, different address', async function () { |
| 528 | + dnsLookupStub.resolves([ |
| 529 | + { address: '127.0.0.1', family: 4 }, |
| 530 | + { address: '192.168.1.15', family: 4 }, |
| 531 | + ]); |
| 532 | + |
| 533 | + const interfaces = await getAllInterfaces('localhost', dnsLookupStub); |
| 534 | + |
| 535 | + expect(interfaces).to.have.lengthOf(2); |
| 536 | + expect(interfaces[0].address).to.equal('127.0.0.1'); |
| 537 | + expect(interfaces[1].address).to.equal('192.168.1.15'); |
| 538 | + expect(interfaces[0].family).to.equal(4); |
| 539 | + expect(interfaces[1].family).to.equal(4); |
| 540 | + }); |
| 541 | + }); |
488 | 542 | });
|
0 commit comments