Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
78fe8ef
[saved objects api] Support 6.x get by id
jbudz May 25, 2017
2c839cd
[saved objects api] Support 6.x deletes by id
jbudz May 26, 2017
c5f7c1e
[saved objects api] Support 6.x finds
jbudz May 30, 2017
f43c43e
[saved objects api] Support 6.x updates
jbudz Jun 12, 2017
933e4bb
[saved objects api] Support 6.x creates
jbudz Jun 12, 2017
fb8e39c
Cleanup
jbudz Jun 12, 2017
9ed5623
Cleanup
jbudz Jun 12, 2017
cf0fd7e
[saved objects client] Add tests for createIdQuery
jbudz Jun 14, 2017
2a71736
[saved objects client] Update tests
jbudz Jun 14, 2017
cae9a39
[saved objects client] Fix file path
jbudz Jun 19, 2017
a49446d
[saved object api] Add getDocType method
jbudz Jun 19, 2017
89fe573
[saved objects api] Export getDocType
jbudz Jun 19, 2017
19eac30
[saved objects api] Support 6.x bulk gets
jbudz Jun 21, 2017
4f4719e
[saved objects api] Support 6.x bulk creates
jbudz Jun 21, 2017
13325f7
Fix tests
jbudz Jun 21, 2017
5ecdf99
[api tests] Add multiple .kibana types archive
jbudz Jun 22, 2017
08b3380
[api tests] Init saved objects tests
jbudz Jun 22, 2017
c65ee27
[api tests] Add single .kibana types archive
jbudz Jun 22, 2017
6460bcf
[api tests] Init testing kibana indices under a single type
jbudz Jun 22, 2017
acd8f75
[api tests] Add saved object get and create tests
jbudz Jun 22, 2017
a284f33
[api integration] More saved object tests
jbudz Jun 23, 2017
ce3ee97
[api integration] More saved object tests
jbudz Jun 23, 2017
e6733b2
[api integration] More saved object tests
jbudz Jun 23, 2017
0f88216
[api integration] Fix lint error
jbudz Jun 26, 2017
3c37eec
[api integration] Add bulk get tests
jbudz Jun 26, 2017
aff06c2
[server tests] Fix bulk response check
jbudz Jun 26, 2017
42c8593
[saved objects api] Fix bulk create error check
jbudz Jun 27, 2017
7ffbb5d
[api fixtures] Add dynamic strict to single typed .kibana
jbudz Jun 27, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('importDashboards(req)', () => {
let requestStub;
beforeEach(() => {
requestStub = sinon.stub().returns(Promise.resolve({
responses: []
items: []
}));

req = {
Expand Down Expand Up @@ -47,10 +47,10 @@ describe('importDashboards(req)', () => {
expect(requestStub.args[0][1]).to.equal('bulk');
expect(requestStub.args[0][2]).to.eql({
body: [
{ create: { _type: 'dashboard', _id: 'dashboard-01' } },
{ panelJSON: '{}' },
{ create: { _type: 'visualization', _id: 'panel-01' } },
{ visState: '{}' }
{ create: { _type: 'doc', _id: 'dashboard-01' } },
{ dashboard: { panelJSON: '{}' }, type: 'dashboard' },
{ create: { _type: 'doc', _id: 'panel-01' } },
{ visualization: { visState: '{}' }, type: 'visualization' }
],
index: '.kibana'
});
Expand All @@ -64,10 +64,10 @@ describe('importDashboards(req)', () => {
expect(requestStub.args[0][1]).to.equal('bulk');
expect(requestStub.args[0][2]).to.eql({
body: [
{ index: { _type: 'dashboard', _id: 'dashboard-01' } },
{ panelJSON: '{}' },
{ index: { _type: 'visualization', _id: 'panel-01' } },
{ visState: '{}' }
{ index: { _type: 'doc', _id: 'dashboard-01' } },
{ dashboard: { panelJSON: '{}' }, type: 'dashboard' },
{ index: { _type: 'doc', _id: 'panel-01' } },
{ visualization: { visState: '{}' }, type: 'visualization' }
],
index: '.kibana'
});
Expand All @@ -81,8 +81,8 @@ describe('importDashboards(req)', () => {
expect(requestStub.args[0][1]).to.equal('bulk');
expect(requestStub.args[0][2]).to.eql({
body: [
{ create: { _type: 'dashboard', _id: 'dashboard-01' } },
{ panelJSON: '{}' }
{ create: { _type: 'doc', _id: 'dashboard-01' } },
{ dashboard: { panelJSON: '{}' }, type: 'dashboard' }
],
index: '.kibana'
});
Expand Down
138 changes: 102 additions & 36 deletions src/server/saved_objects/client/__tests__/saved_objects_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ describe('SavedObjectsClient', () => {

expect(args[0]).to.be('bulk');
expect(args[1].body).to.eql([
{ create: { _type: 'config', _id: 'one' } },
{ title: 'Test One' },
{ create: { _type: 'index-pattern', _id: 'two' } },
{ title: 'Test Two' }
{ create: { _type: 'doc', _id: 'one' } },
{ config: { title: 'Test One' }, type: 'config' },
{ create: { _type: 'doc', _id: 'two' } },
{ 'index-pattern': { title: 'Test Two' }, type: 'index-pattern' }
]);
});

Expand All @@ -116,10 +116,10 @@ describe('SavedObjectsClient', () => {

expect(args[0]).to.be('bulk');
expect(args[1].body).to.eql([
{ index: { _type: 'config', _id: 'one' } },
{ title: 'Test One' },
{ index: { _type: 'index-pattern', _id: 'two' } },
{ title: 'Test Two' }
{ index: { _type: 'doc', _id: 'one' } },
{ config: { title: 'Test One' }, type: 'config' },
{ index: { _type: 'doc', _id: 'two' } },
{ 'index-pattern': { title: 'Test Two' }, type: 'index-pattern' }
]);
});

Expand Down Expand Up @@ -208,7 +208,9 @@ describe('SavedObjectsClient', () => {

describe('#delete', () => {
it('throws notFound when ES is unable to find the document', (done) => {
callAdminCluster.returns(Promise.resolve({ found: false }));
callAdminCluster.returns(Promise.resolve({
deleted: 0
}));

savedObjectsClient.delete('index-pattern', 'logstash-*').then(() => {
done('failed');
Expand All @@ -224,12 +226,43 @@ describe('SavedObjectsClient', () => {
expect(callAdminCluster.calledOnce).to.be(true);

const args = callAdminCluster.getCall(0).args;
expect(args[0]).to.be('delete');
expect(args[0]).to.be('deleteByQuery');
expect(args[1]).to.eql({
type: 'index-pattern',
id: 'logstash-*',
refresh: 'wait_for',
index: '.kibana-test'
index: '.kibana-test',
body: {
version: true,
query: {
bool: {
should: [
{
ids: {
type: 'index-pattern',
values: 'logstash-*'
}
},
{
bool: {
must: [
{
term: {
id: {
value: 'logstash-*'
}
}
},
{
type: {
value: 'doc'
}
}
]
}
}
]
}
}
}
});
});
});
Expand Down Expand Up @@ -272,7 +305,23 @@ describe('SavedObjectsClient', () => {
const expectedQuery = {
bool: {
must: [{ match_all: {} }],
filter: [{ term: { _type: 'index-pattern' } }]
filter: [
{
bool: {
should: [
{
term: {
_type: 'index-pattern'
}
}, {
term: {
type: 'index-pattern'
}
}
]
}
}
]
}
};

Expand All @@ -294,11 +343,17 @@ describe('SavedObjectsClient', () => {
describe('#get', () => {
it('formats Elasticsearch response', async () => {
callAdminCluster.returns(Promise.resolve({
_id: 'logstash-*',
_type: 'index-pattern',
_version: 2,
_source: {
title: 'Testing'
hits: {
hits: [
{
_id: 'logstash-*',
_type: 'index-pattern',
_version: 2,
_source: {
title: 'Testing'
}
}
]
}
}));

Expand All @@ -325,10 +380,13 @@ describe('SavedObjectsClient', () => {
expect(callAdminCluster.calledOnce).to.be(true);

const options = callAdminCluster.getCall(0).args[1];
expect(options.body.docs).to.eql([
{ _type: 'config', _id: 'one' },
{ _type: 'index-pattern', _id: 'two' },
{ _type: undefined, _id: 'three' }
expect(options.body).to.eql([
{},
{ version: true, query: { bool: { should: [{ ids: { values: 'one', type: 'config' } }, { bool: { must: [{ term: { id: { value: 'one' } } }, { type: { value: 'doc' } }] } }] } } }, //eslint-disable-line max-len
{},
{ version: true, query: { bool: { should: [{ ids: { values: 'two', type: 'index-pattern' } }, { bool: { must: [{ term: { id: { value: 'two' } } }, { type: { value: 'doc' } }] } }] } } }, //eslint-disable-line max-len
{},
{ version: true, query: { bool: { should: [{ ids: { values: 'three' } }, { bool: { must: [{ term: { id: { value: 'three' } } }, { type: { value: 'doc' } }] } }] } } } //eslint-disable-line max-len
]);
});

Expand All @@ -341,17 +399,25 @@ describe('SavedObjectsClient', () => {

it('omits missed objects', async () => {
callAdminCluster.returns(Promise.resolve({
docs:[{
_type: 'config',
_id: 'bad',
found: false
}, {
_type: 'config',
_id: 'good',
found: true,
_version: 2,
_source: { title: 'Test' }
}]
responses: [
{
hits: {
hits: [
{
_id: 'good',
_type: 'doc',
_version: 2,
_source: {
type: 'config',
config: {
title: 'Test'
}
}
}
]
}
}
]
}));

const { saved_objects: savedObjects } = await savedObjectsClient.bulkGet(
Expand Down Expand Up @@ -412,10 +478,10 @@ describe('SavedObjectsClient', () => {

expect(args[0]).to.be('update');
expect(args[1]).to.eql({
type: 'index-pattern',
type: 'doc',
id: 'logstash-*',
version: undefined,
body: { doc: { title: 'Testing' } },
body: { doc: { 'index-pattern': { title: 'Testing' } } },
refresh: 'wait_for',
index: '.kibana-test'
});
Expand Down
16 changes: 14 additions & 2 deletions src/server/saved_objects/client/lib/__tests__/create_find_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ describe('createFindQuery', () => {
query: {
bool: {
filter: [{
term: {
_type: 'index-pattern'
bool: {
should: [
{
term: {
_type: 'index-pattern'
}
},
{
term: {
type: 'index-pattern'
}
}
]

}
}],
must: [{
Expand Down
47 changes: 47 additions & 0 deletions src/server/saved_objects/client/lib/__tests__/create_id_query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import expect from 'expect.js';
import { createIdQuery } from '../create_id_query';

describe('createIdQuery', () => {
it('takes an id and type', () => {
const query = createIdQuery({
id: 'foo',
type: 'bar'
});
const expectedQuery = {
version: true,
query: {
bool: {
should: [
{
ids: {
values: 'foo',
type: 'bar'
}
},
{
bool: {
must: [
{
term: {
id: {
value: 'foo'
}
}
},
{
type: {
value: 'doc'
}
}
]
}
}
]
}
}
};

expect(query).to.eql(expectedQuery);
});

});
37 changes: 37 additions & 0 deletions src/server/saved_objects/client/lib/__tests__/get_doc_type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import expect from 'expect.js';
import { getDocType } from '../get_doc_type';

describe('getDocType', () => {
it('gets the doc type from a legacy index', () => {
const legacyResponse = {
_index: '.kibana',
_type: 'config',
_id: '6.0.0-alpha2',
_score: 1,
_source: {
buildNum: 8467,
defaultIndex: '.kibana'
}
};

expect(getDocType(legacyResponse)).to.eql('config');
});

it('gets the doc type from a new index', () => {
const newResponse = {
_index: '.kibana',
_type: 'doc',
_id: 'AVzBOLGoIr2L3MkvUTRP',
_score: 1,
_source: {
type: 'config',
config: {
buildNum: 8467,
defaultIndex: '.kibana'
}
}
};

expect(getDocType(newResponse)).to.eql('config');
});
});
15 changes: 13 additions & 2 deletions src/server/saved_objects/client/lib/create_find_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ export function createFindQuery(options = {}) {

if (type) {
bool.filter.push({
term: {
_type: type
bool: {
should: [
{
term: {
_type: type
}
},
{
term: {
type
}
}
]
}
});
}
Expand Down
Loading