[ftr/startServers] resolve relative config arguments at CLI (#141450)

This commit is contained in:
Spencer 2022-09-22 11:00:30 -05:00 committed by GitHub
parent da8eb44f92
commit a5afcd7ae9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View file

@ -6,13 +6,19 @@
* Side Public License, v 1.
*/
import Path from 'path';
import { getFlags, FlagsReader } from '@kbn/dev-cli-runner';
import { createAnyInstanceSerializer, createAbsolutePathSerializer } from '@kbn/jest-serializers';
import { REPO_ROOT } from '@kbn/utils';
import { EsVersion } from '../../functional_test_runner';
import { parseFlags, FLAG_OPTIONS } from './flags';
jest.mock('uuid', () => ({ v4: () => 'some-uuid' }));
const cwdMock = (process.cwd = jest.fn().mockReturnValue(REPO_ROOT));
expect.addSnapshotSerializer(
createAnyInstanceSerializer(EsVersion, (v: EsVersion) => `EsVersion ${v.toString()}`)
);
@ -23,10 +29,27 @@ const defaults = getFlags(['--config=foo'], FLAG_OPTIONS);
const test = (opts: Record<string, string | string[] | boolean | undefined>) =>
parseFlags(new FlagsReader({ ...defaults, ...opts }));
beforeEach(() => {
cwdMock.mockReturnValue(REPO_ROOT);
});
it('parses a subset of the flags from runTests', () => {
expect(test({ config: 'foo' })).toMatchInlineSnapshot(`
Object {
"config": "foo",
"config": <absolute path>/foo,
"esFrom": undefined,
"esVersion": <EsVersion 9.9.9>,
"installDir": undefined,
"logsDir": undefined,
}
`);
});
it('respects the cwd of the script', () => {
cwdMock.mockReturnValue(Path.resolve(REPO_ROOT, 'x-pack'));
expect(test({ config: 'foo' })).toMatchInlineSnapshot(`
Object {
"config": <absolute path>/x-pack/foo,
"esFrom": undefined,
"esVersion": <EsVersion 9.9.9>,
"installDir": undefined,

View file

@ -31,8 +31,8 @@ export const FLAG_OPTIONS: FlagOptions = {
export function parseFlags(flags: FlagsReader) {
const configs = [
...(flags.arrayOfStrings('config') ?? []),
...(flags.arrayOfStrings('journey') ?? []),
...(flags.arrayOfPaths('config') ?? []),
...(flags.arrayOfPaths('journey') ?? []),
];
if (configs.length !== 1) {
throw createFlagError(`expected exactly one --config or --journey flag`);