Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit b5fee87

Browse files
djonathascardosokjin
authored andcommitted
test: add test-pluginloader and test-trancing
1 parent 2def9ac commit b5fee87

2 files changed

Lines changed: 165 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright 2018 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {PluginNames, TracerImpl} from '@opencensus/opencensus-core';
18+
import * as assert from 'assert';
19+
import {isArray} from 'util';
20+
21+
import {CONSTANTS} from '../src/trace/constants';
22+
import {PluginLoader} from '../src/trace/instrumentation/plugingloader';
23+
import {TracingImpl} from '../src/trace/tracing';
24+
25+
describe('PluginLoader', () => {
26+
/** Should create a Tracing instance */
27+
describe('new PluginLoader()', () => {
28+
it('should create a PluginLoader instance', () => {
29+
const tracer = new TracerImpl();
30+
const pluginLoader = new PluginLoader(tracer);
31+
assert.ok(pluginLoader instanceof PluginLoader);
32+
});
33+
});
34+
35+
/** Should get the plugins to use. */
36+
describe('static defaultPluginsFromArray()', () => {
37+
it('should get the plugins to use', () => {
38+
const plugins = PluginLoader.defaultPluginsFromArray(
39+
CONSTANTS.DEFAULT_INSTRUMENTATION_MODULES);
40+
assert.ok(plugins['http']);
41+
assert.ok(plugins['https']);
42+
assert.ok(plugins['mongodb-core']);
43+
});
44+
});
45+
46+
/** Should load the plugins. */
47+
describe('loadPlugins()', () => {
48+
it('should load the plugins', () => {
49+
const plugins = PluginLoader.defaultPluginsFromArray(
50+
CONSTANTS.DEFAULT_INSTRUMENTATION_MODULES);
51+
const tracer = new TracerImpl();
52+
const pluginLoader = new PluginLoader(tracer);
53+
54+
assert.equal(pluginLoader.loadPlugins(plugins), null);
55+
});
56+
});
57+
58+
/** Should unload the plugins. */
59+
describe('unloadPlugins()', () => {
60+
it('should unload the plugins', () => {
61+
const plugins = PluginLoader.defaultPluginsFromArray(
62+
CONSTANTS.DEFAULT_INSTRUMENTATION_MODULES);
63+
const tracer = new TracerImpl();
64+
const pluginLoader = new PluginLoader(tracer);
65+
pluginLoader.loadPlugins(plugins);
66+
67+
assert.equal(pluginLoader.unloadPlugins(), null);
68+
});
69+
});
70+
});
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* Copyright 2018 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {ConsoleExporter, Exporter, Tracer, TracerImpl, Tracing} from '@opencensus/opencensus-core';
18+
import * as assert from 'assert';
19+
20+
import {TracingImpl} from '../src/trace/tracing';
21+
22+
describe('Tracing', () => {
23+
/** Should create a Tracing instance */
24+
describe('new Tracing()', () => {
25+
it('should create a Tracer instance', () => {
26+
const tracing = new TracingImpl();
27+
assert.ok(tracing instanceof TracingImpl);
28+
});
29+
});
30+
31+
/** Should get the singleton trancing instance. */
32+
describe('static get instance()', () => {
33+
it('should get the singleton trancing instance', () => {
34+
const tracing = TracingImpl.instance;
35+
assert.ok(tracing instanceof TracingImpl);
36+
});
37+
});
38+
39+
/** Should return a started tracing instance */
40+
describe('start()', () => {
41+
let tracingStarted: Tracing;
42+
before(() => {
43+
const tracing = new TracingImpl();
44+
tracingStarted = tracing.start();
45+
});
46+
it('should return a tracing instance', () => {
47+
assert.ok(tracingStarted instanceof TracingImpl);
48+
});
49+
50+
it('the tracing was started', () => {
51+
assert.ok(tracingStarted.tracer.active);
52+
});
53+
});
54+
55+
/** Should stop the tracing instance */
56+
describe('stop()', () => {
57+
it('should stop the tracing instance', () => {
58+
const tracing = new TracingImpl();
59+
tracing.start();
60+
tracing.stop();
61+
assert.ok(!tracing.tracer.active);
62+
});
63+
});
64+
65+
/** Should get the tracer instance */
66+
describe('get tracer()', () => {
67+
it('should get the tracer instance', () => {
68+
const tracing = new TracingImpl();
69+
tracing.start();
70+
const tracer = tracing.tracer;
71+
assert.ok(tracer instanceof TracerImpl);
72+
});
73+
});
74+
75+
/** Should get the exporter instance */
76+
describe('get exporter()', () => {
77+
it('should get the exporter instance', () => {
78+
const tracing = new TracingImpl();
79+
tracing.start();
80+
const exporter = tracing.exporter;
81+
assert.ok(exporter instanceof ConsoleExporter);
82+
});
83+
});
84+
85+
/** Should get the exporter instance */
86+
describe('registerExporter()', () => {
87+
it('should register the exporter on tracer', () => {
88+
const tracing = new TracingImpl();
89+
tracing.start();
90+
const exporter = tracing.exporter;
91+
tracing.registerExporter(exporter);
92+
assert.equal(tracing.tracer.eventListeners.length, 2);
93+
});
94+
});
95+
});

0 commit comments

Comments
 (0)