|
| 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 | +}); |
0 commit comments