Skip to content

Commit

Permalink
adding FTR tests on export failures
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Jan 21, 2021
1 parent 1a33426 commit 912da12
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,37 @@
}
}
}

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

{
"type": "doc",
"value": {
"index": ".kibana",
"type": "doc",
"id": "test-export-transform-error:type_4-obj_1",
"source": {
"test-export-transform-error": {
"title": "test_2-obj_1"
},
"type": "test-export-transform-error",
"migrationVersion": {},
"updated_at": "2018-12-21T00:43:07.096Z"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
"title": { "type": "text" }
}
},
"test-export-transform-error": {
"properties": {
"title": { "type": "text" }
}
},
"test-export-invalid-transform": {
"properties": {
"title": { "type": "text" }
}
},
"apm-telemetry": {
"properties": {
"has_any_services": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,51 @@ export class SavedObjectExportTransformsPlugin implements Plugin {
getTitle: (obj) => obj.attributes.title,
},
});

/////////////
/////////////
// example of a SO type that will throw an object-transform-error
savedObjects.registerType({
name: 'test-export-transform-error',
hidden: false,
namespaceType: 'single',
mappings: {
properties: {
title: { type: 'text' },
},
},
management: {
defaultSearchField: 'title',
importableAndExportable: true,
getTitle: (obj) => obj.attributes.title,
onExport: (ctx, objs) => {
throw new Error('Error during transform');
},
},
});

// example of a SO type that will throw an invalid-transform-error
savedObjects.registerType({
name: 'test-export-invalid-transform',
hidden: false,
namespaceType: 'single',
mappings: {
properties: {
title: { type: 'text' },
},
},
management: {
defaultSearchField: 'title',
importableAndExportable: true,
getTitle: (obj) => obj.attributes.title,
onExport: (ctx, objs) => {
return objs.map((obj) => ({
...obj,
id: `${obj.id}-mutated`,
}));
},
},
});
}

public start() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,47 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
]);
});
});

it('returns a 400 when the type causes a transform error', async () => {
await supertest
.post('/api/saved_objects/_export')
.set('kbn-xsrf', 'true')
.send({
type: ['test-export-transform-error'],
excludeExportDetails: true,
})
.expect(400)
.then((resp) => {
const { attributes, ...error } = resp.body;
expect(error).to.eql({
error: 'Bad Request',
message: 'Error transforming objects to export',
statusCode: 400,
});
expect(attributes.cause).to.eql('Error during transform');
expect(attributes.objects.map((obj: any) => obj.id)).to.eql(['type_4-obj_1']);
});
});

it('returns a 400 when the type causes an invalid transform', async () => {
await supertest
.post('/api/saved_objects/_export')
.set('kbn-xsrf', 'true')
.send({
type: ['test-export-invalid-transform'],
excludeExportDetails: true,
})
.expect(400)
.then((resp) => {
expect(resp.body).to.eql({
error: 'Bad Request',
message: 'Invalid transform performed on objects to export',
statusCode: 400,
attributes: {
objectKeys: ['test-export-invalid-transform|type_3-obj_1'],
},
});
});
});
});
}

0 comments on commit 912da12

Please sign in to comment.