Commit 2b5b8c1a authored by inphi's avatar inphi

fix(cmn): BaseServiceV2 throws on camelCase options

parent 9ae0a566
...@@ -211,8 +211,15 @@ export abstract class BaseServiceV2< ...@@ -211,8 +211,15 @@ export abstract class BaseServiceV2<
// Since BCFG turns everything into lower case, we're required to turn all of the input option // Since BCFG turns everything into lower case, we're required to turn all of the input option
// names into lower case for the validation step. We'll turn the names back into their original // names into lower case for the validation step. We'll turn the names back into their original
// names when we're done. // names when we're done.
const lowerCaseOptions = Object.entries(params.options).reduce(
(acc, [key, val]) => {
acc[key.toLowerCase()] = val
return acc
},
{}
)
const cleaned = cleanEnv<TOptions>( const cleaned = cleanEnv<TOptions>(
{ ...config.env, ...config.args, ...(params.options || {}) }, { ...config.env, ...config.args, ...(lowerCaseOptions || {}) },
Object.entries(params.optionsSpec || {}).reduce((acc, [key, val]) => { Object.entries(params.optionsSpec || {}).reduce((acc, [key, val]) => {
acc[key.toLowerCase()] = val.validator({ acc[key.toLowerCase()] = val.validator({
desc: val.desc, desc: val.desc,
......
import { validators } from '../dist'
import { BaseServiceV2 } from '../src'
type ServiceOptions = {
camelCase: string
}
class Service extends BaseServiceV2<ServiceOptions, {}, {}> {
constructor(options?: Partial<ServiceOptions>) {
super({
name: 'test-service',
version: '0.0',
options,
optionsSpec: {
camelCase: { validator: validators.str, desc: 'test' },
},
metricsSpec: {},
})
}
protected async main() {
/* eslint-disable @typescript-eslint/no-empty-function */
}
}
describe('BaseServiceV2', () => {
it('base service ctor does not throw on camel case options', async () => {
// throws on error
new Service({ camelCase: 'test' })
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment