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 db unit tests to node:test #2514

Merged
merged 7 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion test/unit/db/query-parsers/sql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ test('database query parser', async (t) => {
t.todo('should strip database names from collection names as ' + cat.table)
} else {
await t.test('should parse the collection as ' + cat.table, function () {
amychisholm03 marked this conversation as resolved.
Show resolved Hide resolved
assert.equal(ps.collection, cat.table)
assert.equal(ps.collection, cat.table, `should parse the collection as ${cat.table}`)
})
}
})
Expand Down
21 changes: 13 additions & 8 deletions test/unit/db/query-trace-aggregator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,7 @@ test('Query Trace Aggregator', async (t) => {

await t.test('prepareJSON', async (t) => {
await t.test('webTransaction when record_sql is "raw"', async (t) => {
let queries

t.beforeEach(() => {
t.beforeEach((ctx) => {
const opts = {
config: new Config({
slow_sql: { enabled: true },
Expand All @@ -297,15 +295,17 @@ test('Query Trace Aggregator', async (t) => {
method: 'sql_trace_data'
}
const harvester = { add: sinon.stub() }
queries = new QueryTraceAggregator(opts, {}, harvester)
ctx.nr = {}
ctx.nr.queries = new QueryTraceAggregator(opts, {}, harvester)
})

await t.test('and `simple_compression` is `false`', async (t) => {
t.beforeEach(() => {
queries.config.simple_compression = false
t.beforeEach((ctx) => {
ctx.nr.queries.config.simple_compression = false
})

await t.test('should compress the query parameters', (t, end) => {
const { queries } = t.nr
addQuery(queries, 600, '/abc')

queries.prepareJSON(function preparedJSON(err, data) {
Expand All @@ -325,11 +325,12 @@ test('Query Trace Aggregator', async (t) => {
})

await t.test('and `simple_compression` is `true`', async (t) => {
t.beforeEach(() => {
queries.config.simple_compression = true
t.beforeEach((ctx) => {
ctx.nr.queries.config.simple_compression = true
})

await t.test('should not compress the query parameters', (t, end) => {
const { queries } = t.nr
addQuery(queries, 600, '/abc')

queries.prepareJSON(function preparedJSON(err, data) {
Expand All @@ -345,6 +346,7 @@ test('Query Trace Aggregator', async (t) => {
})

await t.test('should record work when empty', (t, end) => {
const { queries } = t.nr
queries.prepareJSON(function preparedJSON(err, data) {
assert.equal(err, null, 'should not error')
assert.deepStrictEqual(data, [], 'should return empty array')
Expand All @@ -353,6 +355,7 @@ test('Query Trace Aggregator', async (t) => {
})

await t.test('should record work with a single query', (t, end) => {
const { queries } = t.nr
addQuery(queries, 600, '/abc')

queries.prepareJSON(function preparedJSON(err, data) {
Expand Down Expand Up @@ -383,6 +386,7 @@ test('Query Trace Aggregator', async (t) => {
})

await t.test('should record work with a multiple similar queries', (t, end) => {
const { queries } = t.nr
addQuery(queries, 600, '/abc')
addQuery(queries, 550, '/abc')

Expand Down Expand Up @@ -418,6 +422,7 @@ test('Query Trace Aggregator', async (t) => {
})

await t.test('should record work with a multiple unique queries', (t, end) => {
const { queries } = t.nr
addQuery(queries, 600, '/abc')
addQuery(queries, 550, '/abc', 'drop table users')

Expand Down
Loading