Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners-nr committed Sep 12, 2024
1 parent eb73c9a commit a5b1e78
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 37 deletions.
4 changes: 4 additions & 0 deletions lib/utilization/ecs-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module.exports = function fetchEcsInfo(
if (error) {
return callback(error, null)
}
if (dockerId === null) {
// Some error happened where we could not find the id. Skipping.
return callback(null, null)
}
return callback(null, { ecsDockerId: dockerId })
}
})
Expand Down
67 changes: 30 additions & 37 deletions test/unit/facts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,6 @@ tap.test('utilization', (t) => {
// We don't collect full hostnames
delete expected.full_hostname

// Stub out docker container id query to make this consistent on all OSes.
sysInfo._getDockerContainerId = (_agent, callback) => {
return callback(null)
}

agent = helper.loadMockedAgent(config)
if (mockHostname) {
agent.config.getHostnameSafe = mockHostname
Expand All @@ -470,33 +465,36 @@ tap.test('utilization', (t) => {
function makeMockCommonRequest(t, test, type) {
return (opts, _agent, cb) => {
t.equal(_agent, agent)
setImmediate(
cb,
null,
JSON.stringify(
type === 'aws'
? {
instanceId: test.input_aws_id,
instanceType: test.input_aws_type,
availabilityZone: test.input_aws_zone
}
: type === 'azure'
? {
location: test.input_azure_location,
name: test.input_azure_name,
vmId: test.input_azure_id,
vmSize: test.input_azure_size
}
: type === 'gcp'
? {
id: test.input_gcp_id,
machineType: test.input_gcp_type,
name: test.input_gcp_name,
zone: test.input_gcp_zone
}
: null
)
)
let payload = null
switch (type) {
case 'aws': {
payload = {
instanceId: test.input_aws_id,
instanceType: test.input_aws_type,
availabilityZone: test.input_aws_zone
}
break
}
case 'azure': {
payload = {
location: test.input_azure_location,
name: test.input_azure_name,
vmId: test.input_azure_id,
vmSize: test.input_azure_size
}
break
}
case 'gcp': {
payload = {
id: test.input_gcp_id,
machineType: test.input_gcp_type,
name: test.input_gcp_name,
zone: test.input_gcp_zone
}
break
}
}
setImmediate(cb, null, JSON.stringify(payload))
}
}
})
Expand Down Expand Up @@ -584,11 +582,6 @@ tap.test('boot_id', (t) => {

const expected = test.expected_output_json

// Stub out docker container id query to make this consistent on all OSes.
sysInfo._getDockerContainerId = (_agent, callback) => {
return callback(null)
}

agent = helper.loadMockedAgent(DISABLE_ALL_DETECTIONS)
if (mockHostname) {
agent.config.getHostnameSafe = mockHostname
Expand Down
23 changes: 23 additions & 0 deletions test/unit/utilization/ecs-info.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,29 @@ test('returns null if error encountered', (t, end) => {
}
})

test('returns null if got null', (t, end) => {
const agent = helper.loadMockedAgent({
utilization: {
detect_aws: true
}
})
t.after(() => helper.unloadAgent(agent))

fetchEcsInfo(
agent,
(error, data) => {
assert.equal(error, null)
assert.equal(data, null)
end()
},
{ getEcsContainerId }
)

function getEcsContainerId({ callback }) {
callback(null, null)
}
})

test('returns container id', (t, end) => {
const agent = helper.loadMockedAgent({
utilization: {
Expand Down

0 comments on commit a5b1e78

Please sign in to comment.