Skip to content

Commit

Permalink
[test/api_integration] migrate api tests to functional test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed May 16, 2017
1 parent ca328c3 commit c77ee5e
Show file tree
Hide file tree
Showing 23 changed files with 429 additions and 416 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"inert": "4.0.2",
"jade": "1.11.0",
"jade-loader": "0.7.1",
"joi": "6.6.1",
"joi": "10.4.1",
"jquery": "2.2.4",
"js-yaml": "3.4.1",
"json-loader": "0.5.3",
Expand Down Expand Up @@ -272,7 +272,7 @@
"source-map": "0.5.6",
"source-map-support": "0.2.10",
"strip-ansi": "^3.0.1",
"supertest": "1.2.0",
"supertest": "3.0.0",
"supertest-as-promised": "2.0.2",
"tree-kill": "1.1.0",
"webpack-dev-server": "1.14.1"
Expand Down
4 changes: 4 additions & 0 deletions tasks/config/esvm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module.exports = function (grunt) {
config: {
http: {
port: 9200
},
script: {
inline: true,
stored: true
}
}
},
Expand Down
6 changes: 0 additions & 6 deletions tasks/config/simplemocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,5 @@ module.exports = {
'!src/**/public/**',
'!**/_*.js'
]
},
api: {
src: [
'test/mocha_setup.js',
'test/unit/**/*.js'
]
}
};
6 changes: 6 additions & 0 deletions test/api_integration/apis/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function ({ loadTestFile }) {
describe('apis', () => {
loadTestFile(require.resolve('./scripts'));
loadTestFile(require.resolve('./search'));
});
}
5 changes: 5 additions & 0 deletions test/api_integration/apis/scripts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function ({ loadTestFile }) {
describe('scripts', () => {
loadTestFile(require.resolve('./languages'));
});
}
25 changes: 25 additions & 0 deletions test/api_integration/apis/scripts/languages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import expect from 'expect.js';

export default function ({ getService }) {
const supertest = getService('supertest');

describe('Script Languages API', function getLanguages() {
it('should return 200 with an array of languages', () => (
supertest.get('/api/kibana/scripts/languages')
.expect(200)
.then((response) => {
expect(response.body).to.be.an('array');
})
));

it('should only return langs enabled for inline scripting', () => (
supertest.get('/api/kibana/scripts/languages')
.expect(200)
.then((response) => {
expect(response.body).to.contain('expression');
expect(response.body).to.contain('painless');
expect(response.body).to.not.contain('groovy');
})
));
});
}
42 changes: 42 additions & 0 deletions test/api_integration/apis/search/count.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import expect from 'expect.js';

export default function ({ getService }) {
const esArchiver = getService('esArchiver');
const supertest = getService('supertest');

describe('Count API', function postIngest() {
before(() => esArchiver.load('search/count'));
after(() => esArchiver.unload('search/count'));

it('should return 200 with a document count for existing indices', () => (
supertest
.post('/api/kibana/foo-*/_count')
.expect(200)
.then((response) => {
expect(response.body.count).to.be(2);
})
));

it('should support GET requests as well', () => (
supertest
.get('/api/kibana/foo-*/_count')
.expect(200)
.then((response) => {
expect(response.body.count).to.be(2);
})
));

it('should return 404 if a pattern matches no indices', () => (
supertest
.post('/api/kibana/doesnotexist-*/_count')
.expect(404)
));

it('should return 404 if a concrete index does not exist', () => (
supertest
.post('/api/kibana/concrete/_count')
.expect(404)
));

});
}
5 changes: 5 additions & 0 deletions test/api_integration/apis/search/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function ({ loadTestFile }) {
describe('search', () => {
loadTestFile(require.resolve('./count'));
});
}
26 changes: 26 additions & 0 deletions test/api_integration/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { resolve } from 'path';

import {
SupertestProvider,
} from './services';

import { servers } from '../server_config';

export default async function ({ readConfigFile }) {
const commonConfig = await readConfigFile(require.resolve('../common/config'));

return {
testFiles: [
require.resolve('./apis'),
],
services: {
es: commonConfig.get('services.es'),
esArchiver: commonConfig.get('services.esArchiver'),
supertest: SupertestProvider,
},
servers,
esArchiver: {
directory: resolve(__dirname, './fixtures/es_archives')
},
};
}
Binary file not shown.

0 comments on commit c77ee5e

Please sign in to comment.