minimize number of so fild asserted in tests. it creates flakines when implementation details change (#97374) (#97379)

# Conflicts:
#	test/plugin_functional/test_suites/saved_objects_management/find.ts
This commit is contained in:
Mikhail Shustov 2021-04-16 22:44:23 +02:00 committed by GitHub
parent ded0d670d1
commit 7e97b438a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 211 deletions

View file

@ -9,7 +9,6 @@
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');
@ -17,12 +16,6 @@ export default function ({ getService }: FtrProviderContext) {
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'));
@ -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();
}));
@ -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();
}));
});
@ -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'] },
]);
}));
});
@ -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 () =>

View file

@ -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', () => {

View file

@ -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.',
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',
},
references: [],
updated_at: '2021-02-11T18:51:23.794Z',
namespaces: ['default'],
score: 0,
meta: {
namespaceType: 'single',
},
});
]);
}));
it('returns empty response for non importableAndExportable types', async () =>
@ -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([]);
}));
});
});