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

feat: test-utils #644

Merged
merged 8 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions packages/opentelemetry-plugin-mysql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"devDependencies": {
"@opentelemetry/node": "^0.3.1",
"@opentelemetry/test-utils": "^0.3.1",
"@opentelemetry/tracing": "^0.3.1",
"@types/mocha": "^5.2.7",
"@types/mysql": "^2.15.4",
Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-plugin-mysql/test/mysql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import * as assert from 'assert';
import * as mysql from 'mysql';
import { MysqlPlugin, plugin } from '../src';
import * as testUtils from './testUtils';
import * as testUtils from '@opentelemetry/test-utils';
import { AttributeNames } from '../src/enums';
import { CanonicalCode } from '@opentelemetry/types';

Expand Down Expand Up @@ -54,7 +54,7 @@ describe('[email protected]', () => {
}
tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
if (testMysqlLocally) {
testUtils.startDocker();
testUtils.startDocker('mysql');
// wait 15 seconds for docker container to start
this.timeout(20000);
setTimeout(done, 15000);
Expand All @@ -66,7 +66,7 @@ describe('[email protected]', () => {
after(function() {
if (testMysqlLocally) {
this.timeout(5000);
testUtils.cleanUpDocker();
testUtils.cleanUpDocker('mysql');
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/test-utils": "^0.3.1",
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.9",
"@types/pg": "^7.11.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { AttributeNames } from '../src/enums';
import * as assert from 'assert';
import * as pg from 'pg';
import * as assertionUtils from './assertionUtils';
import * as testUtils from './testUtils';
import * as testUtils from '@opentelemetry/test-utils';

const memoryExporter = new InMemorySpanExporter();

Expand Down Expand Up @@ -103,7 +103,7 @@ describe('[email protected]', () => {
}
tracer.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
if (testPostgresLocally) {
testUtils.startDocker();
testUtils.startDocker('postgres');
}

client = new pg.Client(CONFIG);
Expand All @@ -116,7 +116,7 @@ describe('[email protected]', () => {

after(async () => {
if (testPostgresLocally) {
testUtils.cleanUpDocker();
testUtils.cleanUpDocker('postgres');
}
await client.end();
});
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions packages/opentelemetry-plugin-redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
},
"devDependencies": {
"@opentelemetry/node": "^0.3.1",
"@opentelemetry/test-utils": "^0.3.1",
"@opentelemetry/tracing": "^0.3.1",
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.9",
Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-plugin-redis/test/redis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { NodeTracer } from '@opentelemetry/node';
import { plugin, RedisPlugin } from '../src';
import * as redisTypes from 'redis';
import { NoopLogger } from '@opentelemetry/core';
import * as dockerUtils from './testUtils';
import * as dockerUtils from '@opentelemetry/test-utils';
import * as assertionUtils from './assertionUtils';
import { SpanKind, Status, CanonicalCode } from '@opentelemetry/types';
import { AttributeNames } from '../src/enums';
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('[email protected]', () => {
}

if (shouldTestLocal) {
dockerUtils.startDocker();
dockerUtils.startDocker('redis');
}

redis = require('redis');
Expand All @@ -74,7 +74,7 @@ describe('[email protected]', () => {

after(() => {
if (shouldTestLocal) {
dockerUtils.cleanUpDocker();
dockerUtils.cleanUpDocker('redis');
}
});

Expand Down
54 changes: 0 additions & 54 deletions packages/opentelemetry-plugin-redis/test/testUtils.ts

This file was deleted.

31 changes: 31 additions & 0 deletions packages/opentelemetry-test-utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@opentelemetry/test-utils",
"version": "0.3.1",
"description": "Test utilities.",
"main": "build/testUtils.js",
"scripts": {
"check": "gts check",
"compile": "tsc -p .",
"fix": "gts fix",
"precompile": "tsc --version",
"prepare": "npm run compile"
},
"repository": "open-telemetry/opentelemetry-js",
"keywords": [
"opentelemetry",
"test-utils"
],
"author": "OpenTelemetry Authors",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme",
"devDependencies": {
"gts": "^1.1.2",
"ts-node": "^8.5.4",
"tslint-consistent-codestyle": "^1.16.0",
"tslint-microsoft-contrib": "^6.2.0",
"typescript": "3.7.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,23 @@
*/

import * as childProcess from 'child_process';
export function startDocker() {
const tasks = [
run(
'docker run --rm -d -e MYSQL_ROOT_PASSWORD=rootpw -e MYSQL_DATABASE=test_db -e MYSQL_USER=otel -e MYSQL_PASSWORD=secret -p 33306:3306 --name otmysql circleci/mysql:5.7'
),
];
export function startDocker(db: 'redis' | 'mysql' | 'postgres') {
let dockerRunCmd;
switch (db) {
case 'redis':
dockerRunCmd = `docker run -d -p 63790:6379 --name ot${db} ${db}:alpine`;
break;

case 'mysql':
dockerRunCmd = `docker run --rm -d -e MYSQL_ROOT_PASSWORD=rootpw -e MYSQL_DATABASE=test_db -e MYSQL_USER=otel -e MYSQL_PASSWORD=secret -p 33306:3306 --name ot${db} circleci/${db}:5.7`;
break;

case 'postgres':
dockerRunCmd = `docker run -d -p 54320:5432 --name ot${db} ${db}:alpine`;
break;
}

const tasks = [run(dockerRunCmd)];

for (let i = 0; i < tasks.length; i++) {
const task = tasks[i];
Expand All @@ -33,8 +44,9 @@ export function startDocker() {
return true;
}

export function cleanUpDocker() {
run('docker stop otmysql');
export function cleanUpDocker(db: 'redis' | 'mysql' | 'postgres') {
run(`docker stop ot${db}`);
run(`docker rm ot${db}`);
}

function run(cmd: string) {
Expand Down
10 changes: 10 additions & 0 deletions packages/opentelemetry-test-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.base",
"compilerOptions": {
"rootDir": ".",
"outDir": "build"
},
"include": [
"*.ts"
]
}
4 changes: 4 additions & 0 deletions packages/opentelemetry-test-utils/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rulesDirectory": ["node_modules/tslint-microsoft-contrib"],
"extends": ["../../tslint.base.js", "./node_modules/tslint-consistent-codestyle"]
}