-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Code] Add api test for multi code node setup
- Loading branch information
spacedragon
committed
Feb 19, 2019
1 parent
7018e64
commit a2277c0
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters