diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json index 4697636985..d02fb84ddc 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json @@ -47,6 +47,7 @@ }, "devDependencies": { "@opentelemetry/plugin-pg": "^0.3.1", + "@opentelemetry/test-utils": "^0.3.1", "@types/mocha": "^5.2.7", "@types/node": "^12.6.9", "@types/pg": "^7.11.2", diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts index 73ca6650a1..eb46f689ec 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/pg-pool.test.ts @@ -28,7 +28,7 @@ import * as assert from 'assert'; import * as pg from 'pg'; import * as pgPool from 'pg-pool'; import * as assertionUtils from './assertionUtils'; -import * as testUtils from './testUtils'; +import * as testUtils from '@opentelemetry/test-utils'; const memoryExporter = new InMemorySpanExporter(); @@ -97,14 +97,14 @@ describe('pg-pool@2.x', () => { pool = new pgPool(CONFIG); tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter)); if (testPostgresLocally) { - testUtils.startDocker(); + testUtils.startDocker('postgres'); } done(); }); after(function(done) { if (testPostgresLocally) { - testUtils.cleanUpDocker(); + testUtils.cleanUpDocker('postgres'); } pool.end(() => { done(); diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/testUtils.ts b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/testUtils.ts deleted file mode 100644 index eec866fc41..0000000000 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/test/testUtils.ts +++ /dev/null @@ -1,54 +0,0 @@ -/*! - * Copyright 2019, OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as childProcess from 'child_process'; -export function startDocker() { - const tasks = [ - run('docker run -d -p 54320:5432 --name otpostgres postgres:alpine'), - ]; - - for (let i = 0; i < tasks.length; i++) { - const task = tasks[i]; - if (task && task.code !== 0) { - console.error('Failed to start container!'); - console.error(task.output); - return false; - } - } - return true; -} - -export function cleanUpDocker() { - run('docker stop otpostgres'); - run('docker rm otpostgres'); -} - -function run(cmd: string) { - try { - const proc = childProcess.spawnSync(cmd, { - shell: true, - }); - return { - code: proc.status, - output: proc.output - .map(v => String.fromCharCode.apply(null, v as any)) - .join(''), - }; - } catch (e) { - console.log(e); - return; - } -}