-
Notifications
You must be signed in to change notification settings - Fork 384
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: Fix DNS lookup in remote-method test #1937
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
'use strict' | ||
|
||
const tap = require('tap') | ||
const dns = require('dns') | ||
|
||
const url = require('url') | ||
const Config = require('../../../lib/config') | ||
|
@@ -261,6 +262,16 @@ tap.test('when the connection fails', (t) => { | |
}) | ||
|
||
t.test('should correctly handle a DNS lookup failure', (t) => { | ||
const lookup = dns.lookup | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is fine but could just use sinon too const err = Error('no dns')
err.code = dns.NOTFOUND
sinon.stub(dns, 'lookup').yields(err)
t.teardown(() => {
dns.lookup.restore()
}) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that provide anything we need here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not really. we typically use sinon for mocking but older tests will still have patching style like this. I just wanted to call it out, feel free to merge There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not at all familiar with the sinon API. I like the least amount of mystery in tests as possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's fair. I suggest you familiarize yourself as this repo does use it heavily. but again not a big deal here |
||
dns.lookup = (a, b, cb) => { | ||
const error = Error('no dns') | ||
error.code = dns.NOTFOUND | ||
return cb(error) | ||
} | ||
t.teardown(() => { | ||
dns.lookup = lookup | ||
}) | ||
|
||
const config = { | ||
max_payload_size_in_bytes: 100000 | ||
} | ||
|
@@ -271,13 +282,7 @@ tap.test('when the connection fails', (t) => { | |
const method = new RemoteMethod('TEST', { ...BARE_AGENT, config }, endpoint) | ||
method.invoke([], {}, (error) => { | ||
t.ok(error) | ||
|
||
// https://github.com/joyent/node/commit/7295bb9435c | ||
t.match( | ||
error.message, | ||
/^getaddrinfo E(NOENT|NOTFOUND)( failed.domain.cxlrg)?( failed.domain.cxlrg:80)?$/ // eslint-disable-line max-len | ||
) | ||
|
||
t.equal(error.message, 'no dns') | ||
t.end() | ||
}) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you also want to mock the test above too?