|
| 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 utils from '../src/utils'; |
| 18 | +import * as assert from 'assert'; |
| 19 | +import { KoaInstrumentationConfig, KoaLayerType } from '../src/types'; |
| 20 | + |
| 21 | +describe('Utils', () => { |
| 22 | + describe('isLayerIgnored()', () => { |
| 23 | + it('should not fail with invalid config', () => { |
| 24 | + assert.strictEqual(utils.isLayerIgnored(KoaLayerType.MIDDLEWARE), false); |
| 25 | + assert.strictEqual( |
| 26 | + utils.isLayerIgnored( |
| 27 | + KoaLayerType.MIDDLEWARE, |
| 28 | + {} as KoaInstrumentationConfig |
| 29 | + ), |
| 30 | + false |
| 31 | + ); |
| 32 | + assert.strictEqual( |
| 33 | + utils.isLayerIgnored(KoaLayerType.MIDDLEWARE, { |
| 34 | + ignoreLayersType: {}, |
| 35 | + } as KoaInstrumentationConfig), |
| 36 | + false |
| 37 | + ); |
| 38 | + assert.strictEqual( |
| 39 | + utils.isLayerIgnored(KoaLayerType.ROUTER, { |
| 40 | + ignoreLayersType: {}, |
| 41 | + } as KoaInstrumentationConfig), |
| 42 | + false |
| 43 | + ); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should ignore based on type', () => { |
| 47 | + assert.strictEqual( |
| 48 | + utils.isLayerIgnored(KoaLayerType.MIDDLEWARE, { |
| 49 | + ignoreLayersType: [KoaLayerType.MIDDLEWARE], |
| 50 | + }), |
| 51 | + true |
| 52 | + ); |
| 53 | + assert.strictEqual( |
| 54 | + utils.isLayerIgnored(KoaLayerType.ROUTER, { |
| 55 | + ignoreLayersType: [KoaLayerType.MIDDLEWARE], |
| 56 | + }), |
| 57 | + false |
| 58 | + ); |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments