-
Notifications
You must be signed in to change notification settings - Fork 826
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(otlp-exporter-base): test config functions
- Loading branch information
1 parent
5de03f0
commit 2b185dc
Showing
7 changed files
with
647 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...tal/packages/otlp-exporter-base/test/common/configuration/otlp-http-configuration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { | ||
mergeOtlpHttpConfigurationWithDefaults, | ||
OtlpHttpConfiguration, | ||
} from '../../../src/configuration/otlp-http-configuration'; | ||
import * as assert from 'assert'; | ||
import { testSharedConfigBehavior } from './shared-configuration.test'; | ||
|
||
describe('mergeOtlpHttpConfigurationWithDefaults', function () { | ||
const testDefaults: OtlpHttpConfiguration = { | ||
url: 'default-url', | ||
timeoutMillis: 1, | ||
compression: 'none', | ||
concurrencyLimit: 2, | ||
headers: { 'User-Agent': 'default-user-agent' }, | ||
}; | ||
|
||
describe('headers', function () { | ||
it('merges headers instead of overriding', function () { | ||
const config = mergeOtlpHttpConfigurationWithDefaults( | ||
{ | ||
headers: { foo: 'user' }, | ||
}, | ||
{ | ||
headers: { foo: 'fallback', bar: 'fallback' }, | ||
}, | ||
testDefaults | ||
); | ||
assert.deepEqual(config.headers, { | ||
'User-Agent': 'default-user-agent', | ||
foo: 'user', | ||
bar: 'fallback', | ||
}); | ||
}); | ||
it('does not override default (required) header', function () { | ||
const config = mergeOtlpHttpConfigurationWithDefaults( | ||
{ | ||
headers: { 'User-Agent': 'custom' }, | ||
}, | ||
{ | ||
headers: { 'User-Agent': 'custom-fallback' }, | ||
}, | ||
{ | ||
url: 'default-url', | ||
timeoutMillis: 1, | ||
compression: 'none', | ||
concurrencyLimit: 2, | ||
headers: { 'User-Agent': 'default-user-agent' }, | ||
} | ||
); | ||
assert.deepEqual(config.headers, { | ||
'User-Agent': 'default-user-agent', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('url', function () { | ||
it('uses user provided url over fallback', () => { | ||
const config = mergeOtlpHttpConfigurationWithDefaults( | ||
{ | ||
url: 'https://example.com/user-provided', | ||
}, | ||
{ | ||
url: 'https://example.com/fallback', | ||
}, | ||
testDefaults | ||
); | ||
assert.deepEqual(config.url, 'https://example.com/user-provided'); | ||
}); | ||
it('uses fallback url over default', () => { | ||
const config = mergeOtlpHttpConfigurationWithDefaults( | ||
{}, | ||
{ | ||
url: 'https://example.com/fallback', | ||
}, | ||
testDefaults | ||
); | ||
assert.deepEqual(config.url, 'https://example.com/fallback'); | ||
}); | ||
it('uses default if none other are specified', () => { | ||
const config = mergeOtlpHttpConfigurationWithDefaults( | ||
{}, | ||
{}, | ||
testDefaults | ||
); | ||
assert.deepEqual(config.url, testDefaults.url); | ||
}); | ||
}); | ||
|
||
testSharedConfigBehavior( | ||
mergeOtlpHttpConfigurationWithDefaults, | ||
testDefaults | ||
); | ||
}); |
136 changes: 136 additions & 0 deletions
136
...mental/packages/otlp-exporter-base/test/common/configuration/shared-configuration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as assert from 'assert'; | ||
import { | ||
mergeOtlpSharedConfigurationWithDefaults, | ||
OtlpSharedConfiguration, | ||
} from '../../../src'; | ||
|
||
export function testSharedConfigBehavior<T extends OtlpSharedConfiguration>( | ||
sut: ( | ||
userProvidedConfiguration: Partial<OtlpSharedConfiguration>, | ||
fallbackConfiguration: Partial<OtlpSharedConfiguration>, | ||
defaultConfiguration: T | ||
) => OtlpSharedConfiguration, | ||
defaults: T | ||
): void { | ||
// copy so that we don't modify the original and pollute other tests. | ||
const testDefaults = Object.assign({}, defaults); | ||
|
||
testDefaults.timeoutMillis = 1; | ||
testDefaults.compression = 'none'; | ||
testDefaults.concurrencyLimit = 2; | ||
|
||
describe('timeout', function () { | ||
it('uses user provided timeout over fallback', () => { | ||
const config = sut( | ||
{ | ||
timeoutMillis: 222, | ||
}, | ||
{ | ||
timeoutMillis: 333, | ||
}, | ||
testDefaults | ||
); | ||
assert.deepEqual(config.timeoutMillis, 222); | ||
}); | ||
it('uses fallback timeout over default', () => { | ||
const config = sut( | ||
{}, | ||
{ | ||
timeoutMillis: 444, | ||
}, | ||
testDefaults | ||
); | ||
assert.deepEqual(config.timeoutMillis, 444); | ||
}); | ||
it('uses default if none other are specified', () => { | ||
const config = sut({}, {}, testDefaults); | ||
assert.deepEqual(config.timeoutMillis, testDefaults.timeoutMillis); | ||
}); | ||
|
||
it('throws when value is negative', function () { | ||
assert.throws(() => sut({ timeoutMillis: -1 }, {}, testDefaults)); | ||
}); | ||
}); | ||
|
||
describe('compression', function () { | ||
it('uses user provided compression over fallback', () => { | ||
const config = sut( | ||
{ | ||
compression: 'gzip', | ||
}, | ||
{ | ||
compression: 'none', | ||
}, | ||
testDefaults | ||
); | ||
assert.deepEqual(config.compression, 'gzip'); | ||
}); | ||
it('uses fallback compression over default', () => { | ||
const config = sut( | ||
{}, | ||
{ | ||
compression: 'gzip', | ||
}, | ||
testDefaults | ||
); | ||
assert.deepEqual(config.compression, 'gzip'); | ||
}); | ||
it('uses default if none other are specified', () => { | ||
const config = sut({}, {}, testDefaults); | ||
assert.deepEqual(config.compression, testDefaults.compression); | ||
}); | ||
}); | ||
|
||
describe('concurrency limit', function () { | ||
it('uses user provided limit over fallback', () => { | ||
const config = sut( | ||
{ | ||
concurrencyLimit: 20, | ||
}, | ||
{ | ||
concurrencyLimit: 40, | ||
}, | ||
testDefaults | ||
); | ||
assert.deepEqual(config.concurrencyLimit, 20); | ||
}); | ||
it('uses fallback limit over default', () => { | ||
const config = sut( | ||
{}, | ||
{ | ||
concurrencyLimit: 50, | ||
}, | ||
testDefaults | ||
); | ||
assert.deepEqual(config.concurrencyLimit, 50); | ||
}); | ||
it('uses default if none other are specified', () => { | ||
const config = sut({}, {}, testDefaults); | ||
assert.deepEqual(config.concurrencyLimit, testDefaults.concurrencyLimit); | ||
}); | ||
}); | ||
} | ||
|
||
describe('mergeOtlpSharedConfigurationWithDefaults', function () { | ||
testSharedConfigBehavior(mergeOtlpSharedConfigurationWithDefaults, { | ||
timeoutMillis: 1, | ||
compression: 'none', | ||
concurrencyLimit: 2, | ||
}); | ||
}); |
Oops, something went wrong.