Skip to content

Commit

Permalink
tests: fixed up tests for public travis
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Clement committed Nov 29, 2016
1 parent 9d90e16 commit 870d26a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
63 changes: 28 additions & 35 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,23 @@ Config.prototype.clearHostnameCache = function clearHostnameCache() {
this.getHostnameSafe = getHostnameSafe
}

Config.prototype.getIPAddresses = function getIPAddresses() {
var addresses = {}
var interfaces = os.networkInterfaces()

for (var interfaceKey in interfaces) {
if (interfaceKey.match(/^lo/)) continue

var interfaceDescriptions = interfaces[interfaceKey]
for (var i = 0; i < interfaceDescriptions.length; i++) {
var description = interfaceDescriptions[i]
var family = description.family.toLowerCase()
addresses[family] = description.address
}
}
return addresses
}

function getHostnameSafe() {
var _hostname
this.getHostnameSafe = function getCachedHostname() {
Expand All @@ -787,45 +804,21 @@ function getHostnameSafe() {
_hostname = os.hostname()
return _hostname
} catch (e) {
var interfaces = os.networkInterfaces()
var ipv4Address
var ipv6Address

for (var interfaceKey in interfaces) {
if (interfaceKey.match(/^lo/)) continue

var interfaceDescriptions = interfaces[interfaceKey]
for (var i = 0; i < interfaceDescriptions.length; i++) {
var description = interfaceDescriptions[i]
var family = description.family.toLowerCase()

if (family === 'ipv6') {
ipv6Address = description.address
if (this.process_host.ipv_preference === '6') {
_hostname = ipv6Address
return _hostname
}
} else if (family === 'ipv4') {
ipv4Address = description.address
if (this.process_host.ipv_preference !== '6') {
_hostname = ipv4Address
return _hostname
}
}
}
}
if (ipv4Address) {
var addresses = this.getIPAddresses()

if (this.process_host.ipv_preference === '6' && addresses.ipv6) {
_hostname = addresses.ipv6
} else if (addresses.ipv4) {
logger.info('Defaulting to ipv4 address for host name')
_hostname = ipv4Address
return _hostname
} else if (ipv6Address) {
_hostname = addresses.ipv4
} else if (addresses.ipv6) {
logger.info('Defaulting to ipv6 address for host name')
_hostname = ipv6Address
return _hostname
_hostname = addresses.ipv6
} else {
logger.info('No hostname, ipv4, or ipv6 address found for machine')
_hostname = 'UNKNOWN_BOX'
}

logger.info('No hostname, ipv4, or ipv6 address found for machine')
_hostname = 'UNKNOWN_BOX'
return _hostname
}
}
Expand Down
10 changes: 9 additions & 1 deletion test/integration/core/dns.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ test('reverse', function(t) {
helper.runInTransaction(agent, function() {
dns.reverse('127.0.0.1', function(err, names) {
t.notOk(err, 'should not error')
t.deepEqual(names, [])
if (process.env.TRAVIS && names.length > 0) {
t.deepEqual(names, [
"nettuno",
"travis",
"vagrant"
])
} else {
t.deepEqual(names, [])
}
verifySegments(t, agent, 'dns.reverse')
})
})
Expand Down
4 changes: 4 additions & 0 deletions test/unit/facts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ describe('display_host', function () {
})
it("should be ipv6 when ipv_preference === '6' and os.hostname() not available",
function(done) {
if (!agent.config.getIPAddresses()['ipv6']) {
console.log('this machine does not have an ipv6 address, skipping')
done()
}
agent.config.process_host.ipv_preference = '6'
var ipv6Pattern = /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/

Expand Down

0 comments on commit 870d26a

Please sign in to comment.