From 3744c6abfe1a5431a0f4a8dc04a0d632e6e8ca77 Mon Sep 17 00:00:00 2001 From: Jordi Bertran de Balanda Date: Wed, 5 Apr 2023 14:49:53 +0200 Subject: [PATCH] add tests on v1 for mysql databases --- packages/datadog-plugin-mariadb/test/index.spec.js | 14 ++++++++++---- packages/datadog-plugin-mariadb/test/naming.js | 14 ++++++++++++++ packages/datadog-plugin-mysql/test/index.spec.js | 10 ++++++++-- packages/datadog-plugin-mysql/test/naming.js | 14 ++++++++++++++ packages/datadog-plugin-mysql2/test/index.spec.js | 14 ++++++++++---- packages/datadog-plugin-mysql2/test/naming.js | 14 ++++++++++++++ 6 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 packages/datadog-plugin-mariadb/test/naming.js create mode 100644 packages/datadog-plugin-mysql/test/naming.js create mode 100644 packages/datadog-plugin-mysql2/test/naming.js diff --git a/packages/datadog-plugin-mariadb/test/index.spec.js b/packages/datadog-plugin-mariadb/test/index.spec.js index 54972a5d5f9..df2e0dc4238 100644 --- a/packages/datadog-plugin-mariadb/test/index.spec.js +++ b/packages/datadog-plugin-mariadb/test/index.spec.js @@ -5,6 +5,8 @@ const agent = require('../../dd-trace/test/plugins/agent') const proxyquire = require('proxyquire').noPreserveCache() const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants') +const namingSchema = require('./naming') + // https://github.com/mariadb-corporation/mariadb-connector-nodejs/commit/0a90b71ab20ab4e8b6a86a77ba291bba8ba6a34e const range = semver.gte(process.version, '15.0.0') ? '>=2.5.1' : '>=2' @@ -86,7 +88,8 @@ describe('Plugin', () => { it('should do automatic instrumentation', done => { agent .use(traces => { - expect(traces[0][0]).to.have.property('service', 'test-mariadb') + expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName) + expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName) expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution') expect(traces[0][0]).to.have.property('type', 'sql') expect(traces[0][0].meta).to.have.property('span.kind', 'client') @@ -108,7 +111,8 @@ describe('Plugin', () => { it('should support prepared statement shorthand', done => { agent .use(traces => { - expect(traces[0][0]).to.have.property('service', 'test-mariadb') + expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName) + expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName) expect(traces[0][0]).to.have.property('resource', 'SELECT ? + ? AS solution') expect(traces[0][0]).to.have.property('type', 'sql') expect(traces[0][0].meta).to.have.property('span.kind', 'client') @@ -129,7 +133,8 @@ describe('Plugin', () => { it('should support prepared statements', done => { agent .use(traces => { - expect(traces[0][0]).to.have.property('service', 'test-mariadb') + expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName) + expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName) expect(traces[0][0]).to.have.property('resource', 'SELECT ? + ? AS solution') expect(traces[0][0]).to.have.property('type', 'sql') expect(traces[0][0].meta).to.have.property('span.kind', 'client') @@ -293,7 +298,8 @@ describe('Plugin', () => { it('should do automatic instrumentation', done => { agent .use(traces => { - expect(traces[0][0]).to.have.property('service', 'test-mariadb') + expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName) + expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName) expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution') expect(traces[0][0]).to.have.property('type', 'sql') expect(traces[0][0].meta).to.have.property('span.kind', 'client') diff --git a/packages/datadog-plugin-mariadb/test/naming.js b/packages/datadog-plugin-mariadb/test/naming.js new file mode 100644 index 00000000000..b53a036f23e --- /dev/null +++ b/packages/datadog-plugin-mariadb/test/naming.js @@ -0,0 +1,14 @@ +const { resolveNaming } = require('../../dd-trace/test/plugins/helpers') + +module.exports = resolveNaming({ + outbound: { + v0: { + opName: 'mariadb.query', + serviceName: 'test-mariadb' + }, + v1: { + opName: 'mariadb.query', + serviceName: 'test' + } + } +}) diff --git a/packages/datadog-plugin-mysql/test/index.spec.js b/packages/datadog-plugin-mysql/test/index.spec.js index 82a74844904..cc2fc03a7c0 100644 --- a/packages/datadog-plugin-mysql/test/index.spec.js +++ b/packages/datadog-plugin-mysql/test/index.spec.js @@ -4,6 +4,8 @@ const agent = require('../../dd-trace/test/plugins/agent') const proxyquire = require('proxyquire').noPreserveCache() const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants') +const namingSchema = require('./naming') + describe('Plugin', () => { let mysql let tracer @@ -67,7 +69,8 @@ describe('Plugin', () => { it('should do automatic instrumentation', done => { agent.use(traces => { - expect(traces[0][0]).to.have.property('service', 'test-mysql') + expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName) + expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName) expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution') expect(traces[0][0]).to.have.property('type', 'sql') expect(traces[0][0].meta).to.have.property('span.kind', 'client') @@ -134,6 +137,7 @@ describe('Plugin', () => { it('should be configured with the correct values', done => { agent.use(traces => { + expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName) expect(traces[0][0]).to.have.property('service', 'custom') done() }) @@ -167,6 +171,7 @@ describe('Plugin', () => { it('should be configured with the correct values', done => { agent.use(traces => { + expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName) expect(traces[0][0]).to.have.property('service', 'custom') sinon.assert.calledWith(serviceSpy, sinon.match({ host: 'localhost', @@ -203,7 +208,8 @@ describe('Plugin', () => { it('should do automatic instrumentation', done => { agent.use(traces => { - expect(traces[0][0]).to.have.property('service', 'test-mysql') + expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName) + expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName) expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution') expect(traces[0][0]).to.have.property('type', 'sql') expect(traces[0][0].meta).to.have.property('span.kind', 'client') diff --git a/packages/datadog-plugin-mysql/test/naming.js b/packages/datadog-plugin-mysql/test/naming.js new file mode 100644 index 00000000000..e0a849ddf77 --- /dev/null +++ b/packages/datadog-plugin-mysql/test/naming.js @@ -0,0 +1,14 @@ +const { resolveNaming } = require('../../dd-trace/test/plugins/helpers') + +module.exports = resolveNaming({ + outbound: { + v0: { + opName: 'mysql.query', + serviceName: 'test-mysql' + }, + v1: { + opName: 'mysql.query', + serviceName: 'test' + } + } +}) diff --git a/packages/datadog-plugin-mysql2/test/index.spec.js b/packages/datadog-plugin-mysql2/test/index.spec.js index f06d5ff315b..41cff066450 100644 --- a/packages/datadog-plugin-mysql2/test/index.spec.js +++ b/packages/datadog-plugin-mysql2/test/index.spec.js @@ -4,6 +4,8 @@ const agent = require('../../dd-trace/test/plugins/agent') const proxyquire = require('proxyquire').noPreserveCache() const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants') +const namingSchema = require('./naming') + describe('Plugin', () => { let mysql2 let tracer @@ -74,7 +76,8 @@ describe('Plugin', () => { it('should do automatic instrumentation', done => { agent .use(traces => { - expect(traces[0][0]).to.have.property('service', 'test-mysql') + expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName) + expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName) expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution') expect(traces[0][0]).to.have.property('type', 'sql') expect(traces[0][0].meta).to.have.property('span.kind', 'client') @@ -94,7 +97,8 @@ describe('Plugin', () => { it('should support prepared statement shorthand', done => { agent .use(traces => { - expect(traces[0][0]).to.have.property('service', 'test-mysql') + expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName) + expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName) expect(traces[0][0]).to.have.property('resource', 'SELECT ? + ? AS solution') expect(traces[0][0]).to.have.property('type', 'sql') expect(traces[0][0].meta).to.have.property('span.kind', 'client') @@ -116,7 +120,8 @@ describe('Plugin', () => { it('should support prepared statements', done => { agent .use(traces => { - expect(traces[0][0]).to.have.property('service', 'test-mysql') + expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName) + expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName) expect(traces[0][0]).to.have.property('resource', 'SELECT ? + ? AS solution') expect(traces[0][0]).to.have.property('type', 'sql') expect(traces[0][0].meta).to.have.property('span.kind', 'client') @@ -262,7 +267,8 @@ describe('Plugin', () => { it('should do automatic instrumentation', done => { agent .use(traces => { - expect(traces[0][0]).to.have.property('service', 'test-mysql') + expect(traces[0][0]).to.have.property('name', namingSchema.outbound.opName) + expect(traces[0][0]).to.have.property('service', namingSchema.outbound.serviceName) expect(traces[0][0]).to.have.property('resource', 'SELECT 1 + 1 AS solution') expect(traces[0][0]).to.have.property('type', 'sql') expect(traces[0][0].meta).to.have.property('span.kind', 'client') diff --git a/packages/datadog-plugin-mysql2/test/naming.js b/packages/datadog-plugin-mysql2/test/naming.js new file mode 100644 index 00000000000..e0a849ddf77 --- /dev/null +++ b/packages/datadog-plugin-mysql2/test/naming.js @@ -0,0 +1,14 @@ +const { resolveNaming } = require('../../dd-trace/test/plugins/helpers') + +module.exports = resolveNaming({ + outbound: { + v0: { + opName: 'mysql.query', + serviceName: 'test-mysql' + }, + v1: { + opName: 'mysql.query', + serviceName: 'test' + } + } +})