-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add prod/dev config handling + loader tests
- Loading branch information
1 parent
3469894
commit ee3280c
Showing
7 changed files
with
187 additions
and
21 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
45 changes: 45 additions & 0 deletions
45
packages/kbn-apm-config-loader/src/config_loader.test.mocks.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,45 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
export const getConfigurationFilePathsMock = jest.fn(); | ||
jest.doMock('./utils/get_config_file_paths', () => ({ | ||
getConfigurationFilePaths: getConfigurationFilePathsMock, | ||
})); | ||
|
||
export const getConfigFromFilesMock = jest.fn(); | ||
jest.doMock('./utils/read_config', () => ({ | ||
getConfigFromFiles: getConfigFromFilesMock, | ||
})); | ||
|
||
export const applyConfigOverridesMock = jest.fn(); | ||
jest.doMock('./utils/apply_config_overrides', () => ({ | ||
applyConfigOverrides: applyConfigOverridesMock, | ||
})); | ||
|
||
export const ApmConfigurationMock = jest.fn(); | ||
jest.doMock('./config', () => ({ | ||
ApmConfiguration: ApmConfigurationMock, | ||
})); | ||
|
||
export const resetAllMocks = () => { | ||
getConfigurationFilePathsMock.mockReset(); | ||
getConfigFromFilesMock.mockReset(); | ||
applyConfigOverridesMock.mockReset(); | ||
ApmConfigurationMock.mockReset(); | ||
}; |
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,75 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you 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 | ||
* | ||
* http://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 { | ||
ApmConfigurationMock, | ||
applyConfigOverridesMock, | ||
getConfigFromFilesMock, | ||
getConfigurationFilePathsMock, | ||
resetAllMocks, | ||
} from './config_loader.test.mocks'; | ||
|
||
import { loadConfiguration } from './config_loader'; | ||
|
||
describe('loadConfiguration', () => { | ||
const argv = ['some', 'arbitrary', 'args']; | ||
const rootDir = '/root/dir'; | ||
const isDistributable = false; | ||
|
||
afterEach(() => { | ||
resetAllMocks(); | ||
}); | ||
|
||
it('calls `getConfigurationFilePaths` with the correct arguments', () => { | ||
loadConfiguration(argv, rootDir, isDistributable); | ||
expect(getConfigurationFilePathsMock).toHaveBeenCalledTimes(1); | ||
expect(getConfigurationFilePathsMock).toHaveBeenCalledWith(argv); | ||
}); | ||
|
||
it('calls `getConfigFromFiles` with the correct arguments', () => { | ||
const configPaths = ['/path/to/config', '/path/to/other/config']; | ||
getConfigurationFilePathsMock.mockReturnValue(configPaths); | ||
|
||
loadConfiguration(argv, rootDir, isDistributable); | ||
expect(getConfigFromFilesMock).toHaveBeenCalledTimes(1); | ||
expect(getConfigFromFilesMock).toHaveBeenCalledWith(configPaths); | ||
}); | ||
|
||
it('calls `applyConfigOverrides` with the correct arguments', () => { | ||
const config = { server: { uuid: 'uuid' } }; | ||
getConfigFromFilesMock.mockReturnValue(config); | ||
|
||
loadConfiguration(argv, rootDir, isDistributable); | ||
expect(applyConfigOverridesMock).toHaveBeenCalledTimes(1); | ||
expect(applyConfigOverridesMock).toHaveBeenCalledWith(config, argv); | ||
}); | ||
|
||
it('creates and return an `ApmConfiguration` instance', () => { | ||
const apmInstance = { apmInstance: true }; | ||
ApmConfigurationMock.mockImplementation(() => apmInstance); | ||
|
||
const config = { server: { uuid: 'uuid' } }; | ||
getConfigFromFilesMock.mockReturnValue(config); | ||
|
||
const instance = loadConfiguration(argv, rootDir, isDistributable); | ||
expect(ApmConfigurationMock).toHaveBeenCalledTimes(1); | ||
expect(ApmConfigurationMock).toHaveBeenCalledWith(rootDir, config, isDistributable); | ||
expect(instance).toBe(apmInstance); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
// There is an (incomplete) `AgentConfigOptions` type declared in node_modules/elastic-apm-node/index.d.ts | ||
// but it's not exported, and using ts tricks to retrieve the type via Parameters<ApmAgent['start']>[0] | ||
// causes errors in the generated .d.ts file because of esModuleInterop and the fact that the apm module | ||
// is just exporting an instance of the `ApmAgent` type. | ||
export type ApmAgentConfig = Record<string, any>; |
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