-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ingest Manager] prevent crash on unhandled rejection from setupInges…
…tManager (#74300) * Add test to ensure setup rejects if errors thrown. * Return the promise from setup so test passes
- Loading branch information
John Schulz
authored
Aug 5, 2020
1 parent
22d6f09
commit beb7b82
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/ingest_manager/server/services/setup.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { setupIngestManager } from './setup'; | ||
import { savedObjectsClientMock } from 'src/core/server/mocks'; | ||
|
||
describe('setupIngestManager', () => { | ||
it('returned promise should reject if errors thrown', async () => { | ||
const { savedObjectsClient, callClusterMock } = makeErrorMocks(); | ||
const setupPromise = setupIngestManager(savedObjectsClient, callClusterMock); | ||
await expect(setupPromise).rejects.toThrow('mocked'); | ||
}); | ||
}); | ||
|
||
function makeErrorMocks() { | ||
jest.mock('./app_context'); // else fails w/"Logger not set." | ||
jest.mock('./epm/registry/registry_url', () => { | ||
return { | ||
fetchUrl: () => { | ||
throw new Error('mocked registry#fetchUrl'); | ||
}, | ||
}; | ||
}); | ||
|
||
const callClusterMock = jest.fn(); | ||
const savedObjectsClient = savedObjectsClientMock.create(); | ||
savedObjectsClient.find = jest.fn().mockImplementation(() => { | ||
throw new Error('mocked SO#find'); | ||
}); | ||
savedObjectsClient.get = jest.fn().mockImplementation(() => { | ||
throw new Error('mocked SO#get'); | ||
}); | ||
savedObjectsClient.update = jest.fn().mockImplementation(() => { | ||
throw new Error('mocked SO#update'); | ||
}); | ||
|
||
return { | ||
savedObjectsClient, | ||
callClusterMock, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters