Skip to content

Commit

Permalink
[ftr/config] require servers.elasticsearch.port config (#126650)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer authored Mar 2, 2022
1 parent f724198 commit 0bb0211
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ export default function () {
captureLogOutput: false,
sendToCiStats: false,
},
servers: {
elasticsearch: {
port: 1234,
},
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ export default () => ({
mochaReporter: {
sendToCiStats: false,
},
servers: {
elasticsearch: {
port: 1234,
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
export default function () {
return {
testFiles: ['config.1'],
servers: {
elasticsearch: {
port: 1234,
},
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ export default async function ({ readConfigFile }) {

return {
testFiles: [...config1.get('testFiles'), 'config.2'],
servers: {
elasticsearch: {
port: 1234,
},
},
};
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ describe('Config', () => {
services: {
foo: () => 42,
},
servers: {
elasticsearch: {
port: 1234,
},
},
},
primary: true,
path: process.cwd(),
Expand Down
42 changes: 29 additions & 13 deletions packages/kbn-test/src/functional_test_runner/lib/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () =>
Expand Down Expand Up @@ -170,7 +184,9 @@ export const schema = Joi.object()
servers: Joi.object()
.keys({
kibana: urlPartsSchema(),
elasticsearch: urlPartsSchema(),
elasticsearch: urlPartsSchema({
requiredKeys: ['port'],
}),
})
.default(),

Expand Down

0 comments on commit 0bb0211

Please sign in to comment.