This repository has been archived by the owner on May 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from oibe/split_opentracing_compatibility_tests
Separated opentracing mock tracer tests from opentracing api
- Loading branch information
Showing
4 changed files
with
130 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// For the convenience of unit testing, add these to the global namespace | ||
var _ = require('underscore'); | ||
var expect = require('chai').expect; | ||
|
||
// Unit testing is done against the debug version of the library as it has | ||
// additional conformance checks that are optimized out of the production | ||
// library. Again, globals are used purely for convenience. | ||
var opentracing = require('../debug.js'); | ||
|
||
module.exports = function noopImplementationTests(_createTracer) { | ||
var createTracer = _createTracer || function() { return new opentracing.Tracer(); }; | ||
|
||
describe('Noop Tracer Implementation', function() { | ||
describe('Tracer#inject', function() { | ||
it('should enforce the required carrier types', function() { | ||
var tracer = createTracer(); | ||
var spanContext = tracer.startSpan('test_operation').context(); | ||
expect(function() { tracer.inject(spanContext, opentracing.FORMAT_TEXT_MAP, ''); }).to.throw(Error); | ||
expect(function() { tracer.inject(spanContext, opentracing.FORMAT_TEXT_MAP, 5); }).to.throw(Error); | ||
|
||
expect(function() { tracer.extract(opentracing.FORMAT_BINARY, { buffer : '' }); }).to.throw(Error); | ||
expect(function() { tracer.extract(opentracing.FORMAT_BINARY, { buffer : 5 }); }).to.throw(Error); | ||
}); | ||
|
||
it('should handle Spans and SpanContexts', function() { | ||
var tracer = createTracer(); | ||
var span = tracer.startSpan('test_operation'); | ||
var textCarrier = {}; | ||
expect(function() { tracer.inject(span, opentracing.FORMAT_TEXT_MAP, textCarrier); }).to.not.throw(Error); | ||
}); | ||
}); | ||
|
||
describe('Span#finish', function() { | ||
it('should return undefined', function() { | ||
var tracer = createTracer(); | ||
var span = tracer.startSpan('test_span'); | ||
expect(span.finish()).to.be.undefined; | ||
}); | ||
|
||
it('should only accept numbers as an argument', function() { | ||
var tracer = createTracer(); | ||
function f(arg) { | ||
return function() { | ||
var span = tracer.startSpan('test_span'); | ||
span.finish(arg); | ||
} | ||
} | ||
expect(f('1234567')).to.throw(Error); | ||
expect(f([])).to.throw(Error); | ||
expect(f({})).to.throw(Error); | ||
}); | ||
it('should throw an Error if given more than 1 argument', function() { | ||
var tracer = createTracer(); | ||
var span = tracer.startSpan('test_span'); | ||
expect(function() { span.finish(Date.now(), { extra : 123 }) }).to.be.throw(Error); | ||
}); | ||
}); | ||
|
||
describe('Miscellaneous', function() { | ||
describe('Memory usage', function() { | ||
it('should not report leaks after setting the global tracer', function() { | ||
opentracing.initGlobalTracer(createTracer()); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var _ = require('underscore'); | ||
var expect = require('chai').expect; | ||
var opentracing = require('../lib'); | ||
|
||
module.exports = function opentracingAPITests() { | ||
describe('Opentracing API', function() { | ||
describe('Constants', function() { | ||
var constStrings = [ | ||
'FORMAT_TEXT_MAP', | ||
'FORMAT_BINARY', | ||
'FORMAT_HTTP_HEADERS', | ||
'REFERENCE_CHILD_OF', | ||
'REFERENCE_FOLLOWS_FROM', | ||
]; | ||
_.each(constStrings, function(name) { | ||
it(name + ' should be a constant string', function() { | ||
expect(opentracing[name]).to.be.a('string'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Standalone functions', function() { | ||
var funcs = [ | ||
'childOf', | ||
'followsFrom', | ||
'initGlobalTracer', | ||
'globalTracer', | ||
|
||
]; | ||
_.each(funcs, function(name) { | ||
it(name + ' should be a function', function() { | ||
expect(opentracing[name]).to.be.a('function'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters