Skip to content

Commit

Permalink
fix(cluster): resolve localhost with digResolver as well
Browse files Browse the repository at this point in the history
Closes #171
  • Loading branch information
mKeRix committed May 26, 2020
1 parent 331ec13 commit 5b076de
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/cluster/resolvers.spec.ts
Expand Up @@ -11,7 +11,7 @@ jest.mock('util', () => ({

describe('resolvers', () => {
beforeEach(async () => {
jest.clearAllMocks();
jest.resetAllMocks();
});

it('should return a single address correctly', (done) => {
Expand Down Expand Up @@ -65,6 +65,29 @@ describe('resolvers', () => {
});
});

it('should return localhost correctly', (done) => {
const service: Service = {
addresses: undefined,
flags: undefined,
fullname: undefined,
host: 'localhost.',
interfaceIndex: undefined,
networkInterface: undefined,
port: undefined,
replyDomain: undefined,
type: undefined,
};

getAddrInfoDig(service, () => {
try {
expect(service.addresses).toStrictEqual(['127.0.0.1']);
done();
} catch (e) {
done(e);
}
});
});

it('should pass errors to the callback', (done) => {
const service: Service = {
addresses: undefined,
Expand Down
5 changes: 5 additions & 0 deletions src/cluster/resolvers.ts
Expand Up @@ -15,6 +15,11 @@ export async function getAddrInfoDig(
service: Service,
next: (e?: Error) => void
): Promise<void> {
if (service.host === 'localhost' || service.host === 'localhost.') {
service.addresses = (service.addresses || []).concat(['127.0.0.1']);
next();
}

try {
const digOutput = await execPromise(
`dig +short @224.0.0.251 -p 5353 -4 ${service.host}`
Expand Down

0 comments on commit 5b076de

Please sign in to comment.