Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
Remove unnecessary fixtures, use simpler approach.
  • Loading branch information
treble-snake committed Mar 28, 2021
1 parent 448e3db commit e55f26b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 134 deletions.
16 changes: 0 additions & 16 deletions src/test/fixtures/ExtendingSpan.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/test/fixtures/ExtendingSpanContext.ts

This file was deleted.

85 changes: 0 additions & 85 deletions src/test/fixtures/NonExtendingSpan.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/test/fixtures/NonExtendingSpanContext.ts

This file was deleted.

33 changes: 18 additions & 15 deletions src/test/opentracing_api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import { expect } from 'chai';
import * as opentracing from '../index';
import MockContext from '../mock_tracer/mock_context';
import MockSpan from '../mock_tracer/mock_span';
import MockTracer from '../mock_tracer/mock_tracer';
import Span from '../span';
import SpanContext from '../span_context';
import {ExtendingSpan} from './fixtures/ExtendingSpan';
import {ExtendingSpanContext} from './fixtures/ExtendingSpanContext';
import {NonExtendingSpan} from './fixtures/NonExtendingSpan';
import {NonExtendingSpanContext} from './fixtures/NonExtendingSpanContext';

export function opentracingAPITests(): void {
describe('Opentracing API', () => {
Expand Down Expand Up @@ -92,28 +91,32 @@ export function opentracingAPITests(): void {
expect(ref).to.be.an('object');
});

it('gets context from custom non-extending span classes', () => {
const ctx = new SpanContext();
const span = new NonExtendingSpan(ctx) as unknown as Span;
it('should get context from custom extending span classes', () => {
const span = new MockSpan(new MockTracer());
const ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, span);
expect(ref.referencedContext()).to.equal(ctx);
expect(ref.referencedContext() instanceof SpanContext).to.equal(true);
});

it('gets context from custom extending span classes', () => {
it('should get context from custom non-extending span classes', () => {
const ctx = new SpanContext();
const span = new ExtendingSpan(ctx) as unknown as Span;
const ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, span);
const pseudoSpan = {
context: () => ctx
} as Span;
const ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, pseudoSpan);
expect(ref.referencedContext()).to.equal(ctx);
});

it('uses extending contexts', () => {
const ctx = new ExtendingSpanContext();
it('should use extending contexts', () => {
const ctx = new MockContext({} as MockSpan);
const ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, ctx);
expect(ref.referencedContext()).to.equal(ctx);
});

it('uses non-extending contexts', () => {
const ctx = new NonExtendingSpanContext();
it('should use non-extending contexts', () => {
const ctx = {
toTraceId: () => '',
toSpanId: () => ''
};
const ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, ctx);
expect(ref.referencedContext()).to.equal(ctx);
});
Expand Down

0 comments on commit e55f26b

Please sign in to comment.