Skip to content

Commit

Permalink
add FTR test
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Sep 7, 2021
1 parent 83c1bf9 commit 694ab57
Show file tree
Hide file tree
Showing 4 changed files with 838 additions and 0 deletions.
125 changes: 125 additions & 0 deletions test/api_integration/apis/saved_objects/delete_unknown_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* 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 expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

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

describe('/deprecations/_delete_unknown_types', () => {
before(async () => {
await esArchiver.emptyKibanaIndex();
await esArchiver.load(
'test/api_integration/fixtures/es_archiver/saved_objects/delete_unknown_types'
);
});

after(async () => {
await esArchiver.unload(
'test/api_integration/fixtures/es_archiver/saved_objects/delete_unknown_types'
);
});

const fetchIndexContent = async () => {
const { body } = await es.search<{ type: string }>({
index: '.kibana',
body: {
size: 100,
},
});
return body.hits.hits
.map((hit) => ({
type: hit._source!.type,
id: hit._id,
}))
.sort((a, b) => {
return a.id > b.id ? 1 : -1;
});
};

it('should return 200 with individual responses', async () => {
const beforeDelete = await fetchIndexContent();
expect(beforeDelete).to.eql([
{
id: 'dashboard:b70c7ae0-3224-11e8-a572-ffca06da1357',
type: 'dashboard',
},
{
id: 'index-pattern:8963ca30-3224-11e8-a572-ffca06da1357',
type: 'index-pattern',
},
{
id: 'search:960372e0-3224-11e8-a572-ffca06da1357',
type: 'search',
},
{
id: 'space:default',
type: 'space',
},
{
id: 'unknown-shareable-doc',
type: 'unknown-shareable-type',
},
{
id: 'unknown-type:unknown-doc',
type: 'unknown-type',
},
{
id: 'visualization:a42c0580-3224-11e8-a572-ffca06da1357',
type: 'visualization',
},
]);

await supertest
.post(`/internal/saved_objects/deprecations/_delete_unknown_types`)
.send({})
.expect(200)
.then((resp) => {
expect(resp.body).to.eql({ success: true });
});

for (let i = 0; i < 10; i++) {
const afterDelete = await fetchIndexContent();
// we're deleting with `wait_for_completion: false` and we don't surface
// the task ID in the API, so we're forced to use pooling for the FTR tests
if (afterDelete.map((obj) => obj.type).includes('unknown-type') && i < 10) {
await delay(1000);
continue;
}
expect(afterDelete).to.eql([
{
id: 'dashboard:b70c7ae0-3224-11e8-a572-ffca06da1357',
type: 'dashboard',
},
{
id: 'index-pattern:8963ca30-3224-11e8-a572-ffca06da1357',
type: 'index-pattern',
},
{
id: 'search:960372e0-3224-11e8-a572-ffca06da1357',
type: 'search',
},
{
id: 'space:default',
type: 'space',
},
{
id: 'visualization:a42c0580-3224-11e8-a572-ffca06da1357',
type: 'visualization',
},
]);
break;
}
});
});
}
1 change: 1 addition & 0 deletions test/api_integration/apis/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./resolve'));
loadTestFile(require.resolve('./resolve_import_errors'));
loadTestFile(require.resolve('./update'));
loadTestFile(require.resolve('./delete_unknown_types'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"type": "doc",
"value": {
"id": "index-pattern:8963ca30-3224-11e8-a572-ffca06da1357",
"index": ".kibana",
"source": {
"coreMigrationVersion": "7.14.0",
"index-pattern": {
"fields": "[{\"name\":\"_id\",\"type\":\"string\",\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"name\":\"_index\",\"type\":\"string\",\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"name\":\"_score\",\"type\":\"number\",\"count\":0,\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"name\":\"_source\",\"type\":\"_source\",\"count\":0,\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"name\":\"_type\",\"type\":\"string\",\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"name\":\"id\",\"type\":\"number\",\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true}]",
"title": "saved_objects*"
},
"migrationVersion": {
"index-pattern": "7.11.0"
},
"references": [
],
"type": "index-pattern",
"updated_at": "2018-03-28T01:08:34.290Z"
},
"type": "_doc"
}
}

{
"type": "doc",
"value": {
"id": "search:960372e0-3224-11e8-a572-ffca06da1357",
"index": ".kibana",
"source": {
"coreMigrationVersion": "7.14.0",
"migrationVersion": {
"search": "7.9.3"
},
"references": [
{
"id": "8963ca30-3224-11e8-a572-ffca06da1357",
"name": "kibanaSavedObjectMeta.searchSourceJSON.index",
"type": "index-pattern"
}
],
"search": {
"columns": [
"_source"
],
"description": "",
"hits": 0,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"highlightAll\":true,\"version\":true,\"query\":{\"query\":\"id:3\",\"language\":\"lucene\"},\"filter\":[],\"indexRefName\":\"kibanaSavedObjectMeta.searchSourceJSON.index\"}"
},
"sort": [
[
"_score",
"desc"
]
],
"title": "OneRecord",
"version": 1
},
"type": "search",
"updated_at": "2018-03-28T01:08:55.182Z"
},
"type": "_doc"
}
}

{
"type": "doc",
"value": {
"id": "visualization:a42c0580-3224-11e8-a572-ffca06da1357",
"index": ".kibana",
"source": {
"coreMigrationVersion": "7.14.0",
"migrationVersion": {
"visualization": "7.14.0"
},
"references": [
{
"id": "960372e0-3224-11e8-a572-ffca06da1357",
"name": "search_0",
"type": "search"
}
],
"type": "visualization",
"updated_at": "2018-03-28T01:09:18.936Z",
"visualization": {
"description": "",
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"filter\":[],\"query\":{\"query\":\"\",\"language\":\"lucene\"}}"
},
"savedSearchRefName": "search_0",
"title": "VisualizationFromSavedSearch",
"uiStateJSON": "{\"vis\":{\"params\":{\"sort\":{\"columnIndex\":null,\"direction\":null}}}}",
"version": 1,
"visState": "{\"title\":\"VisualizationFromSavedSearch\",\"type\":\"table\",\"params\":{\"perPage\":10,\"showPartialRows\":false,\"showMeticsAtAllLevels\":false,\"sort\":{\"columnIndex\":null,\"direction\":null},\"showTotal\":false,\"totalFunc\":\"sum\",\"showToolbar\":true},\"aggs\":[{\"id\":\"1\",\"enabled\":true,\"type\":\"count\",\"schema\":\"metric\",\"params\":{}}]}"
}
},
"type": "_doc"
}
}

{
"type": "doc",
"value": {
"id": "dashboard:b70c7ae0-3224-11e8-a572-ffca06da1357",
"index": ".kibana",
"source": {
"coreMigrationVersion": "7.14.0",
"dashboard": {
"description": "",
"hits": 0,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"query\":{\"query\":\"\",\"language\":\"lucene\"},\"filter\":[],\"highlightAll\":true,\"version\":true}"
},
"optionsJSON": "{\"darkTheme\":false,\"useMargins\":true,\"hidePanelTitles\":false}",
"panelsJSON": "[{\"version\":\"7.0.0-alpha1\",\"gridData\":{\"w\":24,\"h\":15,\"x\":0,\"y\":0,\"i\":\"1\"},\"panelIndex\":\"1\",\"embeddableConfig\":{\"enhancements\":{}},\"panelRefName\":\"panel_0\"},{\"version\":\"7.0.0-alpha1\",\"gridData\":{\"w\":24,\"h\":15,\"x\":24,\"y\":0,\"i\":\"2\"},\"panelIndex\":\"2\",\"embeddableConfig\":{\"enhancements\":{}},\"panelRefName\":\"panel_1\"}]",
"timeRestore": false,
"title": "Dashboard",
"version": 1
},
"migrationVersion": {
"dashboard": "7.14.0"
},
"references": [
{
"id": "add810b0-3224-11e8-a572-ffca06da1357",
"name": "panel_0",
"type": "visualization"
},
{
"id": "a42c0580-3224-11e8-a572-ffca06da1357",
"name": "panel_1",
"type": "visualization"
}
],
"type": "dashboard",
"updated_at": "2018-03-28T01:09:50.606Z"
},
"type": "_doc"
}
}


{
"type": "doc",
"value": {
"id": "unknown-type:unknown-doc",
"index": ".kibana",
"source": {
"coreMigrationVersion": "7.14.0",
"unknown-type": {
"foo": "bar"
},
"migrationVersion": {},
"references": [
],
"type": "unknown-type",
"updated_at": "2018-03-28T01:08:34.290Z"
},
"type": "_doc"
}
}


{
"type": "doc",
"value": {
"id": "unknown-shareable-doc",
"index": ".kibana",
"source": {
"coreMigrationVersion": "7.14.0",
"unknown-shareable-type": {
"foo": "bar"
},
"migrationVersion": {},
"references": [
],
"type": "unknown-shareable-type",
"updated_at": "2018-03-28T01:08:34.290Z"
},
"type": "_doc"
}
}
Loading

0 comments on commit 694ab57

Please sign in to comment.