Skip to content

Commit

Permalink
add FTR test
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Jun 4, 2021
1 parent 410980b commit b19882d
Show file tree
Hide file tree
Showing 4 changed files with 750 additions and 137 deletions.
40 changes: 10 additions & 30 deletions src/core/server/saved_objects/export/collect_exported_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface CollectExportedObjectOptions {
savedObjectsClient: SavedObjectsClientContract;
objects: SavedObject[];
/** flag to also include all related saved objects in the export stream. */
includeReferences: boolean;
includeReferences?: boolean;
/** optional namespace to override the namespace used by the savedObjectsClient. */
namespace?: string;
/** The http request initiating the export. */
Expand All @@ -32,7 +32,7 @@ interface CollectExportedObjectResult {

export const collectExportedObjects = async ({
objects,
includeReferences,
includeReferences = true,
namespace,
request,
exportTransforms,
Expand All @@ -44,12 +44,14 @@ export const collectExportedObjects = async ({

let currentObjects = objects;
do {
const transformed = await applyTransforms({
objects: currentObjects,
alreadyProcessed,
exportTransforms,
request,
});
const transformed = (
await applyExportTransforms({
request,
objects: currentObjects,
transforms: exportTransforms,
})
).filter((object) => !alreadyProcessed.has(objKey(object)));

transformed.forEach((obj) => alreadyProcessed.add(objKey(obj)));
collectedObjects.push(...transformed);

Expand Down Expand Up @@ -79,28 +81,6 @@ export const collectExportedObjects = async ({

const objKey = (obj: { type: string; id: string }) => `${obj.type}:${obj.id}`;

interface ProcessCurrentLevelOptions {
objects: SavedObject[];
alreadyProcessed: Set<string>;
request: KibanaRequest;
exportTransforms: Record<string, SavedObjectsExportTransform>;
}

const applyTransforms = async ({
objects,
alreadyProcessed,
exportTransforms,
request,
}: ProcessCurrentLevelOptions) => {
const transformed = await applyExportTransforms({
request,
objects,
transforms: exportTransforms,
});
// remove potential additions from the hooks that are already included in the export
return transformed.filter((object) => !alreadyProcessed.has(objKey(object)));
};

type ObjectKey = string;

interface CollectedReference {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"type": "doc",
"value": {
"index": ".kibana",
"type": "doc",
"id": "test-export-transform:type_1-obj_1",
"source": {
"test-export-transform": {
"title": "test_1-obj_1",
"enabled": true
},
"type": "test-export-transform",
"migrationVersion": {},
"updated_at": "2018-12-21T00:43:07.096Z",
"references": [
{
"type": "test-export-transform",
"id": "type_1-obj_2",
"name": "ref-1"
},
{
"type": "test-export-add",
"id": "type_2-obj_1",
"name": "ref-2"
}
]
}
}
}

{
"type": "doc",
"value": {
"index": ".kibana",
"type": "doc",
"id": "test-export-transform:type_1-obj_2",
"source": {
"test-export-transform": {
"title": "test_1-obj_2",
"enabled": true
},
"type": "test-export-transform",
"migrationVersion": {},
"updated_at": "2018-12-21T00:43:07.096Z"
}
}
}

{
"type": "doc",
"value": {
"index": ".kibana",
"type": "doc",
"id": "test-export-add:type_2-obj_1",
"source": {
"test-export-add": {
"title": "test_2-obj_1"
},
"type": "test-export-add",
"migrationVersion": {},
"updated_at": "2018-12-21T00:43:07.096Z"
}
}
}

{
"type": "doc",
"value": {
"index": ".kibana",
"type": "doc",
"id": "test-export-add-dep:type_dep-obj_1",
"source": {
"test-export-add-dep": {
"title": "type_dep-obj_1"
},
"type": "test-export-add-dep",
"migrationVersion": {},
"updated_at": "2018-12-21T00:43:07.096Z",
"references": [
{
"type": "test-export-add",
"id": "type_2-obj_1"
}
]
}
}
}
Loading

0 comments on commit b19882d

Please sign in to comment.