Skip to content

Commit 54ab238

Browse files
authored
test: Updated unit tests that were missing constructing specs at instrumentation source (#2252)
1 parent 8b1fa5d commit 54ab238

File tree

7 files changed

+187
-140
lines changed

7 files changed

+187
-140
lines changed

lib/instrumentation/amqplib/amqplib.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ function wrapModel(shim, Model, promiseMode) {
289289
if (TEMP_RE.test(queue)) {
290290
queue = null
291291
}
292-
return new MessageSubscribeSpec({
292+
return new MessageSpec({
293293
queue,
294294
promise: promiseMode,
295295
callback: setCallback(shim, promiseMode)

test/unit/metric/datastore-instance.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const tap = require('tap')
1010
const helper = require('../../lib/agent_helper')
1111
const DatastoreShim = require('../../../lib/shim/datastore-shim')
1212
const tests = require('../../lib/cross_agent_tests/datastores/datastore_instances')
13+
const DatastoreParameters = require('../../../lib/shim/specs/params/datastore')
1314

1415
tap.test('Datastore instance metrics collected via the datastore shim', function (t) {
1516
t.autoend()
@@ -53,10 +54,10 @@ tap.test('Datastore instance metrics collected via the datastore shim', function
5354
port = test.unix_socket || test.database_path || test.port
5455
}
5556
return {
56-
parameters: {
57+
parameters: new DatastoreParameters({
5758
host: dbHost,
5859
port_path_or_id: port
59-
}
60+
})
6061
}
6162
})
6263

test/unit/shim/datastore-shim.test.js

+57-35
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const helper = require('../../lib/agent_helper')
1212
const Shim = require('../../../lib/shim/shim')
1313
const DatastoreShim = require('../../../lib/shim/datastore-shim')
1414
const ParsedStatement = require('../../../lib/db/parsed-statement')
15+
const { QuerySpec, OperationSpec } = require('../../../lib/shim/specs')
1516

1617
test('DatastoreShim', function (t) {
1718
t.autoend()
@@ -371,7 +372,7 @@ test('DatastoreShim', function (t) {
371372

372373
t.test('should create a child segment when opaque is false', (t) => {
373374
shim.recordOperation(wrappable, 'withNested', () => {
374-
return { name: 'test', opaque: false }
375+
return new OperationSpec({ name: 'test', opaque: false })
375376
})
376377
helper.runInTransaction(agent, (tx) => {
377378
const startingSegment = agent.tracer.getSegment()
@@ -388,7 +389,7 @@ test('DatastoreShim', function (t) {
388389

389390
t.test('should not create a child segment when opaque is true', (t) => {
390391
shim.recordOperation(wrappable, 'withNested', () => {
391-
return { name: 'test', opaque: true }
392+
return new OperationSpec({ name: 'test', opaque: true })
392393
})
393394
helper.runInTransaction(agent, (tx) => {
394395
const startingSegment = agent.tracer.getSegment()
@@ -455,7 +456,7 @@ test('DatastoreShim', function (t) {
455456
beforeEach()
456457
localhost = getMetricHostName(agent, 'localhost')
457458
shim.recordOperation(wrappable, 'getActiveSegment', function (s, fn, n, args) {
458-
return { parameters: args[0] }
459+
return new OperationSpec({ parameters: args[0] })
459460
})
460461
})
461462
t.afterEach(afterEach)
@@ -547,14 +548,14 @@ test('DatastoreShim', function (t) {
547548
t.beforeEach(function () {
548549
beforeEach()
549550
shim.recordOperation(wrappable, 'getActiveSegment', function () {
550-
return {
551+
return new OperationSpec({
551552
name: 'op',
552553
parameters: {
553554
host: 'some_host',
554555
port_path_or_id: 1234,
555556
database_name: 'foobar'
556557
}
557-
}
558+
})
558559
})
559560

560561
return new Promise((resolve) => {
@@ -627,11 +628,15 @@ test('DatastoreShim', function (t) {
627628
t.test(
628629
'should create a datastore query segment but no metric when `record` is false',
629630
function (t) {
630-
shim.recordQuery(wrappable, 'getActiveSegment', {
631-
query: shim.FIRST,
632-
record: false,
633-
name: 'getActiveSegment'
634-
})
631+
shim.recordQuery(
632+
wrappable,
633+
'getActiveSegment',
634+
new QuerySpec({
635+
query: shim.FIRST,
636+
record: false,
637+
name: 'getActiveSegment'
638+
})
639+
)
635640

636641
helper.runInTransaction(agent, function (tx) {
637642
const startingSegment = agent.tracer.getSegment()
@@ -646,7 +651,11 @@ test('DatastoreShim', function (t) {
646651
)
647652

648653
t.test('should create a datastore query metric when `record` is true', function (t) {
649-
shim.recordQuery(wrappable, 'getActiveSegment', { query: shim.FIRST, record: true })
654+
shim.recordQuery(
655+
wrappable,
656+
'getActiveSegment',
657+
new QuerySpec({ query: shim.FIRST, record: true })
658+
)
650659

651660
helper.runInTransaction(agent, function (tx) {
652661
const startingSegment = agent.tracer.getSegment()
@@ -660,7 +669,7 @@ test('DatastoreShim', function (t) {
660669
})
661670

662671
t.test('should create a datastore query metric when `record` is defaulted', function (t) {
663-
shim.recordQuery(wrappable, 'getActiveSegment', { query: shim.FIRST })
672+
shim.recordQuery(wrappable, 'getActiveSegment', new QuerySpec({ query: shim.FIRST }))
664673

665674
helper.runInTransaction(agent, function (tx) {
666675
const startingSegment = agent.tracer.getSegment()
@@ -691,14 +700,17 @@ test('DatastoreShim', function (t) {
691700
t.test('should allow after handlers to be specified', function (t) {
692701
let executed = false
693702
const toWrap = function () {}
694-
const wrapped = shim.recordQuery(toWrap, {
695-
query: function () {
696-
return 'test'
697-
},
698-
after: function () {
699-
executed = true
700-
}
701-
})
703+
const wrapped = shim.recordQuery(
704+
toWrap,
705+
new QuerySpec({
706+
query: function () {
707+
return 'test'
708+
},
709+
after: function () {
710+
executed = true
711+
}
712+
})
713+
)
702714

703715
helper.runInTransaction(agent, function () {
704716
t.notOk(executed)
@@ -710,10 +722,13 @@ test('DatastoreShim', function (t) {
710722

711723
t.test('should bind the callback if there is one', function (t) {
712724
const cb = function () {}
713-
const wrapped = shim.recordQuery(helper.checkWrappedCb.bind(t, shim, cb), {
714-
query: shim.FIRST,
715-
callback: shim.LAST
716-
})
725+
const wrapped = shim.recordQuery(
726+
helper.checkWrappedCb.bind(t, shim, cb),
727+
new QuerySpec({
728+
query: shim.FIRST,
729+
callback: shim.LAST
730+
})
731+
)
717732

718733
helper.runInTransaction(agent, function () {
719734
wrapped(query, cb)
@@ -723,23 +738,30 @@ test('DatastoreShim', function (t) {
723738
t.test('should bind the row callback if there is one', function (t) {
724739
const cb = function () {}
725740

726-
const wrapped = shim.recordQuery(helper.checkWrappedCb.bind(t, shim, cb), {
727-
query: shim.FIRST,
728-
rowCallback: shim.LAST
729-
})
741+
const wrapped = shim.recordQuery(
742+
helper.checkWrappedCb.bind(t, shim, cb),
743+
new QuerySpec({
744+
query: shim.FIRST,
745+
rowCallback: shim.LAST
746+
})
747+
)
730748

731749
helper.runInTransaction(agent, function () {
732750
wrapped(query, cb)
733751
})
734752
})
735753

736754
t.test('should execute inContext function when specified in spec', function (t) {
737-
shim.recordQuery(wrappable, 'bar', {
738-
query: 'select foo from bar;',
739-
inContext(segment) {
740-
segment.addAttribute('test-attr', 'unit-test')
741-
}
742-
})
755+
shim.recordQuery(
756+
wrappable,
757+
'bar',
758+
new QuerySpec({
759+
query: 'select foo from bar;',
760+
inContext(segment) {
761+
segment.addAttribute('test-attr', 'unit-test')
762+
}
763+
})
764+
)
743765

744766
helper.runInTransaction(agent, (tx) => {
745767
wrappable.bar()
@@ -797,7 +819,7 @@ test('DatastoreShim', function (t) {
797819
})
798820

799821
t.test('should create a datastore batch query metric', function (t) {
800-
shim.recordBatchQuery(wrappable, 'getActiveSegment', { query: shim.FIRST })
822+
shim.recordBatchQuery(wrappable, 'getActiveSegment', new QuerySpec({ query: shim.FIRST }))
801823

802824
helper.runInTransaction(agent, function (tx) {
803825
const startingSegment = agent.tracer.getSegment()

0 commit comments

Comments
 (0)