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.
chore: Converted collector unit tests to node:test (newrelic#2510)
- Loading branch information
1 parent
47b8398
commit 762511b
Showing
12 changed files
with
2,119 additions
and
2,872 deletions.
There are no files selected for viewing
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 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 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
module.exports = { | ||
assertMetricValues | ||
} | ||
|
||
const assert = require('node:assert') | ||
|
||
/** | ||
* @param {Transaction} transaction Nodejs agent transaction | ||
* @param {Array} expected Array of metric data where metric data is in this form: | ||
* [ | ||
* { | ||
* “name”:”name of metric”, | ||
* “scope”:”scope of metric”, | ||
* }, | ||
* [count, | ||
* total time, | ||
* exclusive time, | ||
* min time, | ||
* max time, | ||
* sum of squares] | ||
* ] | ||
* @param {boolean} exact When true, found and expected metric lengths should match | ||
*/ | ||
function assertMetricValues(transaction, expected, exact) { | ||
const metrics = transaction.metrics | ||
|
||
for (let i = 0; i < expected.length; ++i) { | ||
let expectedMetric = Object.assign({}, expected[i]) | ||
let name = null | ||
let scope = null | ||
|
||
if (typeof expectedMetric === 'string') { | ||
name = expectedMetric | ||
expectedMetric = {} | ||
} else { | ||
name = expectedMetric[0].name | ||
scope = expectedMetric[0].scope | ||
} | ||
|
||
const metric = metrics.getMetric(name, scope) | ||
assert.ok(metric, 'should have expected metric name') | ||
|
||
assert.deepStrictEqual(metric.toJSON(), expectedMetric[1], 'metric values should match') | ||
} | ||
|
||
if (exact) { | ||
const metricsJSON = metrics.toJSON() | ||
assert.equal(metricsJSON.length, expected.length, 'metrics length should match') | ||
} | ||
} |
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.