|
| 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 | +import { stringToLogLevel } from '../../../src'; |
| 17 | +import * as assert from 'assert'; |
| 18 | +import * as sinon from 'sinon'; |
| 19 | +import { diag, DiagLogLevel } from '@opentelemetry/api'; |
| 20 | + |
| 21 | +describe('stringToLogLevel', function () { |
| 22 | + afterEach(function () { |
| 23 | + sinon.restore(); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should map valid string to log level', function () { |
| 27 | + assert.strictEqual(stringToLogLevel('ALL'), DiagLogLevel.ALL); |
| 28 | + assert.strictEqual(stringToLogLevel('VERBOSE'), DiagLogLevel.VERBOSE); |
| 29 | + assert.strictEqual(stringToLogLevel('DEBUG'), DiagLogLevel.DEBUG); |
| 30 | + assert.strictEqual(stringToLogLevel('INFO'), DiagLogLevel.INFO); |
| 31 | + assert.strictEqual(stringToLogLevel('WARN'), DiagLogLevel.WARN); |
| 32 | + assert.strictEqual(stringToLogLevel('ERROR'), DiagLogLevel.ERROR); |
| 33 | + assert.strictEqual(stringToLogLevel('NONE'), DiagLogLevel.NONE); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should ignore casing when resolving', function () { |
| 37 | + assert.strictEqual(stringToLogLevel('error'), DiagLogLevel.ERROR); |
| 38 | + assert.strictEqual(stringToLogLevel('eRRoR'), DiagLogLevel.ERROR); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should return undefined on undefined input', function () { |
| 42 | + assert.strictEqual(stringToLogLevel(undefined), undefined); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should return undefined on null input', function () { |
| 46 | + assert.strictEqual(stringToLogLevel(undefined), undefined); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should fall back to INFO and warn on input that cannot be mapped', function () { |
| 50 | + const warnStub = sinon.stub(diag, 'warn'); |
| 51 | + assert.strictEqual(stringToLogLevel('does not exist'), DiagLogLevel.INFO); |
| 52 | + sinon.assert.calledOnceWithMatch(warnStub, 'Unknown'); |
| 53 | + }); |
| 54 | +}); |
0 commit comments