|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 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 | + * https://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 * as assert from 'assert'; |
| 18 | +import * as context from '../../src/trace/spancontext-utils'; |
| 19 | +import { TraceFlags } from '../../src'; |
| 20 | + |
| 21 | +describe('spancontext-utils', () => { |
| 22 | + it('should return true for valid spancontext', () => { |
| 23 | + const spanContext = { |
| 24 | + traceId: 'd4cda95b652f4a1592b449d5929fda1b', |
| 25 | + spanId: '6e0c63257de34c92', |
| 26 | + traceFlags: TraceFlags.NONE, |
| 27 | + }; |
| 28 | + assert.ok(context.isSpanContextValid(spanContext)); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should return false when traceId is invalid', () => { |
| 32 | + const spanContext = { |
| 33 | + traceId: context.INVALID_TRACEID, |
| 34 | + spanId: '6e0c63257de34c92', |
| 35 | + traceFlags: TraceFlags.NONE, |
| 36 | + }; |
| 37 | + assert.ok(!context.isSpanContextValid(spanContext)); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should return false when spanId is invalid', () => { |
| 41 | + const spanContext = { |
| 42 | + traceId: 'd4cda95b652f4a1592b449d5929fda1b', |
| 43 | + spanId: context.INVALID_SPANID, |
| 44 | + traceFlags: TraceFlags.NONE, |
| 45 | + }; |
| 46 | + assert.ok(!context.isSpanContextValid(spanContext)); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should return false when traceId & spanId is invalid', () => { |
| 50 | + const spanContext = { |
| 51 | + traceId: context.INVALID_TRACEID, |
| 52 | + spanId: context.INVALID_SPANID, |
| 53 | + traceFlags: TraceFlags.NONE, |
| 54 | + }; |
| 55 | + assert.ok(!context.isSpanContextValid(spanContext)); |
| 56 | + }); |
| 57 | +}); |
0 commit comments