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

Commit f957357

Browse files
Adapted tests for dev
1 parent 5034618 commit f957357

4 files changed

Lines changed: 168 additions & 153 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* Copyright 2017 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 { RootSpan } from '../src/trace/model/rootspan';
18+
import { Span } from '../src/trace/model/span';
19+
import { Tracer } from '../src/trace/model/tracer';
20+
import { SpanBaseModel } from '../src/trace/types/tracetypes';
21+
22+
let assert = require('assert');
23+
let tracer = new Tracer();
24+
25+
describe('RootSpan', function () {
26+
describe('new RootSpan()', function () {
27+
it('should create a RootSpan instance', function () {
28+
let root = new RootSpan(tracer);
29+
assert.ok(root instanceof SpanBaseModel);
30+
});
31+
});
32+
33+
describe('start()', function () {
34+
35+
it('should start a RootSpan instance', function () {
36+
let root = new RootSpan(tracer);
37+
root.start();
38+
assert.ok(root.started);
39+
});
40+
41+
});
42+
43+
describe('startSpan()', function () {
44+
45+
let root, span;
46+
47+
before(function () {
48+
root = new RootSpan(tracer);
49+
root.start();
50+
span = root.startSpan('spanName', 'spanType');
51+
});
52+
53+
it('should check span instance type', function () {
54+
assert.ok(span instanceof Span);
55+
});
56+
57+
it('should check if a new span was started', function () {
58+
assert.ok(span.started);
59+
});
60+
});
61+
62+
describe('end()', function () {
63+
it('should end the trace', function () {
64+
let root = new RootSpan(tracer);
65+
root.start();
66+
root.end();
67+
assert.ok(root.ended);
68+
});
69+
});
70+
71+
describe('end() before trace started', function () {
72+
it('should not end trace', function () {
73+
let root = new RootSpan(tracer);
74+
root.end();
75+
assert.ok(!root.ended);
76+
});
77+
});
78+
79+
describe('startSpan() before trace started', function () {
80+
it('should not create span', function () {
81+
let root = new RootSpan(tracer);
82+
let span = root.startSpan('spanName', 'spanType');
83+
assert.ok(span == null);
84+
});
85+
});
86+
87+
describe('startSpan() after trace ended', function () {
88+
it('should not create span', function () {
89+
let root = new RootSpan(tracer);
90+
root.start();
91+
root.end();
92+
let span = root.startSpan('spanName', 'spanType');
93+
assert.ok(span == null);
94+
});
95+
});
96+
});

packages/opencensus-core/test/test-span.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,59 +24,58 @@ var assert = require('assert');
2424

2525
let tracer = new Tracer()
2626

27-
describe('Span creation', function () {
27+
describe('Span', function () {
2828

29-
let root;
30-
let span;
29+
describe('startSpan()', function () {
3130

32-
before(function () {
33-
root = new RootSpan(tracer);
34-
span = root.startSpan('spanName', 'typeSpan');
35-
});
31+
it('should create an span', function () {
32+
const rootSpan = new RootSpan(tracer);
33+
assert.ok(rootSpan instanceof SpanBaseModel);
3634

37-
it('should create an span on the trace', function () {
38-
assert.ok(root instanceof SpanBaseModel);
39-
span = root.startSpan('spanName', 'typeSpan');
35+
rootSpan.start();
36+
const span = rootSpan.startSpan('spanName', 'typeSpan');
4037
assert.ok(span instanceof Span);
4138
assert.ok(span.id);
4239
});
4340

4441
it('should start a span', function () {
42+
const rootSpan = new RootSpan(tracer);
43+
rootSpan.start();
44+
const span = rootSpan.startSpan('spanName', 'typeSpan');
4545
span.start();
4646
assert.ok(span.started);
4747
});
4848

4949
it('should end a span', function () {
50+
const rootSpan = new RootSpan(tracer);
51+
rootSpan.start();
52+
const span = rootSpan.startSpan('spanName', 'typeSpan');
53+
span.start();
5054
span.end();
5155
assert.ok(span.ended);
5256
});
5357
});
5458

55-
describe('Span checking creation', function () {
56-
57-
let root;
58-
let span;
59-
60-
before(function () {
61-
root = new RootSpan(tracer);
62-
span = root.startSpan('spanName', 'typeSpan');
63-
});
59+
describe('Span checking after creation', function () {
6460

6561
it('should not start span after it ended', function () {
62+
const root = new RootSpan(tracer);
63+
root.start();
64+
const span = root.startSpan('spanName', 'typeSpan');
65+
span.start();
6666
span.end();
67+
68+
span.start();
6769
assert.equal(span.ended, true);
6870
});
6971
});
7072

7173
describe('Span data', function () {
7274

73-
let root;
74-
75-
before(function () {
76-
root = new RootSpan(tracer);
77-
});
75+
it('should create an unique numeric span ID strings', function () {
76+
const root = new RootSpan(tracer);
77+
root.start();
7878

79-
it('generates unique numeric span ID strings', function () {
8079
var numberOfSpansToCheck = 5;
8180
for (var i = 0; i < numberOfSpansToCheck; i++) {
8281
var span = root.startSpan('spanName' + i, 'typeSpan' + i);
@@ -89,8 +88,9 @@ describe('Span data', function () {
8988
});
9089

9190
// TODO
92-
it('truncates namespace', function(){
91+
it('should truncate namespace', function () {
9392
this.skip();
9493
});
9594
});
9695

96+
});

packages/opencensus-core/test/test-trace.ts

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)