Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Convert config to node:test #2517

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
makeFilterAssertions(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()
makeFilterAssertions(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 makeFilterAssertions(filter) {
amychisholm03 marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading