|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import * as assert from 'assert'; |
| 18 | +import * as Sinon from 'sinon'; |
18 | 19 | import { ConfigurationModel } from '../src'; |
19 | | -import { DiagLogLevel } from '@opentelemetry/api'; |
| 20 | +import { diag, DiagLogLevel } from '@opentelemetry/api'; |
20 | 21 | import { createConfigFactory } from '../src/ConfigFactory'; |
21 | 22 | import { OtlpHttpEncoding } from '../src/models/commonModel'; |
22 | 23 | import { |
@@ -751,6 +752,7 @@ describe('ConfigFactory', function () { |
751 | 752 | for (const [key, value] of Object.entries(_origEnvVariables)) { |
752 | 753 | process.env[key] = value; |
753 | 754 | } |
| 755 | + Sinon.restore(); |
754 | 756 | }); |
755 | 757 |
|
756 | 758 | describe('get values from environment variables', function () { |
@@ -1935,17 +1937,23 @@ describe('ConfigFactory', function () { |
1935 | 1937 | }); |
1936 | 1938 |
|
1937 | 1939 | it('should return error from invalid config file', function () { |
| 1940 | + const warnSpy = Sinon.spy(diag, 'warn'); |
1938 | 1941 | process.env.OTEL_EXPERIMENTAL_CONFIG_FILE = './fixtures/kitchen-sink.txt'; |
1939 | | - assert.throws(() => { |
1940 | | - createConfigFactory(); |
1941 | | - }); |
| 1942 | + createConfigFactory(); |
| 1943 | + Sinon.assert.calledWith( |
| 1944 | + warnSpy, |
| 1945 | + 'Config file ./fixtures/kitchen-sink.txt set on OTEL_EXPERIMENTAL_CONFIG_FILE is not valid' |
| 1946 | + ); |
1942 | 1947 | }); |
1943 | 1948 |
|
1944 | 1949 | it('should return error from invalid config file format', function () { |
| 1950 | + const warnSpy = Sinon.spy(diag, 'warn'); |
1945 | 1951 | process.env.OTEL_EXPERIMENTAL_CONFIG_FILE = 'test/fixtures/invalid.yaml'; |
1946 | | - assert.throws(() => { |
1947 | | - createConfigFactory(); |
1948 | | - }); |
| 1952 | + createConfigFactory(); |
| 1953 | + Sinon.assert.calledWith( |
| 1954 | + warnSpy, |
| 1955 | + 'Unsupported File Format: invalid. It must be one of the following: 1.0-rc.1,1.0-rc.2' |
| 1956 | + ); |
1949 | 1957 | }); |
1950 | 1958 |
|
1951 | 1959 | it('should initialize config with default values with empty string for config file', function () { |
|
0 commit comments