Skip to content

Commit

Permalink
chore: Convert config to node:test (#2517)
Browse files Browse the repository at this point in the history
  • Loading branch information
amychisholm03 authored Aug 28, 2024
1 parent bea4548 commit 1534a73
Show file tree
Hide file tree
Showing 11 changed files with 1,056 additions and 1,390 deletions.
99 changes: 46 additions & 53 deletions test/unit/config/attribute-filter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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')
}
17 changes: 7 additions & 10 deletions test/unit/config/collector-hostname.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
Loading

0 comments on commit 1534a73

Please sign in to comment.