-
Notifications
You must be signed in to change notification settings - Fork 8
OPDATA-7692 filter endpoints by env var initial commit #804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8d9adfe
b859bf4
7b165bb
9780cde
082564f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import test from 'ava' | ||
| import { Adapter, AdapterEndpoint } from '../../src/adapter' | ||
| import { LoggerFactoryProvider } from '../../src/util/logger' | ||
| import { NopTransport } from '../../src/util/testing-utils' | ||
|
|
||
| test.before(() => { | ||
| LoggerFactoryProvider.set() | ||
| }) | ||
|
|
||
| const makeEndpoint = (name: string) => new AdapterEndpoint({ name, transport: new NopTransport() }) | ||
|
|
||
| test.afterEach(() => { | ||
| delete process.env['ENABLED_ENDPOINTS'] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleanup should go in This is more of an issue with jest where you can have before/afterEach apply to subsets of tests, but still a good rule of thumb to follow.
|
||
| }) | ||
|
|
||
| test('loads all endpoints when ENABLED_ENDPOINTS is not set', (t) => { | ||
| const adapter = new Adapter({ | ||
| name: 'TEST', | ||
| endpoints: [makeEndpoint('price'), makeEndpoint('volume')], | ||
| }) | ||
| t.is(adapter.endpoints.length, 2) | ||
| }) | ||
|
|
||
| test('filters to only the named endpoints', (t) => { | ||
| process.env['ENABLED_ENDPOINTS'] = 'price' | ||
| const adapter = new Adapter({ | ||
| name: 'TEST', | ||
| endpoints: [makeEndpoint('price'), makeEndpoint('volume')], | ||
| }) | ||
| t.is(adapter.endpoints.length, 1) | ||
| t.is(adapter.endpoints[0].name, 'price') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Combine these 2 lines into The error will be more useful than just the length not matching. |
||
| }) | ||
|
|
||
| test('trims whitespace and lowercases names in ENABLED_ENDPOINTS', (t) => { | ||
| process.env['ENABLED_ENDPOINTS'] = ' Price , VOLUME ' | ||
| const adapter = new Adapter({ | ||
| name: 'TEST', | ||
| endpoints: [makeEndpoint('price'), makeEndpoint('volume')], | ||
| }) | ||
| t.is(adapter.endpoints.length, 2) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
| }) | ||
|
|
||
| test('throws when no endpoints match ENABLED_ENDPOINTS', (t) => { | ||
| process.env['ENABLED_ENDPOINTS'] = 'nonexistent' | ||
| t.throws(() => new Adapter({ name: 'TEST', endpoints: [makeEndpoint('price')] }), { | ||
| message: /nonexistent/, | ||
| }) | ||
| }) | ||
|
|
||
| test('clears defaultEndpoint when it is excluded by ENABLED_ENDPOINTS', (t) => { | ||
| process.env['ENABLED_ENDPOINTS'] = 'volume' | ||
| const adapter = new Adapter({ | ||
| name: 'TEST', | ||
| defaultEndpoint: 'price', | ||
| endpoints: [makeEndpoint('price'), makeEndpoint('volume')], | ||
| }) | ||
| t.is(adapter.defaultEndpoint, undefined) | ||
| }) | ||
|
|
||
| test('keeps defaultEndpoint when it is included in ENABLED_ENDPOINTS', (t) => { | ||
| process.env['ENABLED_ENDPOINTS'] = 'price' | ||
| const adapter = new Adapter({ | ||
| name: 'TEST', | ||
| defaultEndpoint: 'price', | ||
| endpoints: [makeEndpoint('price'), makeEndpoint('volume')], | ||
| }) | ||
| t.is(adapter.defaultEndpoint, 'price') | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should throw if any of the listed endpoints don't match. That would be a mistake that you want to find out sooner rather than later.