kibana/x-pack/legacy/plugins/code/server/test_utils.ts
Mengwei Ding 2274421436
[Code] disk watermark check for clone and update (#42174) (#42383)
* [Code] disk watermark check

* apply disk check

* switch to one config

* Add i18n

* Add unit tests

* update i18n message id
2019-07-31 14:53:35 -07:00

74 lines
1.9 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import fs from 'fs';
import { Server } from 'hapi';
import * as os from 'os';
import path from 'path';
import { AnyObject } from './lib/esqueue';
import { ServerOptions } from './server_options';
import { ServerFacade } from '..';
// TODO migrate other duplicate classes, functions
export const emptyAsyncFunc = async (_: AnyObject): Promise<any> => {
Promise.resolve({});
};
const TEST_OPTIONS = {
enabled: true,
queueIndex: '.code_internal-worker-queue',
queueTimeoutMs: 60 * 60 * 1000, // 1 hour by default
updateFreqencyMs: 5 * 60 * 1000, // 5 minutes by default
indexFrequencyMs: 24 * 60 * 60 * 1000, // 1 day by default
lsp: {
requestTimeoutMs: 5 * 60, // timeout a request over 30s
detach: false,
verbose: false,
},
security: {
enableMavenImport: true,
enableGradleImport: true,
installNodeDependency: true,
enableGitCertCheck: true,
gitProtocolWhitelist: ['ssh', 'https', 'git'],
},
disk: {
thresholdEnabled: true,
watermarkLowMb: 100,
},
repos: [],
maxWorkspace: 5, // max workspace folder for each language server
};
export function createTestServerOption() {
const tmpDataPath = fs.mkdtempSync(path.join(os.tmpdir(), 'code_test'));
const config = {
get(key: string) {
if (key === 'path.data') {
return tmpDataPath;
}
},
};
return new ServerOptions(TEST_OPTIONS, config);
}
export function createTestHapiServer() {
const server: ServerFacade = new Server();
// @ts-ignore
server.config = () => {
return {
get(key: string) {
if (key === 'env.dev') return false;
else return true;
},
};
};
return server;
}