Skip to content

Commit

Permalink
minimize number of so fild asserted in tests. it creates flakines whe…
Browse files Browse the repository at this point in the history
…n implementation details change (#97374)

# Conflicts:
#	test/plugin_functional/test_suites/saved_objects_management/find.ts
  • Loading branch information
mshustov committed Apr 16, 2021
1 parent 948847c commit e60f948
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 211 deletions.
165 changes: 21 additions & 144 deletions test/api_integration/apis/saved_objects/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,13 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
import { SavedObject } from '../../../../src/core/server';
import { getKibanaVersion } from './lib/saved_objects_test_utils';

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

describe('find', () => {
let KIBANA_VERSION: string;

before(async () => {
KIBANA_VERSION = await getKibanaVersion(getService);
});

describe('with kibana index', () => {
before(() => esArchiver.load('saved_objects/basic'));
after(() => esArchiver.unload('saved_objects/basic'));
Expand All @@ -32,33 +25,9 @@ export default function ({ getService }: FtrProviderContext) {
.get('/api/saved_objects/_find?type=visualization&fields=title')
.expect(200)
.then((resp) => {
expect(resp.body).to.eql({
page: 1,
per_page: 20,
total: 1,
saved_objects: [
{
type: 'visualization',
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
version: 'WzE4LDJd',
attributes: {
title: 'Count of requests',
},
score: 0,
migrationVersion: resp.body.saved_objects[0].migrationVersion,
coreMigrationVersion: KIBANA_VERSION,
namespaces: ['default'],
references: [
{
id: '91200a00-9efd-11e7-acb3-3dab96693fab',
name: 'kibanaSavedObjectMeta.searchSourceJSON.index',
type: 'index-pattern',
},
],
updated_at: '2017-09-21T18:51:23.794Z',
},
],
});
expect(resp.body.saved_objects.map((so: { id: string }) => so.id)).to.eql([
'dd7caf20-9efd-11e7-acb3-3dab96693fab',
]);
expect(resp.body.saved_objects[0].migrationVersion).to.be.ok();
}));

Expand Down Expand Up @@ -129,33 +98,12 @@ export default function ({ getService }: FtrProviderContext) {
.get('/api/saved_objects/_find?type=visualization&fields=title&namespaces=default')
.expect(200)
.then((resp) => {
expect(resp.body).to.eql({
page: 1,
per_page: 20,
total: 1,
saved_objects: [
{
type: 'visualization',
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
version: 'WzE4LDJd',
attributes: {
title: 'Count of requests',
},
migrationVersion: resp.body.saved_objects[0].migrationVersion,
coreMigrationVersion: KIBANA_VERSION,
namespaces: ['default'],
score: 0,
references: [
{
id: '91200a00-9efd-11e7-acb3-3dab96693fab',
name: 'kibanaSavedObjectMeta.searchSourceJSON.index',
type: 'index-pattern',
},
],
updated_at: '2017-09-21T18:51:23.794Z',
},
],
});
expect(
resp.body.saved_objects.map((so: { id: string; namespaces: string[] }) => ({
id: so.id,
namespaces: so.namespaces,
}))
).to.eql([{ id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab', namespaces: ['default'] }]);
expect(resp.body.saved_objects[0].migrationVersion).to.be.ok();
}));
});
Expand All @@ -166,53 +114,15 @@ export default function ({ getService }: FtrProviderContext) {
.get('/api/saved_objects/_find?type=visualization&fields=title&namespaces=*')
.expect(200)
.then((resp) => {
expect(resp.body).to.eql({
page: 1,
per_page: 20,
total: 2,
saved_objects: [
{
type: 'visualization',
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
version: 'WzE4LDJd',
attributes: {
title: 'Count of requests',
},
migrationVersion: resp.body.saved_objects[0].migrationVersion,
coreMigrationVersion: KIBANA_VERSION,
namespaces: ['default'],
score: 0,
references: [
{
id: '91200a00-9efd-11e7-acb3-3dab96693fab',
name: 'kibanaSavedObjectMeta.searchSourceJSON.index',
type: 'index-pattern',
},
],
updated_at: '2017-09-21T18:51:23.794Z',
},
{
attributes: {
title: 'Count of requests',
},
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
migrationVersion: resp.body.saved_objects[0].migrationVersion,
coreMigrationVersion: KIBANA_VERSION,
namespaces: ['foo-ns'],
references: [
{
id: '91200a00-9efd-11e7-acb3-3dab96693fab',
name: 'kibanaSavedObjectMeta.searchSourceJSON.index',
type: 'index-pattern',
},
],
score: 0,
type: 'visualization',
updated_at: '2017-09-21T18:51:23.794Z',
version: 'WzIyLDJd',
},
],
});
expect(
resp.body.saved_objects.map((so: { id: string; namespaces: string[] }) => ({
id: so.id,
namespaces: so.namespaces,
}))
).to.eql([
{ id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab', namespaces: ['default'] },
{ id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab', namespaces: ['foo-ns'] },
]);
}));
});

Expand All @@ -224,42 +134,9 @@ export default function ({ getService }: FtrProviderContext) {
)
.expect(200)
.then((resp) => {
expect(resp.body).to.eql({
page: 1,
per_page: 20,
total: 1,
saved_objects: [
{
type: 'visualization',
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
attributes: {
title: 'Count of requests',
visState: resp.body.saved_objects[0].attributes.visState,
uiStateJSON: '{"spy":{"mode":{"name":null,"fill":false}}}',
description: '',
version: 1,
kibanaSavedObjectMeta: {
searchSourceJSON:
resp.body.saved_objects[0].attributes.kibanaSavedObjectMeta
.searchSourceJSON,
},
},
namespaces: ['default'],
score: 0,
references: [
{
name: 'kibanaSavedObjectMeta.searchSourceJSON.index',
type: 'index-pattern',
id: '91200a00-9efd-11e7-acb3-3dab96693fab',
},
],
migrationVersion: resp.body.saved_objects[0].migrationVersion,
coreMigrationVersion: KIBANA_VERSION,
updated_at: '2017-09-21T18:51:23.794Z',
version: 'WzE4LDJd',
},
],
});
expect(resp.body.saved_objects.map((so: { id: string }) => so.id)).to.eql([
'dd7caf20-9efd-11e7-acb3-3dab96693fab',
]);
}));

it('wrong type should return 400 with Bad Request', async () =>
Expand Down
41 changes: 3 additions & 38 deletions test/api_integration/apis/saved_objects_management/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,9 @@ export default function ({ getService }: FtrProviderContext) {
.get('/api/kibana/management/saved_objects/_find?type=visualization&fields=title')
.expect(200)
.then((resp: Response) => {
expect(resp.body).to.eql({
page: 1,
per_page: 20,
total: 1,
saved_objects: [
{
type: 'visualization',
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
version: 'WzE4LDJd',
attributes: {
title: 'Count of requests',
},
migrationVersion: resp.body.saved_objects[0].migrationVersion,
coreMigrationVersion: KIBANA_VERSION,
namespaces: ['default'],
references: [
{
id: '91200a00-9efd-11e7-acb3-3dab96693fab',
name: 'kibanaSavedObjectMeta.searchSourceJSON.index',
type: 'index-pattern',
},
],
score: 0,
updated_at: '2017-09-21T18:51:23.794Z',
meta: {
editUrl:
'/management/kibana/objects/savedVisualizations/dd7caf20-9efd-11e7-acb3-3dab96693fab',
icon: 'visualizeApp',
inAppUrl: {
path: '/app/visualize#/edit/dd7caf20-9efd-11e7-acb3-3dab96693fab',
uiCapabilitiesPath: 'visualize.show',
},
title: 'Count of requests',
namespaceType: 'single',
},
},
],
});
expect(resp.body.saved_objects.map((so: { id: string }) => so.id)).to.eql([
'dd7caf20-9efd-11e7-acb3-3dab96693fab',
]);
}));

describe('unknown type', () => {
Expand Down
40 changes: 11 additions & 29 deletions test/plugin_functional/test_suites/saved_objects_management/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,17 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
.set('kbn-xsrf', 'true')
.expect(200)
.then((resp) => {
const { saved_objects: savedObjects, ...paginationDetails } = resp.body;
expect(paginationDetails).to.eql({
page: 1,
per_page: 20,
total: 1,
});

expect(savedObjects.length).to.be(1);
const { version, coreMigrationVersion, ...savedObjectDetails } = savedObjects[0];

expect(savedObjectDetails).to.eql({
type: 'test-hidden-importable-exportable',
id: 'ff3733a0-9fty-11e7-ahb3-3dcb94193fab',
attributes: {
title: 'Hidden Saved object type that is importable/exportable.',
},
references: [],
updated_at: '2021-02-11T18:51:23.794Z',
namespaces: ['default'],
score: 0,
meta: {
namespaceType: 'single',
expect(
resp.body.saved_objects.map((so: { id: string; type: string }) => ({
id: so.id,
type: so.type,
}))
).to.eql([
{
type: 'test-hidden-importable-exportable',
id: 'ff3733a0-9fty-11e7-ahb3-3dcb94193fab',
},
});
]);
}));

it('returns empty response for non importableAndExportable types', async () =>
Expand All @@ -67,12 +54,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
.set('kbn-xsrf', 'true')
.expect(200)
.then((resp) => {
expect(resp.body).to.eql({
page: 1,
per_page: 20,
total: 0,
saved_objects: [],
});
expect(resp.body.saved_objects).to.eql([]);
}));
});
});
Expand Down

0 comments on commit e60f948

Please sign in to comment.