[ftr/config] require servers.elasticsearch.port config (#126650)

This commit is contained in:
Spencer 2022-03-02 09:45:01 -06:00 committed by GitHub
parent f72419889f
commit 0bb021199e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 55 additions and 46 deletions

View file

@ -37,5 +37,10 @@ export default function () {
captureLogOutput: false,
sendToCiStats: false,
},
servers: {
elasticsearch: {
port: 1234,
},
},
};
}

View file

@ -13,4 +13,9 @@ export default () => ({
mochaReporter: {
sendToCiStats: false,
},
servers: {
elasticsearch: {
port: 1234,
},
},
});

View file

@ -61,7 +61,7 @@ describe('failure hooks', function () {
expect(tests).toHaveLength(0);
} catch (error) {
console.error('full log output', linesCopy.join('\n'));
error.message += `\n\nfull log output:${linesCopy.join('\n')}`;
throw error;
}
});

View file

@ -9,5 +9,10 @@
export default function () {
return {
testFiles: ['config.1'],
servers: {
elasticsearch: {
port: 1234,
},
},
};
}

View file

@ -11,5 +11,10 @@ export default async function ({ readConfigFile }) {
return {
testFiles: [...config1.get('testFiles'), 'config.2'],
servers: {
elasticsearch: {
port: 1234,
},
},
};
}

View file

@ -1,17 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
export default async function ({ readConfigFile }) {
const config4 = await readConfigFile(require.resolve('./config.4'));
return {
testFiles: ['baz'],
screenshots: {
...config4.get('screenshots'),
},
};
}

View file

@ -1,15 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
export default function () {
return {
screenshots: {
directory: 'bar',
},
};
}

View file

@ -15,6 +15,11 @@ describe('Config', () => {
services: {
foo: () => 42,
},
servers: {
elasticsearch: {
port: 1234,
},
},
},
primary: true,
path: process.cwd(),

View file

@ -17,19 +17,33 @@ const ID_PATTERN = /^[a-zA-Z0-9_]+$/;
// it will search both --inspect and --inspect-brk
const INSPECTING = !!process.execArgv.find((arg) => arg.includes('--inspect'));
const urlPartsSchema = () =>
const maybeRequireKeys = (keys: string[], schemas: Record<string, Joi.Schema>) => {
if (!keys.length) {
return schemas;
}
const withRequires: Record<string, Joi.Schema> = {};
for (const [key, schema] of Object.entries(schemas)) {
withRequires[key] = keys.includes(key) ? schema.required() : schema;
}
return withRequires;
};
const urlPartsSchema = ({ requiredKeys }: { requiredKeys?: string[] } = {}) =>
Joi.object()
.keys({
protocol: Joi.string().valid('http', 'https').default('http'),
hostname: Joi.string().hostname().default('localhost'),
port: Joi.number(),
auth: Joi.string().regex(/^[^:]+:.+$/, 'username and password separated by a colon'),
username: Joi.string(),
password: Joi.string(),
pathname: Joi.string().regex(/^\//, 'start with a /'),
hash: Joi.string().regex(/^\//, 'start with a /'),
certificateAuthorities: Joi.array().items(Joi.binary()).optional(),
})
.keys(
maybeRequireKeys(requiredKeys ?? [], {
protocol: Joi.string().valid('http', 'https').default('http'),
hostname: Joi.string().hostname().default('localhost'),
port: Joi.number(),
auth: Joi.string().regex(/^[^:]+:.+$/, 'username and password separated by a colon'),
username: Joi.string(),
password: Joi.string(),
pathname: Joi.string().regex(/^\//, 'start with a /'),
hash: Joi.string().regex(/^\//, 'start with a /'),
certificateAuthorities: Joi.array().items(Joi.binary()).optional(),
})
)
.default();
const appUrlPartsSchema = () =>
@ -170,7 +184,9 @@ export const schema = Joi.object()
servers: Joi.object()
.keys({
kibana: urlPartsSchema(),
elasticsearch: urlPartsSchema(),
elasticsearch: urlPartsSchema({
requiredKeys: ['port'],
}),
})
.default(),