|
17 | 17 | import * as assert from 'assert'; |
18 | 18 | import * as mocha from 'mocha'; |
19 | 19 |
|
20 | | -import {Span,RootSpan,Tracer} from '../src/trace/model/types'; |
21 | | -import {SpanImpl} from '../src/trace/model/span'; |
22 | 20 | import {RootSpanImpl} from '../src/trace/model/rootspan'; |
| 21 | +import {SpanImpl} from '../src/trace/model/span'; |
23 | 22 | import {TracerImpl} from '../src/trace/model/tracer'; |
24 | | -let tracer = new TracerImpl(); |
| 23 | +import {RootSpan, Span, TraceOptions, Tracer} from '../src/trace/model/types'; |
| 24 | + |
| 25 | +const tracer = new TracerImpl(); |
25 | 26 |
|
26 | | -describe('RootSpan', function() { |
| 27 | +describe('RootSpan', () => { |
27 | 28 | /** |
28 | 29 | * Should create a RootSpan instance |
29 | 30 | */ |
30 | | - describe('new RootSpan()', function() { |
31 | | - it('should create a RootSpan instance', function() { |
32 | | - let root = new RootSpanImpl(tracer); |
33 | | - assert.ok(root instanceof SpanImpl); |
| 31 | + describe('new RootSpan()', () => { |
| 32 | + it('should create a RootSpan instance', () => { |
| 33 | + const root = new RootSpanImpl(tracer); |
| 34 | + assert.ok(root instanceof RootSpanImpl); |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + /** |
| 39 | + * Should create a RootSpan instance with options |
| 40 | + */ |
| 41 | + describe('new RootSpan() with options', () => { |
| 42 | + it('should create a RootSpan instance with options', () => { |
| 43 | + const trace = new RootSpanImpl(tracer); |
| 44 | + const options = {name: 'test', traceContext: trace.traceContext} as |
| 45 | + TraceOptions; |
| 46 | + const root = new RootSpanImpl(tracer, options); |
| 47 | + assert.ok(root instanceof RootSpanImpl); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + /** |
| 52 | + * Should get span list from rootspan instance |
| 53 | + */ |
| 54 | + describe('get spans()', () => { |
| 55 | + it('should get span list from rootspan instance', () => { |
| 56 | + const root = new RootSpanImpl(tracer); |
| 57 | + root.start(); |
| 58 | + const span = root.startSpan('spanName', 'spanType'); |
| 59 | + |
| 60 | + for (const span of root.spans) { |
| 61 | + assert.ok(span instanceof SpanImpl); |
| 62 | + } |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + /** |
| 67 | + * Should get trace id from rootspan instance |
| 68 | + */ |
| 69 | + describe('new traceId()', () => { |
| 70 | + it('should get trace id from rootspan instance', () => { |
| 71 | + const root = new RootSpanImpl(tracer); |
| 72 | + assert.equal(root.traceId, root.traceContext.traceId); |
34 | 73 | }); |
35 | 74 | }); |
36 | 75 |
|
37 | 76 | /** |
38 | 77 | * Should create and start a RootSpan instance |
39 | 78 | */ |
40 | | - describe('start()', function() { |
41 | | - it('should start a RootSpan instance', function() { |
42 | | - let root = new RootSpanImpl(tracer); |
| 79 | + describe('start()', () => { |
| 80 | + it('should start a RootSpan instance', () => { |
| 81 | + const root = new RootSpanImpl(tracer); |
43 | 82 | root.start(); |
44 | 83 | assert.ok(root.started); |
45 | 84 | }); |
46 | 85 | }); |
47 | 86 |
|
48 | 87 | /** |
49 | | - * Should check type and a span was started |
| 88 | + * Should create and start a new span instance |
50 | 89 | */ |
51 | | - describe('startSpan()', function() { |
| 90 | + describe('startSpan()', () => { |
52 | 91 | let root, span; |
53 | 92 |
|
54 | | - before(function() { |
| 93 | + before(() => { |
55 | 94 | root = new RootSpanImpl(tracer); |
56 | 95 | root.start(); |
57 | 96 | span = root.startSpan('spanName', 'spanType'); |
58 | 97 | }); |
59 | 98 |
|
60 | | - it('should check span instance type', function() { |
| 99 | + it('should create span instance', () => { |
61 | 100 | assert.ok(span instanceof SpanImpl); |
62 | 101 | }); |
63 | 102 |
|
64 | | - it('should check if a new span was started', function() { |
| 103 | + it('should start a span instance', () => { |
65 | 104 | assert.ok(span.started); |
66 | 105 | }); |
67 | 106 | }); |
68 | 107 |
|
69 | 108 | /** |
70 | | - * Should start and end a rootspan properly |
| 109 | + * Should not start a span from a not started rootspan |
| 110 | + */ |
| 111 | + describe('startSpan() before start rootspan', () => { |
| 112 | + it('should not create span', () => { |
| 113 | + const root = new RootSpanImpl(tracer); |
| 114 | + const span = root.startSpan('spanName', 'spanType'); |
| 115 | + assert.ok(span == null); |
| 116 | + }); |
| 117 | + }); |
| 118 | + |
| 119 | + /** |
| 120 | + * Should not create a span from a ended rootspan |
71 | 121 | */ |
72 | | - describe('end()', function() { |
73 | | - it('should end the trace', function() { |
74 | | - let root = new RootSpanImpl(tracer); |
| 122 | + describe('startSpan() after rootspan ended', () => { |
| 123 | + it('should not create span', () => { |
| 124 | + const root = new RootSpanImpl(tracer); |
75 | 125 | root.start(); |
76 | 126 | root.end(); |
77 | | - assert.ok(root.ended); |
| 127 | + const span = root.startSpan('spanName', 'spanType'); |
| 128 | + assert.ok(span == null); |
78 | 129 | }); |
79 | 130 | }); |
80 | 131 |
|
81 | 132 | /** |
82 | | - * Should not end a rootspan which was not started |
| 133 | + * Should end a rootspan instance |
83 | 134 | */ |
84 | | - describe('end() before trace started', function() { |
85 | | - it('should not end trace', function() { |
86 | | - let root = new RootSpanImpl(tracer); |
| 135 | + describe('end()', () => { |
| 136 | + it('should end the rootspan instance', () => { |
| 137 | + const root = new RootSpanImpl(tracer); |
| 138 | + root.start(); |
87 | 139 | root.end(); |
88 | | - assert.ok(!root.ended); |
| 140 | + assert.ok(root.ended); |
89 | 141 | }); |
90 | 142 | }); |
91 | 143 |
|
92 | 144 | /** |
93 | | - * Should not start a span from a not started rootspan |
| 145 | + * Should not end a rootspan which was not started |
94 | 146 | */ |
95 | | - describe('startSpan() before trace started', function() { |
96 | | - it('should not create span', function() { |
97 | | - let root = new RootSpanImpl(tracer); |
98 | | - let span = root.startSpan('spanName', 'spanType'); |
99 | | - assert.ok(span == null); |
| 147 | + describe('end() before start rootspan', () => { |
| 148 | + it('should not end rootspan', () => { |
| 149 | + const root = new RootSpanImpl(tracer); |
| 150 | + root.end(); |
| 151 | + assert.ok(!root.ended); |
100 | 152 | }); |
101 | 153 | }); |
102 | 154 |
|
103 | 155 | /** |
104 | | - * Should not create a span from a ended rootspan |
| 156 | + * Should end all spans inside rootspan |
105 | 157 | */ |
106 | | - describe('startSpan() after trace ended', function() { |
107 | | - it('should not create span', function() { |
108 | | - let root = new RootSpanImpl(tracer); |
| 158 | + describe('end() before end all spans', () => { |
| 159 | + it('should end all spans inside rootspan', () => { |
| 160 | + const root = new RootSpanImpl(tracer); |
109 | 161 | root.start(); |
| 162 | + const span = root.startSpan('spanName', 'spanType'); |
110 | 163 | root.end(); |
111 | | - let span = root.startSpan('spanName', 'spanType'); |
112 | | - assert.ok(span == null); |
| 164 | + |
| 165 | + for (const span of root.spans) { |
| 166 | + assert.ok(span.ended); |
| 167 | + } |
113 | 168 | }); |
114 | 169 | }); |
115 | 170 | }); |
0 commit comments