Skip to content

Commit

Permalink
[Code] Add api test for multi code node setup
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedragon committed Feb 19, 2019
1 parent 7018e64 commit a2277c0
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
12 changes: 12 additions & 0 deletions x-pack/test/api_integration/apis/code/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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.
*/

// tslint:disable-next-line:no-default-export
export default function({ loadTestFile }) {
describe('Code', () => {
loadTestFile(require.resolve('./multi_node'));
});
}
85 changes: 85 additions & 0 deletions x-pack/test/api_integration/apis/code/multi_node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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 {
esTestConfig,
// @ts-ignore: implicit any for JS file
} from '@kbn/test';
import { pick } from 'lodash';
import { resolve } from 'path';
import supertest from 'supertest';
import { format as formatUrl } from 'url';
import { Root } from '../../../../../src/core/server/root';
import { createRootWithCorePlugins } from '../../../../../src/test_utils/kbn_server';

const multinodeTest = ({ getService }) => {
describe('code in multiple nodes', () => {
const supertestForCodeNode: supertest.SuperTest<supertest.Test> = getService('supertest');
let root: Root;
let supertestForNonCode: {
get(url: string): supertest.Test;
post(url: string): supertest.Test;
put(url: string): supertest.Test;
delete(url: string): supertest.Test;
};

async function startNonCodeNodeKibana() {
const username = esTestConfig.getUrlParts().username;
const password = esTestConfig.getUrlParts().password;
const setting = {
plugins: { paths: [resolve(__dirname, '../../../../../x-pack')] },
elasticsearch: {
username,
password,
},
xpack: {
code: { codeNode: false },
},
};
root = createRootWithCorePlugins(setting);
await root.start();
const st = supertest((root as any).server.http.service.httpServer.server.listener);
const testUserCredentials = Buffer.from(`${username}:${password}`);
const authorization = `Basic ${testUserCredentials.toString('base64')}`;
supertestForNonCode = {
get: url => st.get(url).set('Authorization', authorization),
post: url => st.post(url).set('Authorization', authorization),
delete: url => st.delete(url).set('Authorization', authorization),
put: url => st.put(url).set('Authorization', authorization),
};
}

before(startNonCodeNodeKibana);

after(() => root.shutdown());

it('Code node setup should be ok', async () => {
await supertestForCodeNode.get('/api/code/setup').expect(200);
});
it('Non-code node setup should be ok', async () => {
await supertestForNonCode.get('/api/code/setup').expect(200);
});
it('cluster uuid should equals Code node uuid', async () => {
const config = getService('config');
const serverArgs: string[] = config.get('kbnTestServer.serverArgs');
const argsUuid = '--server.uuid=';
const uuidLine = serverArgs.find(s => s.startsWith(argsUuid));
const uuid = uuidLine.substring(argsUuid.length);
const url = formatUrl(pick(config.get('servers.kibana'), ['protocol', 'port', 'hostname']));
await supertestForCodeNode.get('/api/code/cluster').expect(200, {
uuid,
url,
});
await supertestForNonCode.get('/api/code/cluster').expect(200, {
uuid,
url,
});
});
});
};

// tslint:disable-next-line no-default-export
export default multinodeTest;
2 changes: 2 additions & 0 deletions x-pack/test/api_integration/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ export default async function ({ readConfigFile }) {
...xPackFunctionalTestsConfig.get('kbnTestServer'),
serverArgs: [
...xPackFunctionalTestsConfig.get('kbnTestServer.serverArgs'),
'--server.uuid=5b2de169-2785-441b-ae8c-186a1936b17d',
'--optimize.enabled=false',
'--xpack.code.codeNode="true"'
],
},
esTestCluster: xPackFunctionalTestsConfig.get('esTestCluster'),
Expand Down

0 comments on commit a2277c0

Please sign in to comment.