test: move es proxy tests to api_integration (#14406)

Integration tests should go into the corresponding directory under
`test` and should use the appropriate testing framework that is designed
for long-running tests like those. Tests under __tests__ directories
should be fast-running unit tests only.
This commit is contained in:
Court Ewing 2017-10-11 13:59:03 -04:00
parent 2c8172d037
commit b50518f6fc
5 changed files with 99 additions and 116 deletions

View file

@ -1,116 +0,0 @@
import { format } from 'util';
import * as kbnTestServer from '../../../../test_utils/kbn_server';
import { createEsTestCluster } from '../../../../test_utils/es';
describe('plugins/elasticsearch', function () {
describe('routes', function () {
let kbnServer;
const es = createEsTestCluster({
name: 'core_plugins/es/routes',
});
before(async function () {
this.timeout(es.getStartTimeout());
await es.start();
kbnServer = kbnTestServer.createServerWithCorePlugins();
await kbnServer.ready();
await kbnServer.server.plugins.elasticsearch.waitUntilReady();
});
after(async function () {
await kbnServer.close();
await es.stop();
});
function testRoute(options, statusCode = 200) {
if (typeof options.payload === 'object') {
options.payload = JSON.stringify(options.payload);
}
describe(format('%s %s', options.method, options.url), function () {
it('should return ' + statusCode, function (done) {
kbnTestServer.makeRequest(kbnServer, options, function (res) {
if (res.statusCode === statusCode) {
done();
return;
}
done(new Error(`
Invalid response code from elasticseach:
${res.statusCode} should be ${statusCode}
Response:
${res.payload}
`));
});
});
});
}
testRoute({
method: 'GET',
url: '/elasticsearch/_nodes'
}, 404);
testRoute({
method: 'GET',
url: '/elasticsearch'
}, 404);
testRoute({
method: 'POST',
url: '/elasticsearch/.kibana'
}, 404);
testRoute({
method: 'PUT',
url: '/elasticsearch/.kibana'
}, 404);
testRoute({
method: 'DELETE',
url: '/elasticsearch/.kibana'
}, 404);
testRoute({
method: 'GET',
url: '/elasticsearch/.kibana'
}, 404);
testRoute({
method: 'POST',
url: '/elasticsearch/.kibana/_bulk',
payload: '{}'
}, 404);
testRoute({
method: 'POST',
url: '/elasticsearch/.kibana/__kibanaQueryValidator/_validate/query?explain=true&ignore_unavailable=true',
headers: {
'content-type': 'application/json'
},
payload: { query: { query_string: { analyze_wildcard: true, query: '*' } } }
}, 404);
testRoute({
method: 'POST',
url: '/elasticsearch/_mget',
headers: {
'content-type': 'application/json'
},
payload: { docs: [{ _index: '.kibana', _type: 'index-pattern', _id: '[logstash-]YYYY.MM.DD' }] }
}, 404);
testRoute({
method: 'POST',
url: '/elasticsearch/_msearch',
headers: {
'content-type': 'application/json'
},
payload: '{"index":"logstash-2015.04.21","ignore_unavailable":true}\n{"size":500,"sort":{"@timestamp":"desc"},"query":{"bool":{"must":[{"query_string":{"analyze_wildcard":true,"query":"*"}},{"bool":{"must":[{"range":{"@timestamp":{"gte":1429577068175,"lte":1429577968175}}}],"must_not":[]}}],"must_not":[]}},"highlight":{"pre_tags":["@kibana-highlighted-field@"],"post_tags":["@/kibana-highlighted-field@"],"fields":{"*":{}}},"aggs":{"2":{"date_histogram":{"field":"@timestamp","interval":"30s","min_doc_count":0,"extended_bounds":{"min":1429577068175,"max":1429577968175}}}},"stored_fields":["*"],"_source": true,"script_fields":{},"docvalue_fields":["timestamp_offset","@timestamp","utc_time"]}\n' // eslint-disable-line max-len
});
});
});

View file

@ -0,0 +1,83 @@
export default function ({ getService }) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
describe('elasticsearch', () => {
before(() => esArchiver.load('elasticsearch'));
after(() => esArchiver.unload('elasticsearch'));
it('allows search to specific index', async () => (
await supertest
.post('/elasticsearch/elasticsearch/_search')
.expect(200)
));
it('allows msearch', async () => (
await supertest
.post('/elasticsearch/_msearch')
.set('content-type', 'application/x-ndjson')
.send('{"index":"logstash-2015.04.21","ignore_unavailable":true}\n{"size":500,"sort":{"@timestamp":"desc"},"query":{"bool":{"must":[{"query_string":{"analyze_wildcard":true,"query":"*"}},{"bool":{"must":[{"range":{"@timestamp":{"gte":1429577068175,"lte":1429577968175}}}],"must_not":[]}}],"must_not":[]}},"highlight":{"pre_tags":["@kibana-highlighted-field@"],"post_tags":["@/kibana-highlighted-field@"],"fields":{"*":{}}},"aggs":{"2":{"date_histogram":{"field":"@timestamp","interval":"30s","min_doc_count":0,"extended_bounds":{"min":1429577068175,"max":1429577968175}}}},"stored_fields":["*"],"_source": true,"script_fields":{},"docvalue_fields":["timestamp_offset","@timestamp","utc_time"]}\n') // eslint-disable-line max-len
.expect(200)
));
it('rejects nodes API', async () => (
await supertest
.get('/elasticsearch/_nodes')
.expect(404)
));
it('rejects requests to root', async () => (
await supertest
.get('/elasticsearch')
.expect(404)
));
it('rejects POST to .kibana', async () => (
await supertest
.post('/elasticsearch/.kibana')
.expect(404)
));
it('rejects PUT to .kibana', async () => (
await supertest
.put('/elasticsearch/.kibana')
.expect(404)
));
it('rejects DELETE to .kibana', async () => (
await supertest
.delete('/elasticsearch/.kibana')
.expect(404)
));
it('rejects GET to .kibana', async () => (
await supertest
.get('/elasticsearch/.kibana')
.expect(404)
));
it('rejects bulk requests to .kibana', async () => (
await supertest
.post('/elasticsearch/.kibana/_bulk')
.set('content-type', 'application/json')
.send({})
.expect(404)
));
it('rejects validate API', async () => (
await supertest
.post('/elasticsearch/.kibana/__kibanaQueryValidator/_validate/query?explain=true&ignore_unavailable=true')
.set('content-type', 'application/json')
.send({ query: { query_string: { analyze_wildcard: true, query: '*' } } })
.expect(404)
));
it('rejects mget', async () => (
await supertest
.post('/elasticsearch/_mget')
.set('content-type', 'application/json')
.send({ docs: [{ _index: 'elasticsearch', _id: 'somedocid' }] })
.expect(404)
));
});
}

View file

@ -1,5 +1,6 @@
export default function ({ loadTestFile }) {
describe('apis', () => {
loadTestFile(require.resolve('./elasticsearch'));
loadTestFile(require.resolve('./index_patterns'));
loadTestFile(require.resolve('./saved_objects'));
loadTestFile(require.resolve('./scripts'));

View file

@ -0,0 +1,15 @@
{
"type": "index",
"value": {
"index": "elasticsearch",
"settings": {
"index": {
"number_of_shards": "5",
"number_of_replicas": "1"
}
},
"mappings": {
"doc": {}
}
}
}