Skip to content

Commit 364545d

Browse files
committed
add test for indexMigrator
1 parent ec08e99 commit 364545d

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/core/server/saved_objects/migrations/core/index_migrator.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,30 @@ describe('IndexMigrator', () => {
369369
],
370370
});
371371
});
372+
373+
test('rejects when the migration function throws an error', async () => {
374+
const { client } = testOpts;
375+
const migrateDoc = jest.fn((doc: SavedObjectUnsanitizedDoc) => {
376+
throw new Error('error migrating document');
377+
});
378+
379+
testOpts.documentMigrator = {
380+
migrationVersion: { foo: '1.2.3' },
381+
migrate: migrateDoc,
382+
};
383+
384+
withIndex(client, {
385+
numOutOfDate: 1,
386+
docs: [
387+
[{ _id: 'foo:1', _source: { type: 'foo', foo: { name: 'Bar' } } }],
388+
[{ _id: 'foo:2', _source: { type: 'foo', foo: { name: 'Baz' } } }],
389+
],
390+
});
391+
392+
await expect(new IndexMigrator(testOpts).migrate()).rejects.toThrowErrorMatchingInlineSnapshot(
393+
`"error migrating document"`
394+
);
395+
});
372396
});
373397

374398
function withIndex(

0 commit comments

Comments
 (0)