diff --git a/test/unit/config/attribute-filter.test.js b/test/unit/config/attribute-filter.test.js index 4ed01ef7ce..edbee7e0c1 100644 --- a/test/unit/config/attribute-filter.test.js +++ b/test/unit/config/attribute-filter.test.js @@ -5,33 +5,27 @@ 'use strict' -const tap = require('tap') - +const test = require('node:test') +const assert = require('node:assert') const AttributeFilter = require('../../../lib/config/attribute-filter') const { makeAttributeFilterConfig } = require('../../lib/agent_helper') const DESTS = AttributeFilter.DESTINATIONS -tap.test('#constructor', (t) => { - t.autoend() - - t.test('should require a config object', (t) => { - t.throws(function () { +test('#constructor', async (t) => { + await t.test('should require a config object', () => { + assert.throws(function () { return new AttributeFilter() }) - t.doesNotThrow(function () { + assert.doesNotThrow(function () { return new AttributeFilter(makeAttributeFilterConfig()) }) - - t.end() }) }) -tap.test('#filter', (t) => { - t.autoend() - - t.test('should respect the rules', (t) => { +test('#filter', async (t) => { + await t.test('should respect the rules', () => { const filter = new AttributeFilter( makeAttributeFilterConfig({ attributes: { @@ -50,12 +44,10 @@ tap.test('#filter', (t) => { }) ) - makeFilterAssertions(t, filter) - - t.end() + validateFilter(filter) }) - t.test('should not add include rules when they are disabled', (t) => { + await t.test('should not add include rules when they are disabled', () => { const filter = new AttributeFilter( makeAttributeFilterConfig({ attributes: { @@ -74,16 +66,14 @@ tap.test('#filter', (t) => { }) ) - t.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'a'), DESTS.TRANS_COMMON) - t.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'ab'), DESTS.NONE) - t.equal(filter.filterTransaction(DESTS.TRANS_COMMON, ''), DESTS.TRANS_COMMON) - t.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'b'), DESTS.TRANS_COMMON) - t.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'bc'), DESTS.LIMITED) - - t.end() + assert.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'a'), DESTS.TRANS_COMMON) + assert.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'ab'), DESTS.NONE) + assert.equal(filter.filterTransaction(DESTS.TRANS_COMMON, ''), DESTS.TRANS_COMMON) + assert.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'b'), DESTS.TRANS_COMMON) + assert.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'bc'), DESTS.LIMITED) }) - t.test('should not matter the order of the rules', (t) => { + await t.test('should not matter the order of the rules', () => { const filter = new AttributeFilter( makeAttributeFilterConfig({ attributes: { @@ -102,11 +92,10 @@ tap.test('#filter', (t) => { }) ) - makeFilterAssertions(t, filter) - t.end() + validateFilter(filter) }) - t.test('should match `*` to anything', (t) => { + await t.test('should match `*` to anything', () => { const filter = new AttributeFilter( makeAttributeFilterConfig({ attributes: { @@ -118,16 +107,14 @@ tap.test('#filter', (t) => { }) ) - t.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'a'), DESTS.TRANS_COMMON) - t.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'ab'), DESTS.TRANS_COMMON) - t.equal(filter.filterTransaction(DESTS.TRANS_COMMON, ''), DESTS.NONE) - t.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'b'), DESTS.NONE) - t.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'bc'), DESTS.NONE) - - t.end() + assert.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'a'), DESTS.TRANS_COMMON) + assert.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'ab'), DESTS.TRANS_COMMON) + assert.equal(filter.filterTransaction(DESTS.TRANS_COMMON, ''), DESTS.NONE) + assert.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'b'), DESTS.NONE) + assert.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'bc'), DESTS.NONE) }) - t.test('should parse dot rules correctly', (t) => { + await t.test('should parse dot rules correctly', () => { const filter = new AttributeFilter( makeAttributeFilterConfig({ attributes: { @@ -139,29 +126,35 @@ tap.test('#filter', (t) => { }) ) - t.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'a.c'), DESTS.TRANS_COMMON) - t.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'abc'), DESTS.NONE) - - t.equal(filter.filterTransaction(DESTS.NONE, 'a.c'), DESTS.TRANS_COMMON) - t.equal(filter.filterTransaction(DESTS.NONE, 'abc'), DESTS.NONE) + assert.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'a.c'), DESTS.TRANS_COMMON) + assert.equal(filter.filterTransaction(DESTS.TRANS_COMMON, 'abc'), DESTS.NONE) - t.end() + assert.equal(filter.filterTransaction(DESTS.NONE, 'a.c'), DESTS.TRANS_COMMON) + assert.equal(filter.filterTransaction(DESTS.NONE, 'abc'), DESTS.NONE) }) }) -function makeFilterAssertions(t, filter) { +function validateFilter(filter) { // Filters down from global rules - t.equal(filter.filterTransaction(DESTS.TRANS_SCOPE, 'a'), DESTS.TRANS_COMMON, 'a -> common') - t.equal(filter.filterTransaction(DESTS.TRANS_SCOPE, 'ab'), DESTS.TRANS_EVENT, 'ab -> common') - t.equal(filter.filterTransaction(DESTS.TRANS_SCOPE, 'abc'), DESTS.NONE, 'abc -> common') + assert.equal(filter.filterTransaction(DESTS.TRANS_SCOPE, 'a'), DESTS.TRANS_COMMON, 'a -> common') + assert.equal(filter.filterTransaction(DESTS.TRANS_SCOPE, 'ab'), DESTS.TRANS_EVENT, 'ab -> common') + assert.equal(filter.filterTransaction(DESTS.TRANS_SCOPE, 'abc'), DESTS.NONE, 'abc -> common') // Filters down from destination rules. - t.equal(filter.filterTransaction(DESTS.TRANS_SCOPE, 'b'), DESTS.TRANS_COMMON, 'b -> common') - t.equal(filter.filterTransaction(DESTS.TRANS_SCOPE, 'bc'), DESTS.LIMITED, 'bc -> common') - t.equal(filter.filterTransaction(DESTS.TRANS_SCOPE, 'bcd'), DESTS.TRANS_COMMON, 'bcd -> common') - t.equal(filter.filterTransaction(DESTS.TRANS_SCOPE, 'bcde'), DESTS.TRANS_COMMON, 'bcde -> common') + assert.equal(filter.filterTransaction(DESTS.TRANS_SCOPE, 'b'), DESTS.TRANS_COMMON, 'b -> common') + assert.equal(filter.filterTransaction(DESTS.TRANS_SCOPE, 'bc'), DESTS.LIMITED, 'bc -> common') + assert.equal( + filter.filterTransaction(DESTS.TRANS_SCOPE, 'bcd'), + DESTS.TRANS_COMMON, + 'bcd -> common' + ) + assert.equal( + filter.filterTransaction(DESTS.TRANS_SCOPE, 'bcde'), + DESTS.TRANS_COMMON, + 'bcde -> common' + ) // Adds destinations on top of defaults. - t.equal(filter.filterTransaction(DESTS.NONE, 'a'), DESTS.TRANS_COMMON, 'a -> none') - t.equal(filter.filterTransaction(DESTS.NONE, 'ab'), DESTS.TRANS_EVENT, 'ab -> none') + assert.equal(filter.filterTransaction(DESTS.NONE, 'a'), DESTS.TRANS_COMMON, 'a -> none') + assert.equal(filter.filterTransaction(DESTS.NONE, 'ab'), DESTS.TRANS_EVENT, 'ab -> none') } diff --git a/test/unit/config/collector-hostname.test.js b/test/unit/config/collector-hostname.test.js index 54ef7fae46..5ea9de47a0 100644 --- a/test/unit/config/collector-hostname.test.js +++ b/test/unit/config/collector-hostname.test.js @@ -5,8 +5,8 @@ 'use strict' -const tap = require('tap') - +const test = require('node:test') +const assert = require('node:assert') const Config = require('../../../lib/config') const keyTests = require('../../lib/cross_agent_tests/collector_hostname.json') @@ -17,11 +17,9 @@ const keyMapping = { env_override_host: 'NEW_RELIC_HOST' } -tap.test('collector host name', (t) => { - t.autoend() - - keyTests.forEach(function runTest(testCase) { - t.test(testCase.name, (t) => { +test('collector host name', async (t) => { + for (const testCase of keyTests) { + await t.test(testCase.name, async () => { const confSettings = {} const envSettings = {} Object.keys(testCase).forEach(function assignConfValues(key) { @@ -33,11 +31,10 @@ tap.test('collector host name', (t) => { }) runWithEnv(confSettings, envSettings, (config) => { - t.equal(config.host, testCase.hostname) - t.end() + assert.equal(config.host, testCase.hostname) }) }) - }) + } }) function runWithEnv(conf, envObj, callback) { diff --git a/test/unit/config/config-defaults.test.js b/test/unit/config/config-defaults.test.js index 826a66ed96..a00f2bc162 100644 --- a/test/unit/config/config-defaults.test.js +++ b/test/unit/config/config-defaults.test.js @@ -5,14 +5,13 @@ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const path = require('path') const Config = require('../../../lib/config') -tap.test('with default properties', (t) => { - t.autoend() - +test('with default properties', async (t) => { let configuration = null t.beforeEach(() => { @@ -22,230 +21,187 @@ tap.test('with default properties', (t) => { delete configuration.newrelic_home }) - t.test('should have no application name', (t) => { - t.same(configuration.app_name, []) - t.end() + await t.test('should have no application name', () => { + assert.deepStrictEqual(configuration.app_name, []) }) - t.test('should return no application name', (t) => { - t.same(configuration.applications(), []) - t.end() + await t.test('should return no application name', () => { + assert.deepStrictEqual(configuration.applications(), []) }) - t.test('should have no application ID', (t) => { - t.equal(configuration.application_id, null) - t.end() + await t.test('should have no application ID', () => { + assert.equal(configuration.application_id, null) }) - t.test('should have no license key', (t) => { - t.equal(configuration.license_key, '') - t.end() + await t.test('should have no license key', () => { + assert.equal(configuration.license_key, '') }) - t.test('should connect to the collector at collector.newrelic.com', (t) => { - t.equal(configuration.host, 'collector.newrelic.com') - t.end() + await t.test('should connect to the collector at collector.newrelic.com', () => { + assert.equal(configuration.host, 'collector.newrelic.com') }) - t.test('should connect to the collector on port 443', (t) => { - t.equal(configuration.port, 443) - t.end() + await t.test('should connect to the collector on port 443', () => { + assert.equal(configuration.port, 443) }) - t.test('should have SSL enabled', (t) => { - t.equal(configuration.ssl, true) - t.end() + await t.test('should have SSL enabled', () => { + assert.equal(configuration.ssl, true) }) - t.test('should have no security_policies_token', (t) => { - t.equal(configuration.security_policies_token, '') - t.end() + await t.test('should have no security_policies_token', () => { + assert.equal(configuration.security_policies_token, '') }) - t.test('should have no proxy host', (t) => { - t.equal(configuration.proxy_host, '') - t.end() + await t.test('should have no proxy host', () => { + assert.equal(configuration.proxy_host, '') }) - t.test('should have no proxy port', (t) => { - t.equal(configuration.proxy_port, '') - t.end() + await t.test('should have no proxy port', () => { + assert.equal(configuration.proxy_port, '') }) - t.test('should enable the agent', (t) => { - t.equal(configuration.agent_enabled, true) - t.end() + await t.test('should enable the agent', () => { + assert.equal(configuration.agent_enabled, true) }) - t.test('should have an apdexT of 0.1', (t) => { - t.equal(configuration.apdex_t, 0.1) - t.end() + await t.test('should have an apdexT of 0.1', () => { + assert.equal(configuration.apdex_t, 0.1) }) - t.test('should have a null account_id', (t) => { - t.equal(configuration.account_id, null) - t.end() + await t.test('should have a null account_id', () => { + assert.equal(configuration.account_id, null) }) - t.test('should have a null primary_application_id', (t) => { - t.equal(configuration.primary_application_id, null) - t.end() + await t.test('should have a null primary_application_id', () => { + assert.equal(configuration.primary_application_id, null) }) - t.test('should have a null trusted_account_key', (t) => { - t.equal(configuration.trusted_account_key, null) - t.end() + await t.test('should have a null trusted_account_key', () => { + assert.equal(configuration.trusted_account_key, null) }) - t.test('should have the default excluded request attributes', (t) => { - t.same(configuration.attributes.exclude, []) - t.end() + await t.test('should have the default excluded request attributes', () => { + assert.deepStrictEqual(configuration.attributes.exclude, []) }) - t.test('should have the default attribute include setting', (t) => { - t.equal(configuration.attributes.include_enabled, true) - t.end() + await t.test('should have the default attribute include setting', () => { + assert.equal(configuration.attributes.include_enabled, true) }) - t.test('should have the default error message redaction setting ', (t) => { - t.equal(configuration.strip_exception_messages.enabled, false) - t.end() + await t.test('should have the default error message redaction setting ', () => { + assert.equal(configuration.strip_exception_messages.enabled, false) }) - t.test('should enable transaction event attributes', (t) => { - t.equal(configuration.transaction_events.attributes.enabled, true) - t.end() + await t.test('should enable transaction event attributes', () => { + assert.equal(configuration.transaction_events.attributes.enabled, true) }) - t.test('should log at the info level', (t) => { - t.equal(configuration.logging.level, 'info') - t.end() + await t.test('should log at the info level', () => { + assert.equal(configuration.logging.level, 'info') }) - t.test('should have a log filepath of process.cwd + newrelic_agent.log', (t) => { + await t.test('should have a log filepath of process.cwd + newrelic_agent.log', () => { const logPath = path.join(process.cwd(), 'newrelic_agent.log') - t.equal(configuration.logging.filepath, logPath) - t.end() + assert.equal(configuration.logging.filepath, logPath) }) - t.test('should enable the error collector', (t) => { - t.equal(configuration.error_collector.enabled, true) - t.end() + await t.test('should enable the error collector', () => { + assert.equal(configuration.error_collector.enabled, true) }) - t.test('should enable error collector attributes', (t) => { - t.equal(configuration.error_collector.attributes.enabled, true) - t.end() + await t.test('should enable error collector attributes', () => { + assert.equal(configuration.error_collector.attributes.enabled, true) }) - t.test('should ignore status code 404', (t) => { - t.same(configuration.error_collector.ignore_status_codes, [404]) - t.end() + await t.test('should ignore status code 404', () => { + assert.deepStrictEqual(configuration.error_collector.ignore_status_codes, [404]) }) - t.test('should enable the transaction tracer', (t) => { - t.equal(configuration.transaction_tracer.enabled, true) - t.end() + await t.test('should enable the transaction tracer', () => { + assert.equal(configuration.transaction_tracer.enabled, true) }) - t.test('should enable transaction tracer attributes', (t) => { - t.equal(configuration.transaction_tracer.attributes.enabled, true) - t.end() + await t.test('should enable transaction tracer attributes', () => { + assert.equal(configuration.transaction_tracer.attributes.enabled, true) }) - t.test('should set the transaction tracer threshold to `apdex_f`', (t) => { - t.equal(configuration.transaction_tracer.transaction_threshold, 'apdex_f') - t.end() + await t.test('should set the transaction tracer threshold to `apdex_f`', () => { + assert.equal(configuration.transaction_tracer.transaction_threshold, 'apdex_f') }) - t.test('should collect one slow transaction trace per harvest cycle', (t) => { - t.equal(configuration.transaction_tracer.top_n, 20) - t.end() + await t.test('should collect one slow transaction trace per harvest cycle', () => { + assert.equal(configuration.transaction_tracer.top_n, 20) }) - t.test('should obfsucate sql by default', (t) => { - t.equal(configuration.transaction_tracer.record_sql, 'obfuscated') - t.end() + await t.test('should obfsucate sql by default', () => { + assert.equal(configuration.transaction_tracer.record_sql, 'obfuscated') }) - t.test('should have an explain threshold of 500ms', (t) => { - t.equal(configuration.transaction_tracer.explain_threshold, 500) - t.end() + await t.test('should have an explain threshold of 500ms', () => { + assert.equal(configuration.transaction_tracer.explain_threshold, 500) }) - t.test('should not capture slow queries', (t) => { - t.equal(configuration.slow_sql.enabled, false) - t.end() + await t.test('should not capture slow queries', () => { + assert.equal(configuration.slow_sql.enabled, false) }) - t.test('should capture a maximum of 10 slow-queries per harvest', (t) => { - t.equal(configuration.slow_sql.max_samples, 10) - t.end() + await t.test('should capture a maximum of 10 slow-queries per harvest', () => { + assert.equal(configuration.slow_sql.max_samples, 10) }) - t.test('should have no naming rules', (t) => { - t.equal(configuration.rules.name.length, 0) - t.end() + await t.test('should have no naming rules', () => { + assert.equal(configuration.rules.name.length, 0) }) - t.test('should have one default ignoring rules', (t) => { - t.equal(configuration.rules.ignore.length, 1) - t.end() + await t.test('should have one default ignoring rules', () => { + assert.equal(configuration.rules.ignore.length, 1) }) - t.test('should enforce URL backstop', (t) => { - t.equal(configuration.enforce_backstop, true) - t.end() + await t.test('should enforce URL backstop', () => { + assert.equal(configuration.enforce_backstop, true) }) - t.test('should allow passed-in config to override errors ignored', (t) => { + await t.test('should allow passed-in config to override errors ignored', () => { configuration = Config.initialize({ error_collector: { ignore_status_codes: [] } }) - t.same(configuration.error_collector.ignore_status_codes, []) - t.end() + assert.deepStrictEqual(configuration.error_collector.ignore_status_codes, []) }) - t.test('should disable cross application tracer', (t) => { - t.equal(configuration.cross_application_tracer.enabled, false) - t.end() + await t.test('should disable cross application tracer', () => { + assert.equal(configuration.cross_application_tracer.enabled, false) }) - t.test('should enable message tracer segment parameters', (t) => { - t.equal(configuration.message_tracer.segment_parameters.enabled, true) - t.end() + await t.test('should enable message tracer segment parameters', () => { + assert.equal(configuration.message_tracer.segment_parameters.enabled, true) }) - t.test('should not enable browser monitoring attributes', (t) => { - t.equal(configuration.browser_monitoring.attributes.enabled, false) - t.end() + await t.test('should not enable browser monitoring attributes', () => { + assert.equal(configuration.browser_monitoring.attributes.enabled, false) }) - t.test('should enable browser monitoring attributes', (t) => { - t.equal(configuration.browser_monitoring.attributes.enabled, false) - t.end() + await t.test('should enable browser monitoring attributes', () => { + assert.equal(configuration.browser_monitoring.attributes.enabled, false) }) - t.test('should set max_payload_size_in_bytes', (t) => { - t.equal(configuration.max_payload_size_in_bytes, 1000000) - t.end() + await t.test('should set max_payload_size_in_bytes', () => { + assert.equal(configuration.max_payload_size_in_bytes, 1000000) }) - t.test('should not enable serverless_mode', (t) => { - t.equal(configuration.serverless_mode.enabled, false) - t.end() + await t.test('should not enable serverless_mode', () => { + assert.equal(configuration.serverless_mode.enabled, false) }) - t.test('should default span event max_samples_stored', (t) => { - t.equal(configuration.span_events.max_samples_stored, 2000) - t.end() + await t.test('should default span event max_samples_stored', () => { + assert.equal(configuration.span_events.max_samples_stored, 2000) }) - t.test('should default application logging accordingly', (t) => { - t.same(configuration.application_logging, { + await t.test('should default application logging accordingly', () => { + assert.deepStrictEqual(configuration.application_logging, { enabled: true, forwarding: { enabled: true, @@ -258,16 +214,14 @@ tap.test('with default properties', (t) => { enabled: false } }) - t.end() }) - t.test('should default `code_level_metrics.enabled` to true', (t) => { - t.equal(configuration.code_level_metrics.enabled, true) - t.end() + await t.test('should default `code_level_metrics.enabled` to true', () => { + assert.equal(configuration.code_level_metrics.enabled, true) }) - t.test('should default `url_obfuscation` accordingly', (t) => { - t.same(configuration.url_obfuscation, { + await t.test('should default `url_obfuscation` accordingly', () => { + assert.deepStrictEqual(configuration.url_obfuscation, { enabled: false, regex: { pattern: null, @@ -275,11 +229,10 @@ tap.test('with default properties', (t) => { replacement: '' } }) - t.end() }) - t.test('should default security settings accordingly', (t) => { - t.same(configuration.security, { + await t.test('should default security settings accordingly', () => { + assert.deepStrictEqual(configuration.security, { enabled: false, agent: { enabled: false }, mode: 'IAST', @@ -290,28 +243,23 @@ tap.test('with default properties', (t) => { deserialization: { enabled: true } } }) - t.end() }) - t.test('should default heroku.use_dyno_names to true', (t) => { - t.equal(configuration.heroku.use_dyno_names, true) - t.end() + await t.test('should default heroku.use_dyno_names to true', () => { + assert.equal(configuration.heroku.use_dyno_names, true) }) - t.test('should default batching and compression to true for infinite tracing', (t) => { - t.equal(configuration.infinite_tracing.batching, true) - t.equal(configuration.infinite_tracing.compression, true) - t.end() + await t.test('should default batching and compression to true for infinite tracing', () => { + assert.equal(configuration.infinite_tracing.batching, true) + assert.equal(configuration.infinite_tracing.compression, true) }) - t.test('should default worker_threads.enabled to false', (t) => { - t.equal(configuration.worker_threads.enabled, false) - t.end() + await t.test('should default worker_threads.enabled to false', () => { + assert.equal(configuration.worker_threads.enabled, false) }) - t.test('ai_monitoring defaults', (t) => { - t.equal(configuration.ai_monitoring.enabled, false) - t.equal(configuration.ai_monitoring.streaming.enabled, true) - t.end() + await t.test('ai_monitoring defaults', () => { + assert.equal(configuration.ai_monitoring.enabled, false) + assert.equal(configuration.ai_monitoring.streaming.enabled, true) }) }) diff --git a/test/unit/config/config-env.test.js b/test/unit/config/config-env.test.js index 373cfa404e..b1fd16b3c0 100644 --- a/test/unit/config/config-env.test.js +++ b/test/unit/config/config-env.test.js @@ -5,17 +5,16 @@ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const { idempotentEnv } = require('./helper') const VALID_HOST = 'infinite-tracing.test' const VALID_QUEUE_SIZE = 20000 // should not be 10k which is the default -tap.test('when overriding configuration values via environment variables', (t) => { - t.autoend() - - t.test('should pick up on infinite tracing env vars', (t) => { +test('when overriding configuration values via environment variables', async (t) => { + await t.test('should pick up on infinite tracing env vars', (t, end) => { const env = { NEW_RELIC_INFINITE_TRACING_TRACE_OBSERVER_HOST: VALID_HOST, NEW_RELIC_INFINITE_TRACING_TRACE_OBSERVER_PORT: '500', @@ -25,172 +24,168 @@ tap.test('when overriding configuration values via environment variables', (t) = } idempotentEnv(env, (config) => { - t.equal(config.infinite_tracing.trace_observer.host, VALID_HOST) - t.equal(config.infinite_tracing.trace_observer.port, 500) - t.equal(config.infinite_tracing.span_events.queue_size, VALID_QUEUE_SIZE) - t.equal(config.infinite_tracing.compression, false) - t.equal(config.infinite_tracing.batching, false) - t.end() + assert.equal(config.infinite_tracing.trace_observer.host, VALID_HOST) + assert.equal(config.infinite_tracing.trace_observer.port, 500) + assert.equal(config.infinite_tracing.span_events.queue_size, VALID_QUEUE_SIZE) + assert.equal(config.infinite_tracing.compression, false) + assert.equal(config.infinite_tracing.batching, false) + end() }) }) - t.test('should default infinite tracing port to 443', (t) => { + await t.test('should default infinite tracing port to 443', (t, end) => { const env = { NEW_RELIC_INFINITE_TRACING_TRACE_OBSERVER_HOST: VALID_HOST } idempotentEnv(env, (config) => { - t.equal(config.infinite_tracing.trace_observer.port, 443) - t.end() + assert.equal(config.infinite_tracing.trace_observer.port, 443) + end() }) }) - t.test('should pick up the application name', (t) => { + await t.test('should pick up the application name', (t, end) => { idempotentEnv({ NEW_RELIC_APP_NAME: 'app one,app two;and app three' }, (tc) => { - t.ok(tc.app_name) - t.same(tc.app_name, ['app one', 'app two', 'and app three']) - t.end() + assert.ok(tc.app_name) + assert.deepStrictEqual(tc.app_name, ['app one', 'app two', 'and app three']) + end() }) }) - t.test('should trim spaces from multiple application names ', (t) => { + await t.test('should trim spaces from multiple application names ', (t, end) => { idempotentEnv({ NEW_RELIC_APP_NAME: 'zero,one, two, three; four' }, (tc) => { - t.ok(tc.app_name) - t.same(tc.app_name, ['zero', 'one', 'two', 'three', 'four']) - t.end() + assert.ok(tc.app_name) + assert.deepStrictEqual(tc.app_name, ['zero', 'one', 'two', 'three', 'four']) + end() }) }) - t.test('should pick up the license key', (t) => { + await t.test('should pick up the license key', (t, end) => { idempotentEnv({ NEW_RELIC_LICENSE_KEY: 'hambulance' }, (tc) => { - t.ok(tc.license_key) - t.equal(tc.license_key, 'hambulance') - t.equal(tc.host, 'collector.newrelic.com') - - t.end() + assert.ok(tc.license_key) + assert.equal(tc.license_key, 'hambulance') + assert.equal(tc.host, 'collector.newrelic.com') + end() }) }) - t.test('should trim spaces from license key', (t) => { + await t.test('should trim spaces from license key', (t, end) => { idempotentEnv({ NEW_RELIC_LICENSE_KEY: ' license ' }, (tc) => { - t.ok(tc.license_key) - t.equal(tc.license_key, 'license') - t.equal(tc.host, 'collector.newrelic.com') - - t.end() + assert.ok(tc.license_key) + assert.equal(tc.license_key, 'license') + assert.equal(tc.host, 'collector.newrelic.com') + end() }) }) - t.test('should pick up the apdex_t', (t) => { + await t.test('should pick up the apdex_t', (t, end) => { idempotentEnv({ NEW_RELIC_APDEX_T: '111' }, (tc) => { - t.ok(tc.apdex_t) - t.type(tc.apdex_t, 'number') - t.equal(tc.apdex_t, 111) - - t.end() + assert.ok(tc.apdex_t) + assert.strictEqual(typeof tc.apdex_t, 'number') + assert.equal(tc.apdex_t, 111) + end() }) }) - t.test('should pick up the collector host', (t) => { + await t.test('should pick up the collector host', (t, end) => { idempotentEnv({ NEW_RELIC_HOST: 'localhost' }, (tc) => { - t.ok(tc.host) - t.equal(tc.host, 'localhost') - - t.end() + assert.ok(tc.host) + assert.equal(tc.host, 'localhost') + end() }) }) - t.test('should parse the region off the license key', (t) => { + await t.test('should parse the region off the license key', (t, end) => { idempotentEnv({ NEW_RELIC_LICENSE_KEY: 'eu01xxhambulance' }, (tc) => { - t.ok(tc.host) - t.equal(tc.host, 'collector.eu01.nr-data.net') - t.end() + assert.ok(tc.host) + assert.equal(tc.host, 'collector.eu01.nr-data.net') + end() }) }) - t.test('should take an explicit host over the license key parsed host', (t) => { + await t.test('should take an explicit host over the license key parsed host', (t, end) => { idempotentEnv({ NEW_RELIC_LICENSE_KEY: 'eu01xxhambulance' }, function () { idempotentEnv({ NEW_RELIC_HOST: 'localhost' }, (tc) => { - t.ok(tc.host) - t.equal(tc.host, 'localhost') - - t.end() + assert.ok(tc.host) + assert.equal(tc.host, 'localhost') + end() }) }) }) - t.test('should default OTel host if nothing to parse in the license key', (t) => { + await t.test('should default OTel host if nothing to parse in the license key', (t, end) => { idempotentEnv({ NEW_RELIC_LICENSE_KEY: 'hambulance' }, (tc) => { - t.ok(tc.otlp_endpoint) - t.equal(tc.otlp_endpoint, 'otlp.nr-data.net') - t.end() + assert.ok(tc.otlp_endpoint) + assert.equal(tc.otlp_endpoint, 'otlp.nr-data.net') + end() }) }) - t.test('should parse the region off the license key for OTel', (t) => { + await t.test('should parse the region off the license key for OTel', (t, end) => { idempotentEnv({ NEW_RELIC_LICENSE_KEY: 'eu01xxhambulance' }, (tc) => { - t.ok(tc.otlp_endpoint) - t.equal(tc.otlp_endpoint, 'otlp.eu01.nr-data.net') - t.end() + assert.ok(tc.otlp_endpoint) + assert.equal(tc.otlp_endpoint, 'otlp.eu01.nr-data.net') + end() }) }) - t.test('should take an explicit OTel endpoint over the license key parsed host', (t) => { - idempotentEnv({ NEW_RELIC_LICENSE_KEY: 'eu01xxhambulance' }, function () { - idempotentEnv({ NEW_RELIC_OTLP_ENDPOINT: 'localhost' }, (tc) => { - t.ok(tc.otlp_endpoint) - t.equal(tc.otlp_endpoint, 'localhost') - - t.end() + await t.test( + 'should take an explicit OTel endpoint over the license key parsed host', + (t, end) => { + idempotentEnv({ NEW_RELIC_LICENSE_KEY: 'eu01xxhambulance' }, function () { + idempotentEnv({ NEW_RELIC_OTLP_ENDPOINT: 'localhost' }, (tc) => { + assert.ok(tc.otlp_endpoint) + assert.equal(tc.otlp_endpoint, 'localhost') + end() + }) }) - }) - }) + } + ) - t.test('should pick up on feature flags set via environment variables', (t) => { + await t.test('should pick up on feature flags set via environment variables', (t, end) => { const ffNamePrefix = 'NEW_RELIC_FEATURE_FLAG_' const awaitFeatureFlag = ffNamePrefix + 'AWAIT_SUPPORT' idempotentEnv({ [awaitFeatureFlag]: 'false' }, (tc) => { - t.equal(tc.feature_flag.await_support, false) - t.end() + assert.equal(tc.feature_flag.await_support, false) + end() }) }) - t.test('should pick up the collector port', (t) => { + await t.test('should pick up the collector port', (t, end) => { idempotentEnv({ NEW_RELIC_PORT: '7777' }, (tc) => { - t.equal(tc.port, 7777) - t.end() + assert.equal(tc.port, 7777) + end() }) }) - t.test('should pick up exception message omission settings', (t) => { + await t.test('should pick up exception message omission settings', (t, end) => { idempotentEnv({ NEW_RELIC_STRIP_EXCEPTION_MESSAGES_ENABLED: 'please' }, (tc) => { - t.equal(tc.strip_exception_messages.enabled, true) - t.end() + assert.equal(tc.strip_exception_messages.enabled, true) + end() }) }) - t.test('should pick up the proxy host', (t) => { + await t.test('should pick up the proxy host', (t, end) => { idempotentEnv({ NEW_RELIC_PROXY_HOST: 'proxyhost' }, (tc) => { - t.equal(tc.proxy_host, 'proxyhost') - - t.end() + assert.equal(tc.proxy_host, 'proxyhost') + end() }) }) - t.test('should pick up on Distributed Tracing env vars', (t) => { + await t.test('should pick up on Distributed Tracing env vars', (t, end) => { const env = { NEW_RELIC_DISTRIBUTED_TRACING_ENABLED: 'true', NEW_RELIC_DISTRIBUTED_TRACING_EXCLUDE_NEWRELIC_HEADER: 'true' } idempotentEnv(env, (tc) => { - t.equal(tc.distributed_tracing.enabled, true) - t.equal(tc.distributed_tracing.exclude_newrelic_header, true) - t.end() + assert.equal(tc.distributed_tracing.enabled, true) + assert.equal(tc.distributed_tracing.exclude_newrelic_header, true) + end() }) }) - t.test('should pick up on the span events env vars', (t) => { + await t.test('should pick up on the span events env vars', (t, end) => { const env = { NEW_RELIC_SPAN_EVENTS_ENABLED: true, NEW_RELIC_SPAN_EVENTS_ATTRIBUTES_ENABLED: true, @@ -199,84 +194,82 @@ tap.test('when overriding configuration values via environment variables', (t) = NEW_RELIC_SPAN_EVENTS_MAX_SAMPLES_STORED: 2000 } idempotentEnv(env, (tc) => { - t.equal(tc.span_events.enabled, true) - t.equal(tc.span_events.attributes.enabled, true) - t.same(tc.span_events.attributes.include, ['one', 'two', 'three']) - t.same(tc.span_events.attributes.exclude, ['four', 'five', 'six']) - t.equal(tc.span_events.max_samples_stored, 2000) - - t.end() + assert.equal(tc.span_events.enabled, true) + assert.equal(tc.span_events.attributes.enabled, true) + assert.deepStrictEqual(tc.span_events.attributes.include, ['one', 'two', 'three']) + assert.deepStrictEqual(tc.span_events.attributes.exclude, ['four', 'five', 'six']) + assert.equal(tc.span_events.max_samples_stored, 2000) + end() }) }) - t.test('should pick up on the transaction segments env vars', (t) => { + await t.test('should pick up on the transaction segments env vars', (t, end) => { const env = { NEW_RELIC_TRANSACTION_SEGMENTS_ATTRIBUTES_ENABLED: true, NEW_RELIC_TRANSACTION_SEGMENTS_ATTRIBUTES_INCLUDE: 'one,two,three', NEW_RELIC_TRANSACTION_SEGMENTS_ATTRIBUTES_EXCLUDE: 'four,five,six' } idempotentEnv(env, (tc) => { - t.equal(tc.transaction_segments.attributes.enabled, true) - t.same(tc.transaction_segments.attributes.include, ['one', 'two', 'three']) - t.same(tc.transaction_segments.attributes.exclude, ['four', 'five', 'six']) - - t.end() + assert.equal(tc.transaction_segments.attributes.enabled, true) + assert.deepStrictEqual(tc.transaction_segments.attributes.include, ['one', 'two', 'three']) + assert.deepStrictEqual(tc.transaction_segments.attributes.exclude, ['four', 'five', 'six']) + end() }) }) - t.test('should pick up the number of logical processors of the system', (t) => { + await t.test('should pick up the number of logical processors of the system', (t, end) => { idempotentEnv({ NEW_RELIC_UTILIZATION_LOGICAL_PROCESSORS: '123' }, (tc) => { - t.equal(tc.utilization.logical_processors, 123) - t.end() + assert.equal(tc.utilization.logical_processors, 123) + end() }) }) - t.test('should pick up the billing hostname', (t) => { + await t.test('should pick up the billing hostname', (t, end) => { const env = 'NEW_RELIC_UTILIZATION_BILLING_HOSTNAME' idempotentEnv({ [env]: 'a test string' }, (tc) => { - t.equal(tc.utilization.billing_hostname, 'a test string') - t.end() + assert.equal(tc.utilization.billing_hostname, 'a test string') + end() }) }) - t.test('should pick up the total ram of the system', (t) => { + await t.test('should pick up the total ram of the system', (t, end) => { idempotentEnv({ NEW_RELIC_UTILIZATION_TOTAL_RAM_MIB: '123' }, (tc) => { - t.equal(tc.utilization.total_ram_mib, 123) - t.end() + assert.equal(tc.utilization.total_ram_mib, 123) + end() }) }) - t.test('should pick up the proxy port', (t) => { + await t.test('should pick up the proxy port', (t, end) => { idempotentEnv({ NEW_RELIC_PROXY_PORT: 7777 }, (tc) => { - t.equal(tc.proxy_port, '7777') - t.end() + assert.equal(tc.proxy_port, '7777') + end() }) }) - t.test('should pick up instance reporting', (t) => { + await t.test('should pick up instance reporting', (t, end) => { const env = 'NEW_RELIC_DATASTORE_INSTANCE_REPORTING_ENABLED' idempotentEnv({ [env]: false }, (tc) => { - t.equal(tc.datastore_tracer.instance_reporting.enabled, false) - t.end() + assert.equal(tc.datastore_tracer.instance_reporting.enabled, false) + end() }) }) - t.test('should pick up instance database name reporting', (t) => { + await t.test('should pick up instance database name reporting', (t, end) => { const env = 'NEW_RELIC_DATASTORE_DATABASE_NAME_REPORTING_ENABLED' idempotentEnv({ [env]: false }, (tc) => { - t.equal(tc.datastore_tracer.database_name_reporting.enabled, false) - t.end() + assert.equal(tc.datastore_tracer.database_name_reporting.enabled, false) + end() }) }) - t.test('should pick up the log level', (t) => { + await t.test('should pick up the log level', (t, end) => { idempotentEnv({ NEW_RELIC_LOG_LEVEL: 'XXNOEXIST' }, function (tc) { - t.equal(tc.logging.level, 'XXNOEXIST') - t.end() + assert.equal(tc.logging.level, 'XXNOEXIST') + end() }) }) - t.test('should have log level aliases', (t) => { + await t.test('should have log level aliases', (t, end) => { const logAliases = { verbose: 'trace', debugging: 'debug', @@ -287,188 +280,188 @@ tap.test('when overriding configuration values via environment variables', (t) = // eslint-disable-next-line guard-for-in for (const key in logAliases) { idempotentEnv({ NEW_RELIC_LOG_LEVEL: key }, (tc) => { - t.equal(tc.logging.level, logAliases[key]) + assert.equal(tc.logging.level, logAliases[key]) }) } - t.end() + end() }) - t.test('should pick up the log filepath', (t) => { + await t.test('should pick up the log filepath', (t, end) => { idempotentEnv({ NEW_RELIC_LOG: '/highway/to/the/danger/zone' }, (tc) => { - t.equal(tc.logging.filepath, '/highway/to/the/danger/zone') - t.end() + assert.equal(tc.logging.filepath, '/highway/to/the/danger/zone') + end() }) }) - t.test('should pick up whether the agent is enabled', (t) => { + await t.test('should pick up whether the agent is enabled', (t, end) => { idempotentEnv({ NEW_RELIC_ENABLED: 0 }, (tc) => { - t.equal(tc.agent_enabled, false) - t.end() + assert.equal(tc.agent_enabled, false) + end() }) }) - t.test('should pick up whether to capture attributes', (t) => { + await t.test('should pick up whether to capture attributes', (t, end) => { idempotentEnv({ NEW_RELIC_ATTRIBUTES_ENABLED: 'yes' }, (tc) => { - t.equal(tc.attributes.enabled, true) - t.end() + assert.equal(tc.attributes.enabled, true) + end() }) }) - t.test('should pick up whether to add attribute include rules', (t) => { + await t.test('should pick up whether to add attribute include rules', (t, end) => { idempotentEnv({ NEW_RELIC_ATTRIBUTES_INCLUDE_ENABLED: 'yes' }, (tc) => { - t.equal(tc.attributes.include_enabled, true) - t.end() + assert.equal(tc.attributes.include_enabled, true) + end() }) }) - t.test('should pick up excluded attributes', (t) => { + await t.test('should pick up excluded attributes', (t, end) => { idempotentEnv({ NEW_RELIC_ATTRIBUTES_EXCLUDE: 'one,two,three' }, (tc) => { - t.same(tc.attributes.exclude, ['one', 'two', 'three']) - t.end() + assert.deepStrictEqual(tc.attributes.exclude, ['one', 'two', 'three']) + end() }) }) - t.test('should pick up whether the error collector is enabled', (t) => { + await t.test('should pick up whether the error collector is enabled', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_ENABLED: 'NO' }, (tc) => { - t.equal(tc.error_collector.enabled, false) - t.end() + assert.equal(tc.error_collector.enabled, false) + end() }) }) - t.test('should pick up whether error collector attributes are enabled', (t) => { + await t.test('should pick up whether error collector attributes are enabled', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_ATTRIBUTES_ENABLED: 'NO' }, (tc) => { - t.equal(tc.error_collector.attributes.enabled, false) - t.end() + assert.equal(tc.error_collector.attributes.enabled, false) + end() }) }) - t.test('should pick up error collector max_event_samples_stored value', (t) => { + await t.test('should pick up error collector max_event_samples_stored value', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_MAX_EVENT_SAMPLES_STORED: 20 }, (tc) => { - t.equal(tc.error_collector.max_event_samples_stored, 20) - t.end() + assert.equal(tc.error_collector.max_event_samples_stored, 20) + end() }) }) - t.test('should pick up which status codes are ignored', (t) => { + await t.test('should pick up which status codes are ignored', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES: '401,404,502' }, (tc) => { - t.same(tc.error_collector.ignore_status_codes, [401, 404, 502]) - t.end() + assert.deepStrictEqual(tc.error_collector.ignore_status_codes, [401, 404, 502]) + end() }) }) - t.test('should pick up which status codes are ignored when using a range', (t) => { + await t.test('should pick up which status codes are ignored when using a range', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES: '401, 420-421, 502' }, (tc) => { - t.same(tc.error_collector.ignore_status_codes, [401, 420, 421, 502]) - t.end() + assert.deepStrictEqual(tc.error_collector.ignore_status_codes, [401, 420, 421, 502]) + end() }) }) - t.test('should not add codes given with invalid range', (t) => { + await t.test('should not add codes given with invalid range', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES: '421-420' }, (tc) => { - t.same(tc.error_collector.ignore_status_codes, []) - t.end() + assert.deepStrictEqual(tc.error_collector.ignore_status_codes, []) + end() }) }) - t.test('should not add codes if given out of range', (t) => { + await t.test('should not add codes if given out of range', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES: '1 - 1776' }, (tc) => { - t.same(tc.error_collector.ignore_status_codes, []) - t.end() + assert.deepStrictEqual(tc.error_collector.ignore_status_codes, []) + end() }) }) - t.test('should allow negative status codes ', (t) => { + await t.test('should allow negative status codes ', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES: '-7' }, (tc) => { - t.same(tc.error_collector.ignore_status_codes, [-7]) - t.end() + assert.deepStrictEqual(tc.error_collector.ignore_status_codes, [-7]) + end() }) }) - t.test('should not add codes that parse to NaN ', (t) => { + await t.test('should not add codes that parse to NaN ', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES: 'abc' }, (tc) => { - t.same(tc.error_collector.ignore_status_codes, []) - t.end() + assert.deepStrictEqual(tc.error_collector.ignore_status_codes, []) + end() }) }) - t.test('should pick up which status codes are expected', (t) => { + await t.test('should pick up which status codes are expected', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_EXPECTED_ERROR_CODES: '401,404,502' }, (tc) => { - t.same(tc.error_collector.expected_status_codes, [401, 404, 502]) - t.end() + assert.deepStrictEqual(tc.error_collector.expected_status_codes, [401, 404, 502]) + end() }) }) - t.test('should pick up which status codes are expectedd when using a range', (t) => { + await t.test('should pick up which status codes are expectedd when using a range', (t, end) => { idempotentEnv( { NEW_RELIC_ERROR_COLLECTOR_EXPECTED_ERROR_CODES: '401, 420-421, 502' }, (tc) => { - t.same(tc.error_collector.expected_status_codes, [401, 420, 421, 502]) - t.end() + assert.deepStrictEqual(tc.error_collector.expected_status_codes, [401, 420, 421, 502]) + end() } ) }) - t.test('should not add codes given with invalid range', (t) => { + await t.test('should not add codes given with invalid range', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_EXPECTED_ERROR_CODES: '421-420' }, (tc) => { - t.same(tc.error_collector.expected_status_codes, []) - t.end() + assert.deepStrictEqual(tc.error_collector.expected_status_codes, []) + end() }) }) - t.test('should not add codes if given out of range', (t) => { + await t.test('should not add codes if given out of range', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_EXPECTED_ERROR_CODES: '1 - 1776' }, (tc) => { - t.same(tc.error_collector.expected_status_codes, []) - t.end() + assert.deepStrictEqual(tc.error_collector.expected_status_codes, []) + end() }) }) - t.test('should allow negative status codes ', (t) => { + await t.test('should allow negative status codes ', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_EXPECTED_ERROR_CODES: '-7' }, (tc) => { - t.same(tc.error_collector.expected_status_codes, [-7]) - t.end() + assert.deepStrictEqual(tc.error_collector.expected_status_codes, [-7]) + end() }) }) - t.test('should not add codes that parse to NaN ', (t) => { + await t.test('should not add codes that parse to NaN ', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_EXPECTED_ERROR_CODES: 'abc' }, (tc) => { - t.same(tc.error_collector.expected_status_codes, []) - t.end() + assert.deepStrictEqual(tc.error_collector.expected_status_codes, []) + end() }) }) - t.test('should pick up whether the transaction tracer is enabled', (t) => { + await t.test('should pick up whether the transaction tracer is enabled', (t, end) => { idempotentEnv({ NEW_RELIC_TRACER_ENABLED: false }, function (tc) { - t.equal(tc.transaction_tracer.enabled, false) - t.end() + assert.equal(tc.transaction_tracer.enabled, false) + end() }) }) - t.test('should pick up whether transaction tracer attributes are enabled', (t) => { + await t.test('should pick up whether transaction tracer attributes are enabled', (t, end) => { const key = 'NEW_RELIC_TRANSACTION_TRACER_ATTRIBUTES_ENABLED' idempotentEnv({ [key]: false }, (tc) => { - t.equal(tc.transaction_tracer.attributes.enabled, false) - t.end() + assert.equal(tc.transaction_tracer.attributes.enabled, false) + end() }) }) - t.test('should pick up the transaction trace threshold', (t) => { + await t.test('should pick up the transaction trace threshold', (t, end) => { idempotentEnv({ NEW_RELIC_TRACER_THRESHOLD: 0.02 }, (tc) => { - t.equal(tc.transaction_tracer.transaction_threshold, 0.02) - t.end() + assert.equal(tc.transaction_tracer.transaction_threshold, 0.02) + end() }) }) - t.test('should pick up the transaction trace Top N scale', (t) => { + await t.test('should pick up the transaction trace Top N scale', (t, end) => { idempotentEnv({ NEW_RELIC_TRACER_TOP_N: '5' }, (tc) => { - t.equal(tc.transaction_tracer.top_n, 5) - t.end() + assert.equal(tc.transaction_tracer.top_n, 5) + end() }) }) - t.test('should pick up the transaction events env vars', (t) => { + await t.test('should pick up the transaction events env vars', (t, end) => { const env = { NEW_RELIC_TRANSACTION_EVENTS_ATTRIBUTES_ENABLED: true, NEW_RELIC_TRANSACTION_EVENTS_ATTRIBUTES_INCLUDE: 'one,two,three', @@ -476,156 +469,158 @@ tap.test('when overriding configuration values via environment variables', (t) = NEW_RELIC_TRANSACTION_EVENTS_MAX_SAMPLES_STORED: 200 } idempotentEnv(env, (tc) => { - t.equal(tc.transaction_events.attributes.enabled, true) - t.same(tc.transaction_events.attributes.include, ['one', 'two', 'three']) - t.same(tc.transaction_events.attributes.exclude, ['four', 'five', 'six']) - t.equal(tc.transaction_events.max_samples_stored, 200) - - t.end() + assert.equal(tc.transaction_events.attributes.enabled, true) + assert.deepStrictEqual(tc.transaction_events.attributes.include, ['one', 'two', 'three']) + assert.deepStrictEqual(tc.transaction_events.attributes.exclude, ['four', 'five', 'six']) + assert.equal(tc.transaction_events.max_samples_stored, 200) + end() }) }) - t.test('should pick up the custom insights events max samples stored env var', (t) => { + await t.test('should pick up the custom insights events max samples stored env var', (t, end) => { idempotentEnv({ NEW_RELIC_CUSTOM_INSIGHTS_EVENTS_MAX_SAMPLES_STORED: 88 }, (tc) => { - t.equal(tc.custom_insights_events.max_samples_stored, 88) - t.end() + assert.equal(tc.custom_insights_events.max_samples_stored, 88) + end() }) }) - t.test('should pick up renaming rules', (t) => { + await t.test('should pick up renaming rules', (t, end) => { idempotentEnv( { NEW_RELIC_NAMING_RULES: '{"name":"u","pattern":"^t"},{"name":"t","pattern":"^u"}' }, (tc) => { - t.same(tc.rules.name, [ + assert.deepStrictEqual(tc.rules.name, [ { name: 'u', pattern: '^t' }, { name: 't', pattern: '^u' } ]) - - t.end() + end() } ) }) - t.test('should pick up ignoring rules', (t) => { + await t.test('should pick up ignoring rules', (t, end) => { idempotentEnv( { NEW_RELIC_IGNORING_RULES: '^/test,^/no_match,^/socket\\.io/,^/api/.*/index$' }, (tc) => { - t.same(tc.rules.ignore, ['^/test', '^/no_match', '^/socket\\.io/', '^/api/.*/index$']) - - t.end() + assert.deepStrictEqual(tc.rules.ignore, [ + '^/test', + '^/no_match', + '^/socket\\.io/', + '^/api/.*/index$' + ]) + end() } ) }) - t.test('should pick up whether URL backstop has been turned off', (t) => { + await t.test('should pick up whether URL backstop has been turned off', (t, end) => { idempotentEnv({ NEW_RELIC_ENFORCE_BACKSTOP: 'f' }, (tc) => { - t.equal(tc.enforce_backstop, false) - t.end() + assert.equal(tc.enforce_backstop, false) + end() }) }) - t.test('should pick app name from APP_POOL_ID', (t) => { + await t.test('should pick app name from APP_POOL_ID', (t, end) => { idempotentEnv({ APP_POOL_ID: 'Simple Azure app' }, (tc) => { - t.same(tc.applications(), ['Simple Azure app']) - t.end() + assert.deepStrictEqual(tc.applications(), ['Simple Azure app']) + end() }) }) // NOTE: the conversion is done in lib/collector/facts.js - t.test('should pick up labels', (t) => { + await t.test('should pick up labels', (t, end) => { idempotentEnv({ NEW_RELIC_LABELS: 'key:value;a:b;' }, (tc) => { - t.equal(tc.labels, 'key:value;a:b;') - t.end() + assert.equal(tc.labels, 'key:value;a:b;') + end() }) }) const values = ['off', 'obfuscated', 'raw', 'invalid'] - values.forEach((val) => { + for (const val of values) { const expectedValue = val === 'invalid' ? 'off' : val - t.test(`should pickup record_sql value of ${expectedValue}`, (t) => { + await t.test(`should pickup record_sql value of ${expectedValue}`, (t, end) => { idempotentEnv({ NEW_RELIC_RECORD_SQL: val }, (tc) => { - t.equal(tc.transaction_tracer.record_sql, expectedValue) - t.end() + assert.equal(tc.transaction_tracer.record_sql, expectedValue) + end() }) }) - }) + } - t.test('should pickup explain_threshold', (t) => { + await t.test('should pickup explain_threshold', (t, end) => { idempotentEnv({ NEW_RELIC_EXPLAIN_THRESHOLD: '100' }, (tc) => { - t.equal(tc.transaction_tracer.explain_threshold, 100) - t.end() + assert.equal(tc.transaction_tracer.explain_threshold, 100) + end() }) }) - t.test('should pickup slow_sql.enabled', (t) => { + await t.test('should pickup slow_sql.enabled', (t, end) => { idempotentEnv({ NEW_RELIC_SLOW_SQL_ENABLED: 'true' }, (tc) => { - t.equal(tc.slow_sql.enabled, true) - t.end() + assert.equal(tc.slow_sql.enabled, true) + end() }) }) - t.test('should pickup slow_sql.max_samples', (t) => { + await t.test('should pickup slow_sql.max_samples', (t, end) => { idempotentEnv({ NEW_RELIC_MAX_SQL_SAMPLES: '100' }, (tc) => { - t.equal(tc.slow_sql.max_samples, 100) - t.end() + assert.equal(tc.slow_sql.max_samples, 100) + end() }) }) - t.test('should pick up logging.enabled', (t) => { + await t.test('should pick up logging.enabled', (t, end) => { idempotentEnv({ NEW_RELIC_LOG_ENABLED: 'false' }, (tc) => { - t.equal(tc.logging.enabled, false) - t.end() + assert.equal(tc.logging.enabled, false) + end() }) }) - t.test('should pick up message tracer segment reporting', (t) => { + await t.test('should pick up message tracer segment reporting', (t, end) => { const env = 'NEW_RELIC_MESSAGE_TRACER_SEGMENT_PARAMETERS_ENABLED' idempotentEnv({ [env]: false }, (tc) => { - t.equal(tc.message_tracer.segment_parameters.enabled, false) - t.end() + assert.equal(tc.message_tracer.segment_parameters.enabled, false) + end() }) }) - t.test('should pick up disabled utilization detection', (t) => { + await t.test('should pick up disabled utilization detection', (t, end) => { idempotentEnv({ NEW_RELIC_UTILIZATION_DETECT_AWS: false }, (tc) => { - t.equal(tc.utilization.detect_aws, false) - t.end() + assert.equal(tc.utilization.detect_aws, false) + end() }) }) - t.test('should reject disabling ssl', (t) => { + await t.test('should reject disabling ssl', (t, end) => { idempotentEnv({ NEW_RELIC_USE_SSL: false }, (tc) => { - t.equal(tc.ssl, true) - t.end() + assert.equal(tc.ssl, true) + end() }) }) - t.test('should pick up ignored error classes', (t) => { + await t.test('should pick up ignored error classes', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERRORS: 'Error, AnotherError' }, (tc) => { - t.same(tc.error_collector.ignore_classes, ['Error', 'AnotherError']) - t.end() + assert.deepStrictEqual(tc.error_collector.ignore_classes, ['Error', 'AnotherError']) + end() }) }) - t.test('should pick up expected error classes', (t) => { + await t.test('should pick up expected error classes', (t, end) => { idempotentEnv({ NEW_RELIC_ERROR_COLLECTOR_EXPECTED_ERRORS: 'QError, AnotherError' }, (tc) => { - t.same(tc.error_collector.expected_classes, ['QError', 'AnotherError']) - t.end() + assert.deepStrictEqual(tc.error_collector.expected_classes, ['QError', 'AnotherError']) + end() }) }) - t.test('should pick up all_all_headers', (t) => { + await t.test('should pick up all_all_headers', (t, end) => { idempotentEnv({ NEW_RELIC_ALLOW_ALL_HEADERS: 'true' }, function (tc) { - t.equal(tc.allow_all_headers, true) - t.end() + assert.equal(tc.allow_all_headers, true) + end() }) }) - t.test('should pick up application logging values', (t) => { + await t.test('should pick up application logging values', (t, end) => { const config = { NEW_RELIC_APPLICATION_LOGGING_ENABLED: 'true', NEW_RELIC_APPLICATION_LOGGING_FORWARDING_ENABLED: 'true', @@ -634,7 +629,7 @@ tap.test('when overriding configuration values via environment variables', (t) = NEW_RELIC_APPLICATION_LOGGING_LOCAL_DECORATING_ENABLED: 'true' } idempotentEnv(config, function (tc) { - t.strictSame(tc.application_logging, { + assert.deepStrictEqual(tc.application_logging, { enabled: true, forwarding: { enabled: true, @@ -647,131 +642,131 @@ tap.test('when overriding configuration values via environment variables', (t) = enabled: true } }) - t.end() + end() }) }) - t.test('should pick up ignore_server_configuration', (t) => { + await t.test('should pick up ignore_server_configuration', (t, end) => { idempotentEnv({ NEW_RELIC_IGNORE_SERVER_SIDE_CONFIG: 'true' }, function (tc) { - t.equal(tc.ignore_server_configuration, true) - t.end() + assert.equal(tc.ignore_server_configuration, true) + end() }) }) const ipvValues = ['4', '6', 'bogus'] - ipvValues.forEach((val) => { + for (const val of ipvValues) { const expectedValue = val === 'bogus' ? '4' : val - t.test(`should pick up ipv_preference of ${expectedValue}`, (t) => { + await t.test(`should pick up ipv_preference of ${expectedValue}`, (t, end) => { idempotentEnv({ NEW_RELIC_IPV_PREFERENCE: val }, function (tc) { - t.equal(tc.process_host.ipv_preference, expectedValue) - t.end() + assert.equal(tc.process_host.ipv_preference, expectedValue) + end() }) }) - }) - t.test('should pick up error_collector.ignore_messages', (t) => { - const config = { Error: ['On no'] } - idempotentEnv( - { NEW_RELIC_ERROR_COLLECTOR_IGNORE_MESSAGES: JSON.stringify(config) }, - function (tc) { - t.same(tc.error_collector.ignore_messages, config) - t.end() - } - ) - }) + await t.test('should pick up error_collector.ignore_messages', (t, end) => { + const config = { Error: ['On no'] } + idempotentEnv( + { NEW_RELIC_ERROR_COLLECTOR_IGNORE_MESSAGES: JSON.stringify(config) }, + function (tc) { + assert.deepStrictEqual(tc.error_collector.ignore_messages, config) + end() + } + ) + }) - t.test('should pick up code_level_metrics.enabled', (t) => { - idempotentEnv({ NEW_RELIC_CODE_LEVEL_METRICS_ENABLED: 'true' }, function (tc) { - t.equal(tc.code_level_metrics.enabled, true) - t.end() + await t.test('should pick up code_level_metrics.enabled', (t, end) => { + idempotentEnv({ NEW_RELIC_CODE_LEVEL_METRICS_ENABLED: 'true' }, function (tc) { + assert.equal(tc.code_level_metrics.enabled, true) + end() + }) }) - }) - t.test('should pick up url_obfuscation.enabled', (t) => { - const env = { - NEW_RELIC_URL_OBFUSCATION_ENABLED: 'true' - } + await t.test('should pick up url_obfuscation.enabled', (t, end) => { + const env = { + NEW_RELIC_URL_OBFUSCATION_ENABLED: 'true' + } - idempotentEnv(env, (config) => { - t.equal(config.url_obfuscation.enabled, true) - t.end() + idempotentEnv(env, (config) => { + assert.equal(config.url_obfuscation.enabled, true) + end() + }) }) - }) - t.test('should pick up url_obfuscation.regex parameters', (t) => { - const env = { - NEW_RELIC_URL_OBFUSCATION_REGEX_PATTERN: 'regex', - NEW_RELIC_URL_OBFUSCATION_REGEX_FLAGS: 'g', - NEW_RELIC_URL_OBFUSCATION_REGEX_REPLACEMENT: 'replacement' - } + await t.test('should pick up url_obfuscation.regex parameters', (t, end) => { + const env = { + NEW_RELIC_URL_OBFUSCATION_REGEX_PATTERN: 'regex', + NEW_RELIC_URL_OBFUSCATION_REGEX_FLAGS: 'g', + NEW_RELIC_URL_OBFUSCATION_REGEX_REPLACEMENT: 'replacement' + } - idempotentEnv(env, (config) => { - t.same(config.url_obfuscation.regex.pattern, /regex/) - t.equal(config.url_obfuscation.regex.flags, 'g') - t.equal(config.url_obfuscation.regex.replacement, 'replacement') - t.end() + idempotentEnv(env, (config) => { + assert.deepStrictEqual(config.url_obfuscation.regex.pattern, /regex/) + assert.equal(config.url_obfuscation.regex.flags, 'g') + assert.equal(config.url_obfuscation.regex.replacement, 'replacement') + end() + }) }) - }) - t.test('should set regex to undefined if invalid regex', (t) => { - const env = { - NEW_RELIC_URL_OBFUSCATION_REGEX_PATTERN: '[' - } + await t.test('should set regex to undefined if invalid regex', (t, end) => { + const env = { + NEW_RELIC_URL_OBFUSCATION_REGEX_PATTERN: '[' + } - idempotentEnv(env, (config) => { - t.notOk(config.url_obfuscation.regex.pattern) - t.end() + idempotentEnv(env, (config) => { + assert.ok(!config.url_obfuscation.regex.pattern) + end() + }) }) - }) - t.test('should convert NEW_RELIC_GRPC_IGNORE_STATUS_CODES to integers', (t) => { - const env = { - NEW_RELIC_GRPC_IGNORE_STATUS_CODES: '5-7,blah,9' - } + await t.test('should convert NEW_RELIC_GRPC_IGNORE_STATUS_CODES to integers', (t, end) => { + const env = { + NEW_RELIC_GRPC_IGNORE_STATUS_CODES: '5-7,blah,9' + } - idempotentEnv(env, (config) => { - t.same(config.grpc.ignore_status_codes, [5, 6, 7, 9]) - t.end() + idempotentEnv(env, (config) => { + assert.deepStrictEqual(config.grpc.ignore_status_codes, [5, 6, 7, 9]) + end() + }) }) - }) - t.test('should convert security env vars accordingly', (t) => { - const env = { - NEW_RELIC_SECURITY_ENABLED: true, - NEW_RELIC_SECURITY_AGENT_ENABLED: true, - NEW_RELIC_SECURITY_MODE: 'RASP', - NEW_RELIC_SECURITY_VALIDATOR_SERVICE_URL: 'new-url', - NEW_RELIC_SECURITY_DETECTION_RCI_ENABLED: false, - NEW_RELIC_SECURITY_DETECTION_RXSS_ENABLED: false, - NEW_RELIC_SECURITY_DETECTION_DESERIALIZATION_ENABLED: false - } - idempotentEnv(env, (config) => { - t.same(config.security, { - enabled: true, - agent: { enabled: true }, - mode: 'RASP', - validator_service_url: 'new-url', - detection: { - rci: { enabled: false }, - rxss: { enabled: false }, - deserialization: { enabled: false } - } + await t.test('should convert security env vars accordingly', (t, end) => { + const env = { + NEW_RELIC_SECURITY_ENABLED: true, + NEW_RELIC_SECURITY_AGENT_ENABLED: true, + NEW_RELIC_SECURITY_MODE: 'RASP', + NEW_RELIC_SECURITY_VALIDATOR_SERVICE_URL: 'new-url', + NEW_RELIC_SECURITY_DETECTION_RCI_ENABLED: false, + NEW_RELIC_SECURITY_DETECTION_RXSS_ENABLED: false, + NEW_RELIC_SECURITY_DETECTION_DESERIALIZATION_ENABLED: false + } + idempotentEnv(env, (config) => { + assert.deepStrictEqual(config.security, { + enabled: true, + agent: { enabled: true }, + mode: 'RASP', + validator_service_url: 'new-url', + detection: { + rci: { enabled: false }, + rxss: { enabled: false }, + deserialization: { enabled: false } + } + }) + end() }) - t.end() }) - }) - t.test('should convert NEW_RELIC_HEROKU_USE_DYNO_NAMES accordingly', (t) => { - idempotentEnv({ NEW_RELIC_HEROKU_USE_DYNO_NAMES: 'false' }, (config) => { - t.equal(config.heroku.use_dyno_names, false) - t.end() + await t.test('should convert NEW_RELIC_HEROKU_USE_DYNO_NAMES accordingly', (t, end) => { + idempotentEnv({ NEW_RELIC_HEROKU_USE_DYNO_NAMES: 'false' }, (config) => { + assert.equal(config.heroku.use_dyno_names, false) + end() + }) }) - }) - t.test('should convert NEW_RELIC_WORKER_THREADS_ENABLED accordingly', (t) => { - idempotentEnv({ NEW_RELIC_WORKER_THREADS_ENABLED: 'true' }, (config) => { - t.equal(config.worker_threads.enabled, true) - t.end() + await t.test('should convert NEW_RELIC_WORKER_THREADS_ENABLED accordingly', (t, end) => { + idempotentEnv({ NEW_RELIC_WORKER_THREADS_ENABLED: 'true' }, (config) => { + assert.equal(config.worker_threads.enabled, true) + end() + }) }) - }) + } }) diff --git a/test/unit/config/config-formatters.test.js b/test/unit/config/config-formatters.test.js index 67c9608433..1f37f77b5c 100644 --- a/test/unit/config/config-formatters.test.js +++ b/test/unit/config/config-formatters.test.js @@ -5,175 +5,146 @@ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const sinon = require('sinon') const formatters = require('../../../lib/config/formatters') -tap.test('config formatters', (t) => { - t.autoend() - - tap.test('array', (t) => { - t.autoend() - - t.test('should trim string into array', (t) => { +test('config formatters', async () => { + await test('array', async (t) => { + await t.test('should trim string into array', () => { const val = 'opt1, opt2 , opt3 , opt4' const options = formatters.array(val) - t.same(options, ['opt1', 'opt2', 'opt3', 'opt4']) - t.end() + assert.deepStrictEqual(options, ['opt1', 'opt2', 'opt3', 'opt4']) }) - t.test('should create an array with 1 element if no comma exists', (t) => { - t.same(formatters.array('hello'), ['hello']) - t.end() + await t.test('should create an array with 1 element if no comma exists', () => { + assert.deepStrictEqual(formatters.array('hello'), ['hello']) }) }) - tap.test('int', (t) => { - t.autoend() - - t.test('should parse number string as int', (t) => { - t.equal(formatters.int('100'), 100) - t.end() + await test('int', async (t) => { + await t.test('should parse number string as int', () => { + assert.equal(formatters.int('100'), 100) }) - t.test('should return isNaN is string is not a number', (t) => { - t.ok(isNaN(formatters.int('hello'))) - t.end() + await t.test('should return isNaN is string is not a number', () => { + assert.ok(isNaN(formatters.int('hello'))) }) - t.test('should parse float as int', (t) => { + await t.test('should parse float as int', () => { const values = ['1.01', 1.01] values.forEach((val) => { - t.equal(formatters.int(val), 1) + assert.equal(formatters.int(val), 1) }) - t.end() }) }) - tap.test('float', (t) => { - t.autoend() - - t.test('should parse number string as float', (t) => { - t.equal(formatters.float('100'), 100) - t.end() + await test('float', async (t) => { + await t.test('should parse number string as float', () => { + assert.equal(formatters.float('100'), 100) }) - t.test('should return isNaN is string is not a number', (t) => { - t.ok(isNaN(formatters.float('hello'))) - t.end() + await t.test('should return isNaN is string is not a number', () => { + assert.ok(isNaN(formatters.float('hello'))) }) - t.test('should parse float accordingly', (t) => { + await t.test('should parse float accordingly', () => { const values = ['1.01', 1.01] values.forEach((val) => { - t.equal(formatters.float(val), 1.01) + assert.equal(formatters.float(val), 1.01) }) - t.end() }) }) - tap.test('boolean', (t) => { - t.autoend() - + await test('boolean', async (t) => { const falseyValues = [null, 'false', 'f', 'no', 'n', 'disabled', '0'] - falseyValues.forEach((val) => { - t.test(`should map ${val} to false`, (t) => { - t.equal(formatters.boolean(val), false) - t.end() + for (const val of falseyValues) { + await t.test(`should map ${val} to false`, () => { + assert.equal(formatters.boolean(val), false) }) - }) + } // these are new tests but do not want to change behavior of this formatter // but anything that is not a falsey value above is true ¯\_(ツ)_/¯ const truthyValues = ['true', 'anything-else', '[]', '{}'] - truthyValues.forEach((val) => { - t.test(`should map ${val} to true`, (t) => { - t.equal(formatters.boolean(val), true) - t.end() + for (const val of truthyValues) { + await t.test(`should map ${val} to true`, () => { + assert.equal(formatters.boolean(val), true) }) - }) + } }) - tap.test('object', (t) => { - t.autoend() - - t.test('should parse json string as an object', (t) => { + await test('object', async (t) => { + await t.test('should parse json string as an object', () => { const val = '{"key": "value"}' const result = formatters.object(val) - t.same(result, { key: 'value' }) - t.end() + assert.deepStrictEqual(result, { key: 'value' }) }) - t.test('should log error and return null if it cannot parse option as json', (t) => { + await t.test('should log error and return null if it cannot parse option as json', () => { const loggerMock = { error: sinon.stub() } const val = 'invalid' - t.notOk(formatters.object(val, loggerMock)) - t.equal(loggerMock.error.args[0][0], 'New Relic configurator could not deserialize object:') - t.match(loggerMock.error.args[1][0], /SyntaxError: Unexpected token/) - t.end() + assert.equal(formatters.object(val, loggerMock), null) + assert.equal( + loggerMock.error.args[0][0], + 'New Relic configurator could not deserialize object:' + ) + assert.match(loggerMock.error.args[1][0], /SyntaxError: Unexpected token/) }) }) - tap.test('objectList', (t) => { - t.autoend() - - t.test('should parse json string a collection with 1 object', (t) => { + await test('objectList', async (t) => { + await t.test('should parse json string a collection with 1 object', () => { const val = '{"key": "value"}' const result = formatters.objectList(val) - t.same(result, [{ key: 'value' }]) - t.end() + assert.deepStrictEqual(result, [{ key: 'value' }]) }) - t.test('should log error and return null if it cannot parse option as json', (t) => { + await t.test('should log error and return null if it cannot parse option as json', () => { const loggerMock = { error: sinon.stub() } const val = 'invalid' - t.notOk(formatters.objectList(val, loggerMock)) - t.equal( + assert.equal(formatters.objectList(val, loggerMock), null) + assert.equal( loggerMock.error.args[0][0], 'New Relic configurator could not deserialize object list:' ) - t.match(loggerMock.error.args[1][0], /SyntaxError: Unexpected token/) - t.end() + assert.match(loggerMock.error.args[1][0], /SyntaxError: Unexpected token/) }) }) - tap.test('allowList', (t) => { - t.autoend() - - t.test('should return value if in allow list', (t) => { + await test('allowList', async (t) => { + await t.test('should return value if in allow list', () => { const allowList = ['bad', 'good', 'evil'] const val = 'good' const result = formatters.allowList(allowList, val) - t.same(result, val) - t.end() + assert.deepStrictEqual(result, val) }) - t.test('should return first element in allow list if value is not in list', (t) => { + await t.test('should return first element in allow list if value is not in list', () => { const allowList = ['good', 'bad', 'evil'] const val = 'scary' const result = formatters.allowList(allowList, val) - t.same(result, 'good') - t.end() + assert.deepStrictEqual(result, 'good') }) }) - tap.test('regex', (t) => { - t.autoend() - - t.test('should return regex if valid', (t) => { + await test('regex', async (t) => { + await t.test('should return regex if valid', () => { const val = '/hello/' const result = formatters.regex(val) - t.same(result, /\/hello\//) - t.end() + assert.deepStrictEqual(result, /\/hello\//) }) - t.test('should log error and return null if regex is invalid', (t) => { + await t.test('should log error and return null if regex is invalid', () => { const loggerMock = { error: sinon.stub() } const val = '[a-z' - t.notOk(formatters.regex(val, loggerMock)) - t.equal(loggerMock.error.args[0][0], `New Relic configurator could not validate regex: [a-z`) - t.match(loggerMock.error.args[1][0], /SyntaxError: Invalid regular expression/) - t.end() + assert.equal(formatters.regex(val, loggerMock), null) + assert.equal( + loggerMock.error.args[0][0], + `New Relic configurator could not validate regex: [a-z` + ) + assert.match(loggerMock.error.args[1][0], /SyntaxError: Invalid regular expression/) }) }) }) diff --git a/test/unit/config/config-location.test.js b/test/unit/config/config-location.test.js index ae0ce87da8..39341effa5 100644 --- a/test/unit/config/config-location.test.js +++ b/test/unit/config/config-location.test.js @@ -5,7 +5,8 @@ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const path = require('path') const fs = require('fs') const fsPromises = require('fs/promises') @@ -14,9 +15,7 @@ const sinon = require('sinon') const { removeMatchedModules } = require('../../lib/cache-buster') const Config = require('../../../lib/config') -tap.test('when overriding the config file location via NEW_RELIC_HOME', (t) => { - t.autoend() - +test('when overriding the config file location via NEW_RELIC_HOME', async (t) => { const DESTDIR = path.join(__dirname, 'xXxNRHOMETESTxXx') const NOPLACEDIR = path.join(__dirname, 'NOHEREHERECHAMP') const CONFIGPATH = path.join(DESTDIR, 'newrelic.js') @@ -61,48 +60,41 @@ tap.test('when overriding the config file location via NEW_RELIC_HOME', (t) => { await fsPromises.rm(NOPLACEDIR, { recursive: true }) }) - t.test('should load the configuration', (t) => { - t.doesNotThrow(() => { + await t.test('should load the configuration', (t, end) => { + assert.doesNotThrow(() => { Config.initialize() + end() }) - - t.end() }) - t.test('should export the home directory on the resulting object', (t) => { + await t.test('should export the home directory on the resulting object', () => { const configuration = Config.initialize() - t.equal(configuration.newrelic_home, DESTDIR) - - t.end() + assert.equal(configuration.newrelic_home, DESTDIR) }) - t.test('should ignore the configuration file completely when so directed', (t) => { + await t.test('should ignore the configuration file completely when so directed', (t, end) => { process.env.NEW_RELIC_NO_CONFIG_FILE = 'true' process.env.NEW_RELIC_HOME = '/xxxnoexist/nofile' - t.teardown(() => { - delete process.env.NEW_RELIC_NO_CONFIG_FILE - delete process.env.NEW_RELIC_HOME - }) - let configuration - t.doesNotThrow(() => { + assert.doesNotThrow(() => { configuration = Config.initialize() }) - t.notOk(configuration.newrelic_home) - - t.ok(configuration.error_collector) - t.equal(configuration.error_collector.enabled, true) + assert.ok(!configuration.newrelic_home) + assert.ok(configuration.error_collector) + assert.equal(configuration.error_collector.enabled, true) + end() - t.end() + t.after(() => { + delete process.env.NEW_RELIC_NO_CONFIG_FILE + delete process.env.NEW_RELIC_HOME + }) }) }) -tap.test('Selecting config file path', (t) => { - t.autoend() - +test('Selecting config file path', async (t) => { const DESTDIR = path.join(__dirname, 'test_NEW_RELIC_CONFIG_FILENAME') const NOPLACEDIR = path.join(__dirname, 'test_NEW_RELIC_CONFIG_FILENAME_dummy') const MAIN_MODULE_DIR = path.join(__dirname, 'test_NEW_RELIC_CONFIG_FILENAME_MAIN_MODULE') @@ -157,56 +149,49 @@ tap.test('Selecting config file path', (t) => { removeMatchedModules(mainModuleRegex) }) - t.test('should load the default newrelic.js config file', (t) => { + await t.test('should load the default newrelic.js config file', () => { const filename = 'newrelic.js' createSampleConfig(DESTDIR, filename) const configuration = Config.initialize() - t.equal(configuration.app_name, filename) - - t.end() + assert.equal(configuration.app_name, filename) }) - t.test('should load the default newrelic.cjs config file', (t) => { + await t.test('should load the default newrelic.cjs config file', () => { const filename = 'newrelic.cjs' createSampleConfig(DESTDIR, filename) const configuration = Config.initialize() - t.equal(configuration.app_name, filename) - - t.end() + assert.equal(configuration.app_name, filename) }) - t.test('should load config when overriding the default with NEW_RELIC_CONFIG_FILENAME', (t) => { - const filename = 'some-file-name.js' - process.env.NEW_RELIC_CONFIG_FILENAME = filename - createSampleConfig(DESTDIR, filename) - - const configuration = Config.initialize() - t.equal(configuration.app_name, filename) + await t.test( + 'should load config when overriding the default with NEW_RELIC_CONFIG_FILENAME', + () => { + const filename = 'some-file-name.js' + process.env.NEW_RELIC_CONFIG_FILENAME = filename + createSampleConfig(DESTDIR, filename) - t.end() - }) + const configuration = Config.initialize() + assert.equal(configuration.app_name, filename) + } + ) - t.test("should load config from the main module's filepath", (t) => { + await t.test("should load config from the main module's filepath", () => { const filename = 'newrelic.js' createSampleConfig(MAIN_MODULE_DIR, filename) const configuration = Config.initialize() - t.equal(configuration.app_name, filename) - - t.end() + assert.equal(configuration.app_name, filename) }) - t.test('should load even if parsing the config file throws an error', (t) => { + await t.test('should load even if parsing the config file throws an error', () => { const filename = 'newrelic.js' createInvalidConfig(MAIN_MODULE_DIR, filename) process.env.NEW_RELIC_APP_NAME = filename const configuration = Config.initialize() - t.same(configuration.app_name, [filename]) - - t.end() + assert.deepStrictEqual(configuration.app_name, [filename]) }) function createSampleConfig(dir, filename) { diff --git a/test/unit/config/config-security.test.js b/test/unit/config/config-security.test.js index a24c0e7114..5ed52c2882 100644 --- a/test/unit/config/config-security.test.js +++ b/test/unit/config/config-security.test.js @@ -5,33 +5,31 @@ 'use strict' -const tap = require('tap') - +const test = require('node:test') +const assert = require('node:assert') const sinon = require('sinon') const Config = require('../../../lib/config') const securityPolicies = require('../../lib/fixtures').securityPolicies const { idempotentEnv } = require('./helper') -tap.test('should pick up the security policies token', (t) => { +test('should pick up the security policies token', (t, end) => { idempotentEnv({ NEW_RELIC_SECURITY_POLICIES_TOKEN: 'super secure' }, (tc) => { - t.ok(tc.security_policies_token) - t.equal(tc.security_policies_token, 'super secure') - t.end() + assert.ok(tc.security_policies_token) + assert.equal(tc.security_policies_token, 'super secure') + end() }) }) -tap.test('should throw with both high_security and security_policies_token defined', (t) => { - t.throws(function testInitialize() { +test('should throw with both high_security and security_policies_token defined', () => { + assert.throws(function testInitialize() { Config.initialize({ high_security: true, security_policies_token: 'fffff' }) }) - - t.end() }) -tap.test('should enable high security mode (HSM) with non-bool truthy HSM setting', (t) => { +test('should enable high security mode (HSM) with non-bool truthy HSM setting', () => { const applyHSM = Config.prototype._applyHighSecurity let hsmApplied = false @@ -42,17 +40,13 @@ tap.test('should enable high security mode (HSM) with non-bool truthy HSM settin high_security: 'true' }) - t.equal(!!config.high_security, true) - t.equal(hsmApplied, true) + assert.equal(!!config.high_security, true) + assert.equal(hsmApplied, true) Config.prototype._applyHighSecurity = applyHSM - - t.end() }) -tap.test('#_getMostSecure', (t) => { - t.autoend() - +test('#_getMostSecure', async (t) => { let config = null t.beforeEach(() => { @@ -60,28 +54,23 @@ tap.test('#_getMostSecure', (t) => { config.security_policies_token = 'TEST-TEST-TEST-TEST' }) - t.test('returns the new value if the current one is undefined', (t) => { + await t.test('returns the new value if the current one is undefined', () => { const val = config._getMostSecure('record_sql', undefined, 'off') - t.equal(val, 'off') - t.end() + assert.equal(val, 'off') }) - t.test('returns the most strict if it does not know either value', (t) => { + await t.test('returns the most strict if it does not know either value', () => { const val = config._getMostSecure('record_sql', undefined, 'dunno') - t.equal(val, 'off') - t.end() + assert.equal(val, 'off') }) - t.test('should work as a pass through for unknown config options', (t) => { + await t.test('should work as a pass through for unknown config options', () => { const val = config._getMostSecure('unknown.option', undefined, 'dunno') - t.equal(val, 'dunno') - t.end() + assert.equal(val, 'dunno') }) }) -tap.test('#applyLasp', (t) => { - t.autoend() - +test('#applyLasp', async (t) => { let config = null let policies = null let agent = null @@ -100,24 +89,22 @@ tap.test('#applyLasp', (t) => { policies = securityPolicies() }) - t.test('returns null if LASP is not enabled', (t) => { + await t.test('returns null if LASP is not enabled', () => { config.security_policies_token = '' const res = config.applyLasp(agent, {}) - t.equal(res.payload, null) - t.end() + assert.equal(res.payload, null) }) - t.test('returns fatal response if required policy is not implemented or unknown', (t) => { + await t.test('returns fatal response if required policy is not implemented or unknown', () => { policies.job_arguments = { enabled: true, required: true } policies.test = { enabled: true, required: true } const response = config.applyLasp(agent, policies) - t.equal(response.shouldShutdownRun(), true) - t.end() + assert.equal(response.shouldShutdownRun(), true) }) - t.test('takes the most secure from local', (t) => { + await t.test('takes the most secure from local', () => { config.transaction_tracer.record_sql = 'off' config.attributes.include_enabled = false config.strip_exception_messages.enabled = true @@ -131,23 +118,21 @@ tap.test('#applyLasp', (t) => { const response = config.applyLasp(agent, policies) const payload = response.payload - t.equal(config.transaction_tracer.record_sql, 'off') - t.equal(agent._resetQueries.callCount, 0) - t.equal(config.attributes.include_enabled, false) - t.equal(agent.traces.clear.callCount, 0) - t.equal(config.strip_exception_messages.enabled, true) - t.equal(agent._resetErrors.callCount, 0) - t.equal(config.api.custom_events_enabled, false) - t.equal(agent._resetCustomEvents.callCount, 0) - t.equal(config.api.custom_attributes_enabled, false) + assert.equal(config.transaction_tracer.record_sql, 'off') + assert.equal(agent._resetQueries.callCount, 0) + assert.equal(config.attributes.include_enabled, false) + assert.equal(agent.traces.clear.callCount, 0) + assert.equal(config.strip_exception_messages.enabled, true) + assert.equal(agent._resetErrors.callCount, 0) + assert.equal(config.api.custom_events_enabled, false) + assert.equal(agent._resetCustomEvents.callCount, 0) + assert.equal(config.api.custom_attributes_enabled, false) Object.keys(payload).forEach(function checkPolicy(key) { - t.equal(payload[key].enabled, false) + assert.equal(payload[key].enabled, false) }) - - t.end() }) - t.test('takes the most secure from lasp', (t) => { + await t.test('takes the most secure from lasp', () => { config.transaction_tracer.record_sql = 'obfuscated' config.attributes.include_enabled = true config.strip_exception_messages.enabled = false @@ -161,24 +146,22 @@ tap.test('#applyLasp', (t) => { const response = config.applyLasp(agent, policies) const payload = response.payload - t.equal(config.transaction_tracer.record_sql, 'off') - t.equal(agent._resetQueries.callCount, 1) - t.equal(config.attributes.include_enabled, false) - t.same(config.attributes.exclude, ['request.parameters.*']) - t.equal(config.strip_exception_messages.enabled, true) - t.equal(agent._resetErrors.callCount, 1) - t.equal(config.api.custom_events_enabled, false) - t.equal(agent._resetCustomEvents.callCount, 1) - t.equal(config.api.custom_attributes_enabled, false) - t.equal(agent.traces.clear.callCount, 1) + assert.equal(config.transaction_tracer.record_sql, 'off') + assert.equal(agent._resetQueries.callCount, 1) + assert.equal(config.attributes.include_enabled, false) + assert.deepStrictEqual(config.attributes.exclude, ['request.parameters.*']) + assert.equal(config.strip_exception_messages.enabled, true) + assert.equal(agent._resetErrors.callCount, 1) + assert.equal(config.api.custom_events_enabled, false) + assert.equal(agent._resetCustomEvents.callCount, 1) + assert.equal(config.api.custom_attributes_enabled, false) + assert.equal(agent.traces.clear.callCount, 1) Object.keys(payload).forEach(function checkPolicy(key) { - t.equal(payload[key].enabled, false) + assert.equal(payload[key].enabled, false) }) - - t.end() }) - t.test('allows permissive settings', (t) => { + await t.test('allows permissive settings', () => { config.transaction_tracer.record_sql = 'obfuscated' config.attributes.include_enabled = true config.strip_exception_messages.enabled = false @@ -192,42 +175,36 @@ tap.test('#applyLasp', (t) => { const response = config.applyLasp(agent, policies) const payload = response.payload - t.equal(config.transaction_tracer.record_sql, 'obfuscated') - t.equal(config.attributes.include_enabled, true) - t.equal(config.strip_exception_messages.enabled, false) - t.equal(config.api.custom_events_enabled, true) - t.equal(config.api.custom_attributes_enabled, true) + assert.equal(config.transaction_tracer.record_sql, 'obfuscated') + assert.equal(config.attributes.include_enabled, true) + assert.equal(config.strip_exception_messages.enabled, false) + assert.equal(config.api.custom_events_enabled, true) + assert.equal(config.api.custom_attributes_enabled, true) Object.keys(payload).forEach(function checkPolicy(key) { - t.equal(payload[key].enabled, true) + assert.equal(payload[key].enabled, true) }) - - t.end() }) - t.test('returns fatal response if expected policy is not received', (t) => { + await t.test('returns fatal response if expected policy is not received', () => { delete policies.record_sql const response = config.applyLasp(agent, policies) - t.equal(response.shouldShutdownRun(), true) - - t.end() + assert.equal(response.shouldShutdownRun(), true) }) - t.test('should return known policies', (t) => { + await t.test('should return known policies', () => { const response = config.applyLasp(agent, policies) - t.same(response.payload, { + assert.deepEqual(response.payload, { record_sql: { enabled: false, required: false }, attributes_include: { enabled: false, required: false }, allow_raw_exception_messages: { enabled: false, required: false }, custom_events: { enabled: false, required: false }, custom_parameters: { enabled: false, required: false } }) - - t.end() }) }) -tap.test('ai_monitoring should not be enabled in HSM', (t) => { +test('ai_monitoring should not be enabled in HSM', () => { const config = Config.initialize({ ai_monitoring: { enabled: true @@ -235,7 +212,5 @@ tap.test('ai_monitoring should not be enabled in HSM', (t) => { high_security: 'true' }) - t.equal(config.ai_monitoring.enabled, false) - - t.end() + assert.equal(config.ai_monitoring.enabled, false) }) diff --git a/test/unit/config/config-server-side.test.js b/test/unit/config/config-server-side.test.js index b527e7b51d..f7fb0f2df4 100644 --- a/test/unit/config/config-server-side.test.js +++ b/test/unit/config/config-server-side.test.js @@ -5,13 +5,11 @@ 'use strict' -const tap = require('tap') - +const test = require('node:test') +const assert = require('node:assert') const Config = require('../../../lib/config') -tap.test('when receiving server-side configuration', (t) => { - t.autoend() - +test('when receiving server-side configuration', async (t) => { // Unfortunately, the Config currently relies on initialize to // instantiate the logger in the module which is later leveraged // by methods on the instantiated Config instance. @@ -23,527 +21,418 @@ tap.test('when receiving server-side configuration', (t) => { config = new Config() }) - t.test('should set the agent run ID', (t) => { + await t.test('should set the agent run ID', () => { config.onConnect({ agent_run_id: 1234 }) - t.equal(config.run_id, 1234) - - t.end() + assert.equal(config.run_id, 1234) }) - t.test('should set the account ID', (t) => { + await t.test('should set the account ID', () => { config.onConnect({ account_id: 76543 }) - t.equal(config.account_id, 76543) - - t.end() + assert.equal(config.account_id, 76543) }) - t.test('should set the entity GUID', (t) => { + await t.test('should set the entity GUID', () => { config.onConnect({ entity_guid: 1729 }) - t.equal(config.entity_guid, 1729) - - t.end() + assert.equal(config.entity_guid, 1729) }) - t.test('should set the application ID', (t) => { + await t.test('should set the application ID', () => { config.onConnect({ application_id: 76543 }) - t.equal(config.application_id, 76543) - - t.end() + assert.equal(config.application_id, 76543) }) - t.test('should always respect collect_traces', (t) => { - t.equal(config.collect_traces, true) + await t.test('should always respect collect_traces', () => { + assert.equal(config.collect_traces, true) config.onConnect({ collect_traces: false }) - t.equal(config.collect_traces, false) - - t.end() + assert.equal(config.collect_traces, false) }) - t.test('should disable the transaction tracer when told to', (t) => { - t.equal(config.transaction_tracer.enabled, true) + await t.test('should disable the transaction tracer when told to', () => { + assert.equal(config.transaction_tracer.enabled, true) config.onConnect({ 'transaction_tracer.enabled': false }) - t.equal(config.transaction_tracer.enabled, false) - - t.end() + assert.equal(config.transaction_tracer.enabled, false) }) - t.test('should always respect collect_errors', (t) => { - t.equal(config.collect_errors, true) + await t.test('should always respect collect_errors', () => { + assert.equal(config.collect_errors, true) config.onConnect({ collect_errors: false }) - t.equal(config.collect_errors, false) - - t.end() + assert.equal(config.collect_errors, false) }) - t.test('should always respect collect_span_events', (t) => { - t.equal(config.collect_span_events, true) - t.equal(config.span_events.enabled, true) + await t.test('should always respect collect_span_events', () => { + assert.equal(config.collect_span_events, true) + assert.equal(config.span_events.enabled, true) config.onConnect({ collect_span_events: false }) - t.equal(config.span_events.enabled, false) - - t.end() + assert.equal(config.span_events.enabled, false) }) - t.test('should disable the error tracer when told to', (t) => { - t.equal(config.error_collector.enabled, true) + await t.test('should disable the error tracer when told to', () => { + assert.equal(config.error_collector.enabled, true) config.onConnect({ 'error_collector.enabled': false }) - t.equal(config.error_collector.enabled, false) - - t.end() + assert.equal(config.error_collector.enabled, false) }) - t.test('should set apdex_t', (t) => { - t.equal(config.apdex_t, 0.1) + await t.test('should set apdex_t', () => { + assert.equal(config.apdex_t, 0.1) config.on('apdex_t', (value) => { - t.equal(value, 0.05) - t.equal(config.apdex_t, 0.05) - - t.end() + assert.equal(value, 0.05) + assert.equal(config.apdex_t, 0.05) }) config.onConnect({ apdex_t: 0.05 }) }) - t.test('should map transaction_tracer.transaction_threshold', (t) => { - t.equal(config.transaction_tracer.transaction_threshold, 'apdex_f') + await t.test('should map transaction_tracer.transaction_threshold', () => { + assert.equal(config.transaction_tracer.transaction_threshold, 'apdex_f') config.onConnect({ 'transaction_tracer.transaction_threshold': 0.75 }) - t.equal(config.transaction_tracer.transaction_threshold, 0.75) - - t.end() + assert.equal(config.transaction_tracer.transaction_threshold, 0.75) }) - t.test('should map URL rules to the URL normalizer', (t) => { + await t.test('should map URL rules to the URL normalizer', () => { config.on('url_rules', function (rules) { - t.same(rules, [{ name: 'sample_rule' }]) - t.end() + assert.deepEqual(rules, [{ name: 'sample_rule' }]) }) config.onConnect({ url_rules: [{ name: 'sample_rule' }] }) }) - t.test('should map metric naming rules to the metric name normalizer', (t) => { + await t.test('should map metric naming rules to the metric name normalizer', () => { config.on('metric_name_rules', function (rules) { - t.same(rules, [{ name: 'sample_rule' }]) - t.end() + assert.deepEqual(rules, [{ name: 'sample_rule' }]) }) config.onConnect({ metric_name_rules: [{ name: 'sample_rule' }] }) }) - t.test('should map txn naming rules to the txn name normalizer', (t) => { + await t.test('should map txn naming rules to the txn name normalizer', () => { config.on('transaction_name_rules', function (rules) { - t.same(rules, [{ name: 'sample_rule' }]) - t.end() + assert.deepEqual(rules, [{ name: 'sample_rule' }]) }) config.onConnect({ transaction_name_rules: [{ name: 'sample_rule' }] }) }) - t.test('should log the product level', (t) => { - t.equal(config.product_level, 0) + await t.test('should log the product level', () => { + assert.equal(config.product_level, 0) config.onConnect({ product_level: 30 }) - t.equal(config.product_level, 30) - t.end() + assert.equal(config.product_level, 30) }) - t.test('should reject high_security', (t) => { + await t.test('should reject high_security', () => { config.onConnect({ high_security: true }) - t.equal(config.high_security, false) - - t.end() + assert.equal(config.high_security, false) }) - t.test('should disable ai monitoring', (t) => { + await t.test('should disable ai monitoring', () => { config.ai_monitoring.enabled = true - t.equal(config.ai_monitoring.enabled, true) + assert.equal(config.ai_monitoring.enabled, true) config.onConnect({ collect_ai: false }) - t.equal(config.ai_monitoring.enabled, false) - - t.end() + assert.equal(config.ai_monitoring.enabled, false) }) - t.test('should configure cross application tracing', (t) => { + await t.test('should configure cross application tracing', () => { config.cross_application_tracer.enabled = true config.onConnect({ 'cross_application_tracer.enabled': false }) - t.equal(config.cross_application_tracer.enabled, false) - - t.end() + assert.equal(config.cross_application_tracer.enabled, false) }) - t.test('should load named transaction apdexes', (t) => { + await t.test('should load named transaction apdexes', () => { const apdexes = { 'WebTransaction/Custom/UrlGenerator/en/betting/Football': 7.0 } - t.same(config.web_transactions_apdex, {}) + assert.deepEqual(config.web_transactions_apdex, {}) config.onConnect({ web_transactions_apdex: apdexes }) - t.same(config.web_transactions_apdex, apdexes) - - t.end() + assert.deepEqual(config.web_transactions_apdex, apdexes) }) - t.test('should not configure record_sql', (t) => { - t.equal(config.transaction_tracer.record_sql, 'obfuscated') + await t.test('should not configure record_sql', () => { + assert.equal(config.transaction_tracer.record_sql, 'obfuscated') config.onConnect({ 'transaction_tracer.record_sql': 'raw' }) - t.equal(config.transaction_tracer.record_sql, 'obfuscated') - - t.end() + assert.equal(config.transaction_tracer.record_sql, 'obfuscated') }) - t.test('should not configure explain_threshold', (t) => { - t.equal(config.transaction_tracer.explain_threshold, 500) + await t.test('should not configure explain_threshold', () => { + assert.equal(config.transaction_tracer.explain_threshold, 500) config.onConnect({ 'transaction_tracer.explain_threshold': 100 }) - t.equal(config.transaction_tracer.explain_threshold, 500) - - t.end() + assert.equal(config.transaction_tracer.explain_threshold, 500) }) - t.test('should not configure slow_sql.enabled', (t) => { - t.equal(config.slow_sql.enabled, false) + await t.test('should not configure slow_sql.enabled', () => { + assert.equal(config.slow_sql.enabled, false) config.onConnect({ 'transaction_tracer.enabled': true }) - t.equal(config.slow_sql.enabled, false) - - t.end() + assert.equal(config.slow_sql.enabled, false) }) - t.test('should not configure slow_sql.max_samples', (t) => { - t.equal(config.slow_sql.max_samples, 10) + await t.test('should not configure slow_sql.max_samples', () => { + assert.equal(config.slow_sql.max_samples, 10) config.onConnect({ 'transaction_tracer.max_samples': 5 }) - t.equal(config.slow_sql.max_samples, 10) - - t.end() + assert.equal(config.slow_sql.max_samples, 10) }) - t.test('should not blow up when sampling_rate is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when sampling_rate is received', () => { + assert.doesNotThrow(() => { config.onConnect({ sampling_rate: 0 }) }) - - t.end() }) - t.test('should not blow up when cross_process_id is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when cross_process_id is received', () => { + assert.doesNotThrow(() => { config.onConnect({ cross_process_id: 'junk' }) }) - - t.end() }) - t.test('should not blow up with cross_application_tracer.enabled', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up with cross_application_tracer.enabled', () => { + assert.doesNotThrow(() => { config.onConnect({ 'cross_application_tracer.enabled': true }) }) - - t.end() }) - t.test('should not blow up when encoding_key is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when encoding_key is received', () => { + assert.doesNotThrow(() => { config.onConnect({ encoding_key: 'hamsnadwich' }) }) - - t.end() }) - t.test('should not blow up when trusted_account_ids is received', (t) => { + await t.test('should not blow up when trusted_account_ids is received', () => { config.once('trusted_account_ids', (value) => { - t.same(value, [1, 2, 3], 'should get the initial keys') + assert.deepEqual(value, [1, 2, 3], 'should get the initial keys') }) - t.doesNotThrow(() => { + assert.doesNotThrow(() => { config.onConnect({ trusted_account_ids: [1, 2, 3] }) }, 'should allow it once') config.once('trusted_account_ids', (value) => { - t.same(value, [2, 3, 4], 'should get the modified keys') + assert.deepEqual(value, [2, 3, 4], 'should get the modified keys') }) - t.doesNotThrow(() => { + assert.doesNotThrow(() => { config.onConnect({ trusted_account_ids: [2, 3, 4] }) }, 'should allow modification') - - t.end() }) - t.test('should not blow up when trusted_account_key is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when trusted_account_key is received', () => { + assert.doesNotThrow(() => { config.onConnect({ trusted_account_key: 123 }) }) - - t.end() }) - t.test('should not blow up when high_security is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when high_security is received', () => { + assert.doesNotThrow(() => { config.onConnect({ high_security: true }) }) - - t.end() }) - t.test('should not blow up when ssl is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when ssl is received', () => { + assert.doesNotThrow(() => { config.onConnect({ ssl: true }) }) - - t.end() }) - t.test('should not disable ssl', (t) => { - t.doesNotThrow(() => { + await t.test('should not disable ssl', () => { + assert.doesNotThrow(() => { config.onConnect({ ssl: false }) }) - t.equal(config.ssl, true) - - t.end() + assert.equal(config.ssl, true) }) - t.test('should not blow up when transaction_tracer.record_sql is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when transaction_tracer.record_sql is received', () => { + assert.doesNotThrow(() => { config.onConnect({ 'transaction_tracer.record_sql': true }) }) - - t.end() }) - t.test('should not blow up when slow_sql.enabled is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when slow_sql.enabled is received', () => { + assert.doesNotThrow(() => { config.onConnect({ 'slow_sql.enabled': true }) }) - - t.end() }) - t.test('should not blow up when rum.load_episodes_file is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when rum.load_episodes_file is received', () => { + assert.doesNotThrow(() => { config.onConnect({ 'rum.load_episodes_file': true }) }) - - t.end() }) - t.test('should not blow up when browser_monitoring.loader is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when browser_monitoring.loader is received', () => { + assert.doesNotThrow(() => { config.onConnect({ 'browser_monitoring.loader': 'none' }) }) - - t.end() }) - t.test('should not blow up when beacon is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when beacon is received', () => { + assert.doesNotThrow(() => { config.onConnect({ beacon: 'beacon-0.newrelic.com' }) }) - - t.end() }) - t.test('should not blow up when error beacon is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when error beacon is received', () => { + assert.doesNotThrow(() => { config.onConnect({ error_beacon: null }) }) - - t.end() }) - t.test('should not blow up when js_agent_file is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when js_agent_file is received', () => { + assert.doesNotThrow(() => { config.onConnect({ js_agent_file: 'jxc4afffef.js' }) }) - - t.end() }) - t.test('should not blow up when js_agent_loader_file is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when js_agent_loader_file is received', () => { + assert.doesNotThrow(() => { config.onConnect({ js_agent_loader_file: 'nr-js-bootstrap.js' }) }) - - t.end() }) - t.test('should not blow up when episodes_file is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when episodes_file is received', () => { + assert.doesNotThrow(() => { config.onConnect({ episodes_file: 'js-agent.newrelic.com/nr-100.js' }) }) - - t.end() }) - t.test('should not blow up when episodes_url is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when episodes_url is received', () => { + assert.doesNotThrow(() => { config.onConnect({ episodes_url: 'https://js-agent.newrelic.com/nr-100.js' }) }) - - t.end() }) - t.test('should not blow up when browser_key is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when browser_key is received', () => { + assert.doesNotThrow(() => { config.onConnect({ browser_key: 'beefchunx' }) }) - - t.end() }) - t.test('should not blow up when collect_analytics_events is received', (t) => { + await t.test('should not blow up when collect_analytics_events is received', () => { config.transaction_events.enabled = true - t.doesNotThrow(() => { + assert.doesNotThrow(() => { config.onConnect({ collect_analytics_events: false }) }) - t.equal(config.transaction_events.enabled, false) - - t.end() + assert.equal(config.transaction_events.enabled, false) }) - t.test('should not blow up when collect_custom_events is received', (t) => { + await t.test('should not blow up when collect_custom_events is received', () => { config.custom_insights_events.enabled = true - t.doesNotThrow(() => { + assert.doesNotThrow(() => { config.onConnect({ collect_custom_events: false }) }) - t.equal(config.custom_insights_events.enabled, false) - - t.end() + assert.equal(config.custom_insights_events.enabled, false) }) - t.test('should not blow up when transaction_events.enabled is received', (t) => { - t.doesNotThrow(() => { + await t.test('should not blow up when transaction_events.enabled is received', () => { + assert.doesNotThrow(() => { config.onConnect({ 'transaction_events.enabled': false }) }) - t.equal(config.transaction_events.enabled, false) - - t.end() + assert.equal(config.transaction_events.enabled, false) }) - t.test('should override default max_payload_size_in_bytes', (t) => { - t.doesNotThrow(() => { + await t.test('should override default max_payload_size_in_bytes', () => { + assert.doesNotThrow(() => { config.onConnect({ max_payload_size_in_bytes: 100 }) }) - t.equal(config.max_payload_size_in_bytes, 100) - - t.end() + assert.equal(config.max_payload_size_in_bytes, 100) }) - t.test('should not accept serverless_mode', (t) => { - t.doesNotThrow(() => { + await t.test('should not accept serverless_mode', () => { + assert.doesNotThrow(() => { config.onConnect({ 'serverless_mode.enabled': true }) }) - t.equal(config.serverless_mode.enabled, false) - - t.end() + assert.equal(config.serverless_mode.enabled, false) }) - t.test('when handling embedded agent_config', (t) => { - t.autoend() - - t.test('should not blow up when agent_config is passed in', (t) => { - t.doesNotThrow(() => { + await t.test('when handling embedded agent_config', async (t) => { + await t.test('should not blow up when agent_config is passed in', () => { + assert.doesNotThrow(() => { config.onConnect({ agent_config: {} }) }) - - t.end() }) - t.test('should ignore status codes set on the server', (t) => { + await t.test('should ignore status codes set on the server', () => { config.onConnect({ agent_config: { 'error_collector.ignore_status_codes': [401, 409, 415] } }) - t.same(config.error_collector.ignore_status_codes, [404, 401, 409, 415]) - - t.end() + assert.deepEqual(config.error_collector.ignore_status_codes, [404, 401, 409, 415]) }) - t.test('should ignore status codes set on the server as strings', (t) => { + await t.test('should ignore status codes set on the server as strings', () => { config.onConnect({ agent_config: { 'error_collector.ignore_status_codes': ['401', '409', '415'] } }) - t.same(config.error_collector.ignore_status_codes, [404, 401, 409, 415]) - - t.end() + assert.deepEqual(config.error_collector.ignore_status_codes, [404, 401, 409, 415]) }) - t.test('should ignore status codes set on the server when using a range', (t) => { + await t.test('should ignore status codes set on the server when using a range', () => { config.onConnect({ agent_config: { 'error_collector.ignore_status_codes': [401, '420-421', 415, 'abc'] } }) - t.same(config.error_collector.ignore_status_codes, [404, 401, 420, 421, 415]) - - t.end() + assert.deepEqual(config.error_collector.ignore_status_codes, [404, 401, 420, 421, 415]) }) - t.test('should not error out when ignore status codes are neither numbers nor strings', (t) => { - config.onConnect({ - agent_config: { - 'error_collector.ignore_status_codes': [{ non: 'sense' }] - } - }) - t.same(config.error_collector.ignore_status_codes, [404]) - - t.end() - }) + await t.test( + 'should not error out when ignore status codes are neither numbers nor strings', + () => { + config.onConnect({ + agent_config: { + 'error_collector.ignore_status_codes': [{ non: 'sense' }] + } + }) + assert.deepEqual(config.error_collector.ignore_status_codes, [404]) + } + ) - t.test('should not add codes that parse to NaN', (t) => { + await t.test('should not add codes that parse to NaN', () => { config.onConnect({ agent_config: { 'error_collector.ignore_status_codes': ['abc'] } }) - t.same(config.error_collector.ignore_status_codes, [404]) - - t.end() + assert.deepEqual(config.error_collector.ignore_status_codes, [404]) }) - t.test('should not ignore status codes from server with invalid range', (t) => { + await t.test('should not ignore status codes from server with invalid range', () => { config.onConnect({ agent_config: { 'error_collector.ignore_status_codes': ['421-420'] } }) - t.same(config.error_collector.ignore_status_codes, [404]) - - t.end() + assert.deepEqual(config.error_collector.ignore_status_codes, [404]) }) - t.test('should not ignore status codes from server if given out of range', (t) => { + await t.test('should not ignore status codes from server if given out of range', () => { config.onConnect({ agent_config: { 'error_collector.ignore_status_codes': ['1-1776'] } }) - t.same(config.error_collector.ignore_status_codes, [404]) - - t.end() + assert.deepEqual(config.error_collector.ignore_status_codes, [404]) }) - t.test('should ignore negative status codes from server', (t) => { + await t.test('should ignore negative status codes from server', () => { config.onConnect({ agent_config: { 'error_collector.ignore_status_codes': [-7] } }) - t.same(config.error_collector.ignore_status_codes, [404, -7]) - - t.end() + assert.deepEqual(config.error_collector.ignore_status_codes, [404, -7]) }) - t.test('should set `span_event_harvest_config` from server', (t) => { + await t.test('should set `span_event_harvest_config` from server', () => { const spanEventHarvestConfig = { report_period_ms: 1000, harvest_limit: 10000 @@ -554,19 +443,18 @@ tap.test('when receiving server-side configuration', (t) => { } }) - t.same(config.span_event_harvest_config, spanEventHarvestConfig) - t.end() + assert.deepEqual(config.span_event_harvest_config, spanEventHarvestConfig) }) const ignoreServerConfigFlags = [true, false] - ignoreServerConfigFlags.forEach((ignoreServerConfig) => { - t.test( + for (const ignoreServerConfig of ignoreServerConfigFlags) { + await t.test( `should ${ ignoreServerConfig ? 'not ' : '' }update local configuration with server side config values when ignore_server_configuration is set to ${ignoreServerConfig}`, - (t) => { - t.equal(config.slow_sql.enabled, false) - t.equal(config.transaction_tracer.enabled, true) + () => { + assert.equal(config.slow_sql.enabled, false) + assert.equal(config.transaction_tracer.enabled, true) const serverSideConfig = { 'slow_sql.enabled': true, 'transaction_tracer.enabled': false @@ -579,24 +467,20 @@ tap.test('when receiving server-side configuration', (t) => { // should stay same if `ignore_server_configuration` is true if (ignoreServerConfig) { - t.equal(config.slow_sql.enabled, false) - t.equal(config.transaction_tracer.enabled, true) + assert.equal(config.slow_sql.enabled, false) + assert.equal(config.transaction_tracer.enabled, true) // should use updated value if `ignore_server_configuration` is false } else { - t.equal(config.slow_sql.enabled, true) - t.equal(config.transaction_tracer.enabled, false) + assert.equal(config.slow_sql.enabled, true) + assert.equal(config.transaction_tracer.enabled, false) } - - t.end() } ) - }) + } }) - t.test('when event_harvest_config is set', (t) => { - t.autoend() - - t.test('should emit event_harvest_config when harvest interval is changed', (t) => { + await t.test('when event_harvest_config is set', async (t) => { + await t.test('should emit event_harvest_config when harvest interval is changed', () => { const expectedHarvestConfig = { report_period_ms: 5000, harvest_limits: { @@ -607,15 +491,13 @@ tap.test('when receiving server-side configuration', (t) => { } config.once('event_harvest_config', function (harvestconfig) { - t.same(harvestconfig, expectedHarvestConfig) - - t.end() + assert.deepEqual(harvestconfig, expectedHarvestConfig) }) config.onConnect({ event_harvest_config: expectedHarvestConfig }) }) - t.test('should emit null when an invalid report period is provided', (t) => { + await t.test('should emit null when an invalid report period is provided', () => { const invalidHarvestConfig = { report_period_ms: -1, harvest_limits: { @@ -626,15 +508,13 @@ tap.test('when receiving server-side configuration', (t) => { } config.once('event_harvest_config', function (harvestconfig) { - t.same(harvestconfig, null, 'emitted value should be null') - - t.end() + assert.deepEqual(harvestconfig, null, 'emitted value should be null') }) config.onConnect({ event_harvest_config: invalidHarvestConfig }) }) - t.test('should update event_harvest_config when a sub-value changed', (t) => { + await t.test('should update event_harvest_config when a sub-value changed', () => { const originalHarvestConfig = { report_period_ms: 60000, harvest_limits: { @@ -656,15 +536,13 @@ tap.test('when receiving server-side configuration', (t) => { } config.once('event_harvest_config', function (harvestconfig) { - t.same(harvestconfig, expectedHarvestConfig) - - t.end() + assert.deepEqual(harvestconfig, expectedHarvestConfig) }) config.onConnect({ event_harvest_config: expectedHarvestConfig }) }) - t.test('should ignore invalid limits on event_harvest_config', (t) => { + await t.test('should ignore invalid limits on event_harvest_config', () => { const originalHarvestConfig = { report_period_ms: 60000, harvest_limits: { @@ -693,38 +571,30 @@ tap.test('when receiving server-side configuration', (t) => { } config.once('event_harvest_config', function (harvestconfig) { - t.same(harvestconfig, cleanedHarvestLimits, 'should not include invalid limits') - - t.end() + assert.deepEqual(harvestconfig, cleanedHarvestLimits, 'should not include invalid limits') }) config.onConnect({ event_harvest_config: invalidHarvestLimits }) }) }) - t.test('when apdex_t is set', (t) => { - t.autoend() - - t.test('should emit `apdex_t` when apdex_t changes', (t) => { + await t.test('when apdex_t is set', async (t) => { + await t.test('should emit `apdex_t` when apdex_t changes', () => { config.once('apdex_t', function (apdexT) { - t.equal(apdexT, 0.75) - - t.end() + assert.equal(apdexT, 0.75) }) config.onConnect({ apdex_t: 0.75 }) }) - t.test('should update its apdex_t only when it has changed', (t) => { - t.equal(config.apdex_t, 0.1) + await t.test('should update its apdex_t only when it has changed', () => { + assert.equal(config.apdex_t, 0.1) config.once('apdex_t', function () { throw new Error('should never get here') }) config.onConnect({ apdex_t: 0.1 }) - - t.end() }) }) }) diff --git a/test/unit/config/config-serverless.test.js b/test/unit/config/config-serverless.test.js index 04853c411e..63235039fc 100644 --- a/test/unit/config/config-serverless.test.js +++ b/test/unit/config/config-serverless.test.js @@ -5,39 +5,35 @@ 'use strict' -const tap = require('tap') - +const test = require('node:test') +const assert = require('node:assert') const Config = require('../../../lib/config') const { idempotentEnv } = require('./helper') const VALID_HOST = 'infinite-tracing.test' const VALID_PORT = '443' -tap.test('should be true when config true', (t) => { +test('should be true when config true', () => { const conf = Config.initialize({ serverless_mode: { enabled: true } }) - t.equal(conf.serverless_mode.enabled, true) - t.end() + assert.equal(conf.serverless_mode.enabled, true) }) -tap.test('serverless_mode via configuration input', (t) => { - t.autoend() - - t.test('should explicitly disable cross_application_tracer', (t) => { +test('serverless_mode via configuration input', async (t) => { + await t.test('should explicitly disable cross_application_tracer', () => { const config = Config.initialize({ cross_application_tracer: { enabled: true }, serverless_mode: { enabled: true } }) - t.equal(config.cross_application_tracer.enabled, false) - t.end() + assert.equal(config.cross_application_tracer.enabled, false) }) - t.test('should explicitly disable infinite tracing', (t) => { + await t.test('should explicitly disable infinite tracing', () => { const config = Config.initialize({ serverless_mode: { enabled: true }, infinite_tracing: { @@ -48,13 +44,12 @@ tap.test('serverless_mode via configuration input', (t) => { } }) - t.equal(config.infinite_tracing.trace_observer.host, '') - t.end() + assert.equal(config.infinite_tracing.trace_observer.host, '') }) - t.test( + await t.test( 'should explicitly disable native_metrics when serverless mode disabled explicitly', - (t) => { + () => { const config = Config.initialize({ serverless_mode: { enabled: false @@ -63,32 +58,29 @@ tap.test('serverless_mode via configuration input', (t) => { native_metrics: { enabled: false } } }) - t.equal(config.plugins.native_metrics.enabled, false) - t.end() + assert.equal(config.plugins.native_metrics.enabled, false) } ) - t.test('should enable native_metrics when serverless mode disabled explicitly', (t) => { + await t.test('should enable native_metrics when serverless mode disabled explicitly', () => { const config = Config.initialize({ serverless_mode: { enabled: false } }) - t.equal(config.plugins.native_metrics.enabled, true) - t.end() + assert.equal(config.plugins.native_metrics.enabled, true) }) - t.test('should disable native_metrics when serverless mode enabled explicitly', (t) => { + await t.test('should disable native_metrics when serverless mode enabled explicitly', () => { const config = Config.initialize({ serverless_mode: { enabled: true } }) - t.equal(config.plugins.native_metrics.enabled, false) - t.end() + assert.equal(config.plugins.native_metrics.enabled, false) }) - t.test('should enable native_metrics when both enabled explicitly', (t) => { + await t.test('should enable native_metrics when both enabled explicitly', () => { const config = Config.initialize({ serverless_mode: { enabled: true }, plugins: { @@ -96,55 +88,49 @@ tap.test('serverless_mode via configuration input', (t) => { } }) - t.equal(config.plugins.native_metrics.enabled, true) - t.end() + assert.equal(config.plugins.native_metrics.enabled, true) }) - t.test('should set DT config settings while in serverless_mode', (t) => { + await t.test('should set DT config settings while in serverless_mode', () => { const config = Config.initialize({ account_id: '1234', primary_application_id: '2345', serverless_mode: { enabled: true } }) - t.equal(config.account_id, '1234') - t.equal(config.trusted_account_key, '1234') - t.end() + assert.equal(config.account_id, '1234') + assert.equal(config.trusted_account_key, '1234') }) - t.test('should not set DT config settings while not in serverless_mode', (t) => { + await t.test('should not set DT config settings while not in serverless_mode', () => { const config = Config.initialize({ account_id: '1234', primary_application_id: '2345', trusted_account_key: '3456' }) - t.equal(config.account_id, null) - t.equal(config.primary_application_id, null) - t.equal(config.trusted_account_key, null) - - t.end() + assert.equal(config.account_id, null) + assert.equal(config.primary_application_id, null) + assert.equal(config.trusted_account_key, null) }) - t.test('should default logging to disabled', (t) => { + await t.test('should default logging to disabled', () => { const config = Config.initialize({ serverless_mode: { enabled: true } }) - t.equal(config.logging.enabled, false) - t.end() + assert.equal(config.logging.enabled, false) }) - t.test('should allow logging to be enabled from configuration input', (t) => { + await t.test('should allow logging to be enabled from configuration input', () => { const config = Config.initialize({ serverless_mode: { enabled: true }, logging: { enabled: true } }) - t.equal(config.logging.enabled, true) - t.end() + assert.equal(config.logging.enabled, true) }) - t.test('should allow logging to be enabled from env ', (t) => { + await t.test('should allow logging to be enabled from env ', (t, end) => { const inputConfig = { serverless_mode: { enabled: true } } @@ -154,96 +140,99 @@ tap.test('serverless_mode via configuration input', (t) => { } idempotentEnv(envVariables, inputConfig, (config) => { - t.equal(config.logging.enabled, true) - t.end() + assert.equal(config.logging.enabled, true) + end() }) }) }) -tap.test('serverless mode via ENV variables', (t) => { - t.autoend() - - t.test('should pick up serverless_mode', (t) => { +test('serverless mode via ENV variables', async (t) => { + await t.test('should pick up serverless_mode', (t, end) => { idempotentEnv( { NEW_RELIC_SERVERLESS_MODE_ENABLED: true }, (tc) => { - t.equal(tc.serverless_mode.enabled, true) - t.end() + assert.equal(tc.serverless_mode.enabled, true) + end() } ) }) - t.test('should pick up trusted_account_key', (t) => { + await t.test('should pick up trusted_account_key', (t, end) => { idempotentEnv( { NEW_RELIC_SERVERLESS_MODE_ENABLED: true, NEW_RELIC_TRUSTED_ACCOUNT_KEY: '1234' }, (tc) => { - t.equal(tc.trusted_account_key, '1234') - t.end() + assert.equal(tc.trusted_account_key, '1234') + end() } ) }) - t.test('should pick up primary_application_id', (t) => { + await t.test('should pick up primary_application_id', (t, end) => { idempotentEnv( { NEW_RELIC_SERVERLESS_MODE_ENABLED: true, NEW_RELIC_PRIMARY_APPLICATION_ID: '5678' }, (tc) => { - t.equal(tc.primary_application_id, '5678') - t.end() + assert.equal(tc.primary_application_id, '5678') + end() } ) }) - t.test('should pick up account_id', (t) => { + await t.test('should pick up account_id', (t, end) => { idempotentEnv( { NEW_RELIC_SERVERLESS_MODE_ENABLED: true, NEW_RELIC_ACCOUNT_ID: '91011' }, (tc) => { - t.equal(tc.account_id, '91011') - t.end() + assert.equal(tc.account_id, '91011') + end() } ) }) - t.test('should clear serverless_mode DT config options when serverless_mode disabled', (t) => { - const env = { - NEW_RELIC_TRUSTED_ACCOUNT_KEY: 'defined', - NEW_RELIC_ACCOUNT_ID: 'defined', - NEW_RELIC_PRIMARY_APPLICATION_ID: 'defined', - NEW_RELIC_DISTRIBUTED_TRACING_ENABLED: true + await t.test( + 'should clear serverless_mode DT config options when serverless_mode disabled', + (t, end) => { + const env = { + NEW_RELIC_TRUSTED_ACCOUNT_KEY: 'defined', + NEW_RELIC_ACCOUNT_ID: 'defined', + NEW_RELIC_PRIMARY_APPLICATION_ID: 'defined', + NEW_RELIC_DISTRIBUTED_TRACING_ENABLED: true + } + idempotentEnv(env, (tc) => { + assert.equal(tc.primary_application_id, null) + assert.equal(tc.account_id, null) + assert.equal(tc.trusted_account_key, null) + end() + }) } - idempotentEnv(env, (tc) => { - t.equal(tc.primary_application_id, null) - t.equal(tc.account_id, null) - t.equal(tc.trusted_account_key, null) - - t.end() - }) - }) + ) - t.test('should explicitly disable cross_application_tracer in serverless_mode', (t) => { - idempotentEnv( - { - NEW_RELIC_SERVERLESS_MODE_ENABLED: true - }, - (tc) => { - t.equal(tc.serverless_mode.enabled, true) - t.equal(tc.cross_application_tracer.enabled, false) - t.end() - } - ) - }) + await t.test( + 'should explicitly disable cross_application_tracer in serverless_mode', + (t, end) => { + idempotentEnv( + { + NEW_RELIC_SERVERLESS_MODE_ENABLED: true + }, + (tc) => { + assert.equal(tc.serverless_mode.enabled, true) + assert.equal(tc.cross_application_tracer.enabled, false) + end() + } + ) + } + ) - t.test('should allow distributed tracing to be enabled from env', (t) => { + await t.test('should allow distributed tracing to be enabled from env', (t, end) => { idempotentEnv( { NEW_RELIC_SERVERLESS_MODE_ENABLED: true, @@ -251,13 +240,13 @@ tap.test('serverless mode via ENV variables', (t) => { NEW_RELIC_ACCOUNT_ID: '12345' }, (config) => { - t.equal(config.distributed_tracing.enabled, true) - t.end() + assert.equal(config.distributed_tracing.enabled, true) + end() } ) }) - t.test('should allow distributed tracing to be enabled from configuration ', (t) => { + await t.test('should allow distributed tracing to be enabled from configuration ', (t, end) => { const envVariables = { NEW_RELIC_SERVERLESS_MODE_ENABLED: true, NEW_RELIC_ACCOUNT_ID: '12345' @@ -268,115 +257,119 @@ tap.test('serverless mode via ENV variables', (t) => { } idempotentEnv(envVariables, inputConfig, (config) => { - t.equal(config.distributed_tracing.enabled, true) - t.end() + assert.equal(config.distributed_tracing.enabled, true) + end() }) }) - t.test('should enable DT in serverless_mode when account_id has been set', (t) => { + await t.test('should enable DT in serverless_mode when account_id has been set', (t, end) => { idempotentEnv( { NEW_RELIC_SERVERLESS_MODE_ENABLED: true, NEW_RELIC_ACCOUNT_ID: '12345' }, (tc) => { - t.equal(tc.serverless_mode.enabled, true) - t.equal(tc.distributed_tracing.enabled, true) - t.end() + assert.equal(tc.serverless_mode.enabled, true) + assert.equal(tc.distributed_tracing.enabled, true) + end() } ) }) - t.test('should not enable distributed tracing when account_id has not been set', (t) => { - idempotentEnv( - { - NEW_RELIC_SERVERLESS_MODE_ENABLED: true - }, - (tc) => { - t.equal(tc.serverless_mode.enabled, true) - t.equal(tc.distributed_tracing.enabled, false) - t.end() - } - ) - }) + await t.test( + 'should not enable distributed tracing when account_id has not been set', + (t, end) => { + idempotentEnv( + { + NEW_RELIC_SERVERLESS_MODE_ENABLED: true + }, + (tc) => { + assert.equal(tc.serverless_mode.enabled, true) + assert.equal(tc.distributed_tracing.enabled, false) + end() + } + ) + } + ) - t.test('should default primary_application_id to Unknown when not set', (t) => { + await t.test('should default primary_application_id to Unknown when not set', (t, end) => { idempotentEnv( { NEW_RELIC_SERVERLESS_MODE_ENABLED: true, NEW_RELIC_ACCOUNT_ID: '12345' }, (tc) => { - t.equal(tc.serverless_mode.enabled, true) - t.equal(tc.distributed_tracing.enabled, true) - - t.equal(tc.primary_application_id, 'Unknown') - t.end() + assert.equal(tc.serverless_mode.enabled, true) + assert.equal(tc.distributed_tracing.enabled, true) + assert.equal(tc.primary_application_id, 'Unknown') + end() } ) }) - t.test('should set serverless_mode from lambda-specific env var if not set by user', (t) => { - idempotentEnv( - { - AWS_LAMBDA_FUNCTION_NAME: 'someFunc' - }, - (tc) => { - t.equal(tc.serverless_mode.enabled, true) - t.end() - } - ) - }) + await t.test( + 'should set serverless_mode from lambda-specific env var if not set by user', + (t, end) => { + idempotentEnv( + { + AWS_LAMBDA_FUNCTION_NAME: 'someFunc' + }, + (tc) => { + assert.equal(tc.serverless_mode.enabled, true) + end() + } + ) + } + ) - t.test('should pick app name from AWS_LAMBDA_FUNCTION_NAME', (t) => { + await t.test('should pick app name from AWS_LAMBDA_FUNCTION_NAME', (t, end) => { idempotentEnv( { NEW_RELIC_SERVERLESS_MODE_ENABLED: true, AWS_LAMBDA_FUNCTION_NAME: 'MyLambdaFunc' }, (tc) => { - t.ok(tc.app_name) - t.same(tc.applications(), ['MyLambdaFunc']) - t.end() + assert.ok(tc.app_name) + assert.deepEqual(tc.applications(), ['MyLambdaFunc']) + end() } ) }) - t.test('should default generic app name when no AWS_LAMBDA_FUNCTION_NAME', (t) => { + await t.test('should default generic app name when no AWS_LAMBDA_FUNCTION_NAME', (t, end) => { idempotentEnv({ NEW_RELIC_SERVERLESS_MODE_ENABLED: true }, (tc) => { - t.ok(tc.app_name) - t.same(tc.applications(), ['Serverless Application']) - - t.end() + assert.ok(tc.app_name) + assert.deepEqual(tc.applications(), ['Serverless Application']) + end() }) }) - t.test('should default logging to disabled', (t) => { + await t.test('should default logging to disabled', (t, end) => { idempotentEnv( { NEW_RELIC_SERVERLESS_MODE_ENABLED: true }, (config) => { - t.equal(config.logging.enabled, false) - t.end() + assert.equal(config.logging.enabled, false) + end() } ) }) - t.test('should allow logging to be enabled from env', (t) => { + await t.test('should allow logging to be enabled from env', (t, end) => { idempotentEnv( { NEW_RELIC_SERVERLESS_MODE_ENABLED: true, NEW_RELIC_LOG_ENABLED: true }, (config) => { - t.equal(config.logging.enabled, true) - t.end() + assert.equal(config.logging.enabled, true) + end() } ) }) - t.test('should allow logging to be enabled from configuration ', (t) => { + await t.test('should allow logging to be enabled from configuration ', (t, end) => { const envVariables = { NEW_RELIC_SERVERLESS_MODE_ENABLED: true } @@ -386,12 +379,12 @@ tap.test('serverless mode via ENV variables', (t) => { } idempotentEnv(envVariables, inputConfig, (config) => { - t.equal(config.logging.enabled, true) - t.end() + assert.equal(config.logging.enabled, true) + end() }) }) - t.test('should enable native_metrics via env variable', (t) => { + await t.test('should enable native_metrics via env variable', (t, end) => { const envVariables = { NEW_RELIC_SERVERLESS_MODE_ENABLED: true, NEW_RELIC_NATIVE_METRICS_ENABLED: true @@ -406,16 +399,14 @@ tap.test('serverless mode via ENV variables', (t) => { } idempotentEnv(envVariables, inputConfig, (config) => { - t.equal(config.plugins.native_metrics.enabled, true) - t.end() + assert.equal(config.plugins.native_metrics.enabled, true) + end() }) }) }) -tap.test('when distributed_tracing manually set in serverless_mode', (t) => { - t.autoend() - - t.test('disables DT if missing required account_id', (t) => { +test('when distributed_tracing manually set in serverless_mode', async (t) => { + await t.test('disables DT if missing required account_id', () => { const config = Config.initialize({ distributed_tracing: { enabled: true }, serverless_mode: { @@ -423,22 +414,20 @@ tap.test('when distributed_tracing manually set in serverless_mode', (t) => { }, account_id: null }) - t.equal(config.distributed_tracing.enabled, false) - t.end() + assert.equal(config.distributed_tracing.enabled, false) }) - t.test('disables DT when DT set to false', (t) => { + await t.test('disables DT when DT set to false', () => { const config = Config.initialize({ distributed_tracing: { enabled: false }, serverless_mode: { enabled: true } }) - t.equal(config.distributed_tracing.enabled, false) - t.end() + assert.equal(config.distributed_tracing.enabled, false) }) - t.test('disables DT when DT set to false and account_id is set', (t) => { + await t.test('disables DT when DT set to false and account_id is set', () => { const config = Config.initialize({ account_id: '1234', distributed_tracing: { enabled: false }, @@ -446,11 +435,10 @@ tap.test('when distributed_tracing manually set in serverless_mode', (t) => { enabled: true } }) - t.equal(config.distributed_tracing.enabled, false) - t.end() + assert.equal(config.distributed_tracing.enabled, false) }) - t.test('works if all required env vars are defined', (t) => { + await t.test('works if all required env vars are defined', () => { const env = { NEW_RELIC_TRUSTED_ACCOUNT_KEY: 'defined', NEW_RELIC_ACCOUNT_ID: 'defined', @@ -458,7 +446,6 @@ tap.test('when distributed_tracing manually set in serverless_mode', (t) => { NEW_RELIC_SERVERLESS_MODE_ENABLED: true, NEW_RELIC_DISTRIBUTED_TRACING_ENABLED: true } - t.doesNotThrow(idempotentEnv.bind(idempotentEnv, env, () => {})) - t.end() + assert.doesNotThrow(idempotentEnv.bind(idempotentEnv, env, () => {})) }) }) diff --git a/test/unit/config/config.test.js b/test/unit/config/config.test.js index 29df9a598f..f2bb4e15c9 100644 --- a/test/unit/config/config.test.js +++ b/test/unit/config/config.test.js @@ -5,24 +5,21 @@ 'use strict' -const tap = require('tap') +const test = require('node:test') +const assert = require('node:assert') const sinon = require('sinon') const Config = require('../../../lib/config') -tap.test('should handle a directly passed minimal configuration', (t) => { +test('should handle a directly passed minimal configuration', () => { let config - t.doesNotThrow(function testInitialize() { + assert.doesNotThrow(function testInitialize() { config = Config.initialize({}) }) - t.equal(config.agent_enabled, true) - - t.end() + assert.equal(config.agent_enabled, true) }) -tap.test('when loading invalid configuration file', (t) => { - t.autoend() - +test('when loading invalid configuration file', async (t) => { let realpathSyncStub const fsUnwrapped = require('../../../lib/util/unwrapped-core').fs @@ -36,24 +33,20 @@ tap.test('when loading invalid configuration file', (t) => { realpathSyncStub.restore() }) - t.test('should continue agent startup with config.newrelic_home property removed', (t) => { + await t.test('should continue agent startup with config.newrelic_home property removed', () => { const Cornfig = require('../../../lib/config') let configuration - t.doesNotThrow(function envTest() { + assert.doesNotThrow(function envTest() { configuration = Cornfig.initialize() }) - t.notOk(configuration.newrelic_home) - - t.end() + assert.ok(!configuration.newrelic_home) }) }) -tap.test('when loading options via constructor', (t) => { - t.autoend() - - t.test('should properly pick up on expected_messages', (t) => { +test('when loading options via constructor', async (t) => { + await t.test('should properly pick up on expected_messages', () => { const options = { expected_messages: { Error: ['oh no'] @@ -64,11 +57,10 @@ tap.test('when loading options via constructor', (t) => { error_collector: options }) - t.same(config.error_collector.expected_messages, options.expected_messages) - t.end() + assert.deepStrictEqual(config.error_collector.expected_messages, options.expected_messages) }) - t.test('should properly pick up on ignore_messages', (t) => { + await t.test('should properly pick up on ignore_messages', () => { const options = { ignore_messages: { Error: ['oh no'] @@ -79,28 +71,21 @@ tap.test('when loading options via constructor', (t) => { error_collector: options }) - t.same(config.error_collector.ignore_messages, options.ignore_messages) - t.end() + assert.deepStrictEqual(config.error_collector.ignore_messages, options.ignore_messages) }) - t.test('should trim should trim spaces from license key', (t) => { + await t.test('should trim should trim spaces from license key', () => { const config = new Config({ license_key: ' license ' }) - t.equal(config.license_key, 'license') - - t.end() + assert.equal(config.license_key, 'license') }) - t.test('should have log aliases', (t) => { + await t.test('should have log aliases', () => { const config = new Config({ logging: { level: 'verbose' } }) - t.equal(config.logging.level, 'trace') - - t.end() + assert.equal(config.logging.level, 'trace') }) }) -tap.test('#publicSettings', (t) => { - t.autoend() - +test('#publicSettings', async (t) => { let configuration t.beforeEach(() => { @@ -114,60 +99,50 @@ tap.test('#publicSettings', (t) => { configuration = null }) - t.test('should be able to create a flat JSONifiable version', (t) => { + await t.test('should be able to create a flat JSONifiable version', () => { const pub = configuration.publicSettings() // The object returned from Config.publicSettings // should not have any values of type object for (const key in pub) { if (pub[key] !== null) { - t.not(typeof pub[key], 'object') + assert.notStrictEqual(typeof pub[key], 'object') } } - - t.end() }) - t.test('should not return serialized attributeFilter object from publicSettings', (t) => { + await t.test('should not return serialized attributeFilter object from publicSettings', () => { const pub = configuration.publicSettings() const result = Object.keys(pub).some((key) => { return key.includes('attributeFilter') }) - t.notOk(result) - - t.end() + assert.ok(!result) }) - t.test('should not return serialized mergeServerConfig props from publicSettings', (t) => { + await t.test('should not return serialized mergeServerConfig props from publicSettings', () => { const pub = configuration.publicSettings() const result = Object.keys(pub).some((key) => { return key.includes('mergeServerConfig') }) - t.notOk(result) - - t.end() + assert.ok(!result) }) - t.test('should obfuscate certificates in publicSettings', (t) => { + await t.test('should obfuscate certificates in publicSettings', () => { configuration = Config.initialize({ certificates: ['some-pub-cert-1', 'some-pub-cert-2'] }) const publicSettings = configuration.publicSettings() - t.equal(publicSettings['certificates.0'], '****') - t.equal(publicSettings['certificates.1'], '****') - - t.end() + assert.equal(publicSettings['certificates.0'], '****') + assert.equal(publicSettings['certificates.1'], '****') }) - t.test('should turn the app name into an array', (t) => { + await t.test('should turn the app name into an array', () => { configuration = Config.initialize({ app_name: 'test app name' }) - t.same(configuration.applications(), ['test app name']) - - t.end() + assert.deepStrictEqual(configuration.applications(), ['test app name']) }) }) diff --git a/test/unit/config/harvest-config-validator.test.js b/test/unit/config/harvest-config-validator.test.js index 068a15291e..9bebbee152 100644 --- a/test/unit/config/harvest-config-validator.test.js +++ b/test/unit/config/harvest-config-validator.test.js @@ -5,138 +5,108 @@ 'use strict' -const tap = require('tap') - +const test = require('node:test') +const assert = require('node:assert') const harvestConfigValidator = require('../../../lib/config/harvest-config-validator') -tap.test('#isValidHarvestValue', (t) => { - t.autoend() - - t.test('should be valid when positive number', (t) => { +test('#isValidHarvestValue', async (t) => { + await t.test('should be valid when positive number', () => { const isValid = harvestConfigValidator.isValidHarvestValue(1) - t.equal(isValid, true) - - t.end() + assert.equal(isValid, true) }) - t.test('should be valid when zero', (t) => { + await t.test('should be valid when zero', () => { const isValid = harvestConfigValidator.isValidHarvestValue(0) - t.equal(isValid, true) - - t.end() + assert.equal(isValid, true) }) - t.test('should be invalid when null', (t) => { + await t.test('should be invalid when null', () => { const isValid = harvestConfigValidator.isValidHarvestValue(null) - t.equal(isValid, false) - - t.end() + assert.equal(isValid, false) }) - t.test('should be invalid when undefined', (t) => { + await t.test('should be invalid when undefined', () => { const isValid = harvestConfigValidator.isValidHarvestValue() - t.equal(isValid, false) - - t.end() + assert.equal(isValid, false) }) - t.test('should be invalid when less than zero', (t) => { + await t.test('should be invalid when less than zero', () => { const isValid = harvestConfigValidator.isValidHarvestValue(-1) - t.equal(isValid, false) - - t.end() + assert.equal(isValid, false) }) }) -tap.test('#isHarvestConfigValid', (t) => { - t.autoend() - - t.test('should be valid with valid config', (t) => { +test('#isHarvestConfigValid', async (t) => { + await t.test('should be valid with valid config', () => { const validConfig = getValidHarvestConfig() const isValidConfig = harvestConfigValidator.isValidHarvestConfig(validConfig) - t.equal(isValidConfig, true) - - t.end() + assert.equal(isValidConfig, true) }) - t.test('should be invalid with invalid report_period', (t) => { + await t.test('should be invalid with invalid report_period', () => { const invalidConfig = getValidHarvestConfig() invalidConfig.report_period_ms = null const isValidConfig = harvestConfigValidator.isValidHarvestConfig(invalidConfig) - t.equal(isValidConfig, false) - - t.end() + assert.equal(isValidConfig, false) }) - t.test('should be invalid with missing harvest_limits', (t) => { + await t.test('should be invalid with missing harvest_limits', () => { const invalidConfig = getValidHarvestConfig() invalidConfig.harvest_limits = null const isValidConfig = harvestConfigValidator.isValidHarvestConfig(invalidConfig) - t.equal(isValidConfig, false) - - t.end() + assert.equal(isValidConfig, false) }) - t.test('should be invalid with empty harvest_limits', (t) => { + await t.test('should be invalid with empty harvest_limits', () => { const invalidConfig = getValidHarvestConfig() invalidConfig.harvest_limits = {} const isValidConfig = harvestConfigValidator.isValidHarvestConfig(invalidConfig) - t.equal(isValidConfig, false) - - t.end() + assert.equal(isValidConfig, false) }) // TODO: organize the valids together - t.test('should be valid with valid analytic_event_data', (t) => { + await t.test('should be valid with valid analytic_event_data', () => { const validConfig = getValidHarvestConfig() validConfig.harvest_limits.error_event_data = null validConfig.harvest_limits.custom_event_data = null validConfig.harvest_limits.span_event_data = null const isValidConfig = harvestConfigValidator.isValidHarvestConfig(validConfig) - t.equal(isValidConfig, true) - - t.end() + assert.equal(isValidConfig, true) }) - t.test('should be valid with custom_event_data', (t) => { + await t.test('should be valid with custom_event_data', () => { const validConfig = getValidHarvestConfig() validConfig.harvest_limits.error_event_data = null validConfig.harvest_limits.analytic_event_data = null validConfig.harvest_limits.span_event_data = null const isValidConfig = harvestConfigValidator.isValidHarvestConfig(validConfig) - t.equal(isValidConfig, true) - - t.end() + assert.equal(isValidConfig, true) }) - t.test('should be valid with valid error_event_data', (t) => { + await t.test('should be valid with valid error_event_data', () => { const validConfig = getValidHarvestConfig() validConfig.harvest_limits.custom_event_data = null validConfig.harvest_limits.analytic_event_data = null validConfig.harvest_limits.span_event_data = null const isValidConfig = harvestConfigValidator.isValidHarvestConfig(validConfig) - t.equal(isValidConfig, true) - - t.end() + assert.equal(isValidConfig, true) }) - t.test('should be valid with valid span_event_data', (t) => { + await t.test('should be valid with valid span_event_data', () => { const validConfig = getValidHarvestConfig() validConfig.harvest_limits.error_event_data = null validConfig.harvest_limits.custom_event_data = null validConfig.harvest_limits.analytic_event_data = null const isValidConfig = harvestConfigValidator.isValidHarvestConfig(validConfig) - t.equal(isValidConfig, true) - - t.end() + assert.equal(isValidConfig, true) }) })