Skip to content

Commit

Permalink
[QA] Add saved objects info svc (#96364)
Browse files Browse the repository at this point in the history
Add svc and fn to return saved object types in a given index,
defaulted to ".kibana" index.
  • Loading branch information
wayneseymour authored Apr 8, 2021
1 parent 4a54188 commit 9ec466e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/common/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { RetryProvider } from './retry';
import { RandomnessProvider } from './randomness';
import { SecurityServiceProvider } from './security';
import { EsDeleteAllIndicesProvider } from './es_delete_all_indices';
import { SavedObjectInfoProvider } from './saved_object_info';

export const services = {
deployment: DeploymentProvider,
Expand All @@ -26,4 +27,5 @@ export const services = {
randomness: RandomnessProvider,
security: SecurityServiceProvider,
esDeleteAllIndices: EsDeleteAllIndicesProvider,
savedObjectInfo: SavedObjectInfoProvider,
};
53 changes: 53 additions & 0 deletions test/common/services/saved_object_info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { Client } from '@elastic/elasticsearch';
import url from 'url';
import { Either, fromNullable, chain, getOrElse } from 'fp-ts/Either';
import { flow } from 'fp-ts/function';
import { FtrProviderContext } from '../ftr_provider_context';

const pluck = (key: string) => (obj: any): Either<Error, string> =>
fromNullable(new Error(`Missing ${key}`))(obj[key]);

const types = (node: string) => async (index: string = '.kibana') => {
let res: unknown;
try {
const { body } = await new Client({ node }).search({
index,
body: {
aggs: {
savedobjs: {
terms: {
field: 'type',
},
},
},
},
});

res = flow(
pluck('aggregations'),
chain(pluck('savedobjs')),
chain(pluck('buckets')),
getOrElse((err) => `${err.message}`)
)(body);
} catch (err) {
throw new Error(`Error while searching for saved object types: ${err}`);
}

return res;
};

export const SavedObjectInfoProvider: any = ({ getService }: FtrProviderContext) => {
const config = getService('config');

return {
types: types(url.format(config.get('servers.elasticsearch'))),
};
};
4 changes: 4 additions & 0 deletions test/functional/apps/discover/_discover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const savedObjectInfo = getService('savedObjectInfo');
const browser = getService('browser');
const log = getService('log');
const retry = getService('retry');
Expand All @@ -31,6 +32,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

await kibanaServer.savedObjects.clean({ types: ['search'] });
await kibanaServer.importExport.load('discover');
log.info(
`\n### SAVED OBJECT TYPES IN index: [.kibana]: \n\t${await savedObjectInfo.types()}`
);

// and load a set of makelogs data
await esArchiver.loadIfNeeded('logstash_functional');
Expand Down

0 comments on commit 9ec466e

Please sign in to comment.