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

Commit 2fe4fe4

Browse files
luanamartinssantossilva-fabio
authored andcommitted
test: add unit tests for consolelog-exporter
1 parent eba9b69 commit 2fe4fe4

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* Copyright 2018 Google LLC. 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 * as assert from 'assert';
18+
import * as mocha from 'mocha';
19+
20+
import {Buffer} from '../src/exporters/buffer';
21+
import {ConsoleLogExporter, NoopExporter} from '../src/exporters/consolelog-exporter';
22+
import {RootSpanImpl} from '../src/trace/model/rootspan';
23+
import {TracerImpl} from '../src/trace/model/tracer';
24+
import {RootSpan} from '../src/trace/model/types';
25+
26+
const tracer = new TracerImpl();
27+
const DEFAULT_BUFFER_SIZE = 3;
28+
const DEFAULT_BUFFER_TIMEOUT = 20000; // time in milliseconds
29+
const defaultBufferConfig = {
30+
bufferSize: DEFAULT_BUFFER_SIZE,
31+
bufferTimeout: DEFAULT_BUFFER_TIMEOUT
32+
};
33+
34+
describe('NoopExporter', () => {
35+
/** Should do anything when calling onEndSpan() */
36+
describe('onEndSpan()', () => {
37+
it('should do anything', () => {
38+
const exporter = new NoopExporter();
39+
const rootSpan = new RootSpanImpl(tracer);
40+
exporter.onEndSpan(rootSpan);
41+
assert.ok(true);
42+
});
43+
});
44+
45+
/** Should do anything when calling publish() */
46+
describe('publish()', () => {
47+
it('should do anything', () => {
48+
const exporter = new NoopExporter();
49+
const rootSpan = new RootSpanImpl(tracer);
50+
const queue: RootSpan[] = [];
51+
queue.push(rootSpan);
52+
53+
exporter.publish(queue);
54+
assert.ok(true);
55+
});
56+
});
57+
});
58+
59+
describe('ConsoleLogExporter', () => {
60+
/** Should end a span */
61+
describe('onEndSpan()', () => {
62+
it('should end a span', () => {
63+
const exporter = new ConsoleLogExporter(defaultBufferConfig);
64+
const rootSpan = new RootSpanImpl(tracer);
65+
exporter.onEndSpan(rootSpan);
66+
assert.ok(true);
67+
});
68+
});
69+
70+
/** Should publish the rootspan in queue */
71+
describe('publish()', () => {
72+
it('should publish the rootspans in queue', () => {
73+
const exporter = new ConsoleLogExporter(defaultBufferConfig);
74+
const rootSpan = new RootSpanImpl(tracer);
75+
rootSpan.startSpan('name', 'type', rootSpan.traceId);
76+
const queue: RootSpan[] = [];
77+
queue.push(rootSpan);
78+
79+
exporter.publish(queue);
80+
assert.ok(true);
81+
});
82+
});
83+
});

0 commit comments

Comments
 (0)