UNPKG

5.54 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var chai_1 = require("chai");
4var index_1 = require("../index");
5/**
6 * A function that takes a tracer factory, and tests wheter the initialized tracer
7 * fulfills Opentracing's api requirements.
8 *
9 * @param {object} createTracer - a factory function that allocates a tracer.
10 * @param {object} [options] - the options to be set on api compatibility
11 */
12function apiCompatibilityChecks(createTracer, options) {
13 if (createTracer === void 0) { createTracer = function () { return new index_1.Tracer(); }; }
14 if (options === void 0) { options = { skipBaggageChecks: false, skipInjectExtractChecks: false }; }
15 describe('OpenTracing API Compatibility', function () {
16 var tracer;
17 var span;
18 beforeEach(function () {
19 tracer = createTracer();
20 span = tracer.startSpan('test-span');
21 });
22 describe('Tracer', function () {
23 describe('startSpan', function () {
24 it('should handle Spans and SpanContexts', function () {
25 chai_1.expect(function () { tracer.startSpan('child', { childOf: span }); }).to.not.throw(Error);
26 chai_1.expect(function () { tracer.startSpan('child', { childOf: span.context() }); }).to.not.throw(Error);
27 });
28 });
29 describe('inject', function () {
30 (options.skipInjectExtractChecks ? it.skip : it)('should not throw exception on required carrier types', function () {
31 var spanContext = span.context();
32 var textCarrier = {};
33 var binCarrier = new index_1.BinaryCarrier([1, 2, 3]);
34 chai_1.expect(function () { tracer.inject(spanContext, index_1.FORMAT_TEXT_MAP, textCarrier); }).to.not.throw(Error);
35 chai_1.expect(function () { tracer.inject(spanContext, index_1.FORMAT_BINARY, binCarrier); }).to.not.throw(Error);
36 chai_1.expect(function () { tracer.inject(spanContext, index_1.FORMAT_BINARY, {}); }).to.not.throw(Error);
37 });
38 (options.skipInjectExtractChecks ? it.skip : it)('should handle Spans and SpanContexts', function () {
39 var textCarrier = {};
40 chai_1.expect(function () { tracer.inject(span, index_1.FORMAT_TEXT_MAP, textCarrier); }).to.not.throw(Error);
41 chai_1.expect(function () { tracer.inject(span.context(), index_1.FORMAT_TEXT_MAP, textCarrier); }).to.not.throw(Error);
42 });
43 });
44 describe('extract', function () {
45 (options.skipInjectExtractChecks ? it.skip : it)('should not throw exception on required carrier types', function () {
46 var textCarrier = {};
47 var binCarrier = new index_1.BinaryCarrier([1, 2, 3]);
48 chai_1.expect(function () { tracer.extract(index_1.FORMAT_TEXT_MAP, textCarrier); }).to.not.throw(Error);
49 chai_1.expect(function () { tracer.extract(index_1.FORMAT_BINARY, binCarrier); }).to.not.throw(Error);
50 chai_1.expect(function () { tracer.extract(index_1.FORMAT_BINARY, {}); }).to.not.throw(Error);
51 chai_1.expect(function () { tracer.extract(index_1.FORMAT_BINARY, { buffer: null }); }).to.not.throw(Error);
52 });
53 });
54 });
55 describe('Span', function () {
56 (options.skipBaggageChecks ? it.skip : it)('should set baggage and retrieve baggage', function () {
57 span.setBaggageItem('some-key', 'some-value');
58 var val = span.getBaggageItem('some-key');
59 chai_1.assert.equal('some-value', val);
60 });
61 describe('finish', function () {
62 it('should not throw exceptions on valid arguments', function () {
63 span = tracer.startSpan('test-span');
64 chai_1.expect(function () { return span.finish(Date.now()); }).to.not.throw(Error);
65 });
66 });
67 });
68 describe('Reference', function () {
69 it('should handle Spans and span.context()', function () {
70 chai_1.expect(function () { return new index_1.Reference(index_1.REFERENCE_CHILD_OF, span); }).to.not.throw(Error);
71 chai_1.expect(function () { return new index_1.Reference(index_1.REFERENCE_CHILD_OF, span.context()); }).to.not.throw(Error);
72 });
73 });
74 describe('SpanContext', function () {
75 describe('toTraceId', function () {
76 it('should return a string', function () {
77 span = tracer.startSpan('test-span');
78 console.log(span.context().toTraceId());
79 chai_1.expect(function () { return span.context().toTraceId(); }).to.not.throw(Error);
80 chai_1.expect(span.context().toTraceId()).to.be.a('string');
81 });
82 });
83 describe('toSpanId', function () {
84 it('should return a string', function () {
85 span = tracer.startSpan('test-span');
86 chai_1.expect(function () { return span.context().toSpanId(); }).to.not.throw(Error);
87 chai_1.expect(span.context().toSpanId()).to.be.a('string');
88 });
89 });
90 });
91 });
92}
93exports.default = apiCompatibilityChecks;
94//# sourceMappingURL=api_compatibility.js.map
\No newline at end of file