forked from newrelic/node-newrelic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Migrated
test/integration/utilization
tests to node node:test
- Loading branch information
Showing
14 changed files
with
260 additions
and
264 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
const test = require('node:test') | ||
const vendorTests = require('./vendor-info-tests') | ||
|
||
test('pricing aws info', async function (t) { | ||
await vendorTests(t, 'aws') | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const test = require('node:test') | ||
const vendorTests = require('./vendor-info-tests') | ||
|
||
test('pricing azure info', async function (t) { | ||
await vendorTests(t, 'azure') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const assert = require('node:assert') | ||
const fs = require('fs/promises') | ||
const glob = require('glob') | ||
const JSONbig = require('json-bigint')({ useNativeBigInt: true }) | ||
const path = require('path') | ||
|
||
function checkMetrics(agent, expectedMetrics) { | ||
if (!expectedMetrics) { | ||
assert.equal(agent.metrics._metrics.toJSON().length, 0, 'should not have any metrics') | ||
return | ||
} | ||
|
||
Object.keys(expectedMetrics).forEach(function (expectedMetric) { | ||
const metric = agent.metrics.getOrCreateMetric(expectedMetric) | ||
assert.equal( | ||
metric.callCount, | ||
expectedMetrics[expectedMetric].call_count, | ||
'should have correct metric call count (' + expectedMetric + ')' | ||
) | ||
}) | ||
} | ||
|
||
async function getTestCases(vendor) { | ||
const testFile = path.resolve( | ||
__dirname, | ||
'../../lib/cross_agent_tests/utilization_vendor_specific', | ||
vendor + '.json' | ||
) | ||
const data = await fs.readFile(testFile) | ||
return JSONbig.parse(data) | ||
} | ||
|
||
async function getProcTests(type) { | ||
const testDir = path.resolve(__dirname, '../../lib/cross_agent_tests', type) | ||
return new Promise((resolve, reject) => { | ||
glob(path.join(testDir, '*.txt'), function (err, fileList) { | ||
if (err) { | ||
return reject(err) | ||
} | ||
return resolve(fileList) | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = { | ||
checkMetrics, | ||
getTestCases, | ||
getProcTests | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const test = require('node:test') | ||
const vendorTests = require('./vendor-info-tests') | ||
|
||
test('pricing gcp info', async function (t) { | ||
await vendorTests(t, 'gcp') | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
const helper = require('../../lib/agent_helper') | ||
const test = require('node:test') | ||
const assert = require('node:assert') | ||
const { checkMetrics, getTestCases } = require('./common') | ||
|
||
test('pricing pcf info', async function (t) { | ||
const cases = await getTestCases('pcf') | ||
assert.ok(cases.length > 0, 'should have tests to run') | ||
const getInfo = require('../../../lib/utilization/pcf-info') | ||
|
||
t.beforeEach((ctx) => { | ||
const agent = helper.loadMockedAgent() | ||
ctx.nr = { agent } | ||
}) | ||
|
||
t.afterEach((ctx) => { | ||
helper.unloadAgent(ctx.nr.agent) | ||
}) | ||
|
||
for (const testCase of cases) { | ||
await t.test(testCase.testname, makeTest(testCase, getInfo)) | ||
} | ||
}) | ||
|
||
function makeTest(testCase, getInfo) { | ||
return function (t, end) { | ||
const { agent } = t.nr | ||
Object.keys(testCase.env_vars).forEach(function (key) { | ||
const value = testCase.env_vars[key].response | ||
if (value == null) { | ||
delete process.env[key] | ||
} else { | ||
process.env[key] = value | ||
} | ||
}) | ||
|
||
getInfo(agent, function (err, info) { | ||
if (testCase.expected_vendors_hash) { | ||
const expected = testCase.expected_vendors_hash.pcf | ||
assert.ok(!err, 'should not error getting data') | ||
assert.deepEqual(info, expected, 'should have expected info') | ||
} else { | ||
assert.ok(!info, 'should not have received vendor info') | ||
} | ||
|
||
checkMetrics(agent, testCase.expected_metrics) | ||
|
||
end() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.