-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add integration test for isWriteBlockException
- Loading branch information
1 parent
c1bc869
commit 7f3f35c
Showing
1 changed file
with
127 additions
and
0 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
src/core/server/saved_objects/migrationsv2/actions/integration_tests/es_errors.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,127 @@ | ||
/* | ||
* 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 { ElasticsearchClient } from '../../../../'; | ||
import { InternalCoreStart } from '../../../../internal_types'; | ||
import * as kbnTestServer from '../../../../../test_helpers/kbn_server'; | ||
import { Root } from '../../../../root'; | ||
import { isWriteBlockException } from '../es_errors'; | ||
import { createIndex } from '../create_index'; | ||
import { setWriteBlock } from '../set_write_block'; | ||
|
||
const { startES } = kbnTestServer.createTestServers({ | ||
adjustTimeout: (t: number) => jest.setTimeout(t), | ||
}); | ||
|
||
describe('Elasticsearch Errors', () => { | ||
let root: Root; | ||
let start: InternalCoreStart; | ||
let client: ElasticsearchClient; | ||
let esServer: kbnTestServer.TestElasticsearchUtils; | ||
|
||
beforeAll(async () => { | ||
esServer = await startES(); | ||
root = kbnTestServer.createRootWithCorePlugins({ | ||
server: { | ||
basePath: '/foo', | ||
}, | ||
}); | ||
|
||
await root.setup(); | ||
start = await root.start(); | ||
client = start.elasticsearch.client.asInternalUser; | ||
|
||
await createIndex({ | ||
client, | ||
indexName: 'existing_index_with_write_block', | ||
mappings: { properties: {} }, | ||
})(); | ||
await setWriteBlock({ client, index: 'existing_index_with_write_block' })(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await esServer.stop(); | ||
await root.shutdown(); | ||
}); | ||
|
||
describe('isWriteBlockException', () => { | ||
it('correctly identify errors from index operations', async () => { | ||
const res = await client.index( | ||
{ | ||
index: 'existing_index_with_write_block', | ||
id: 'some-id', | ||
op_type: 'index', | ||
body: { | ||
hello: 'dolly', | ||
}, | ||
}, | ||
{ ignore: [403] } | ||
); | ||
|
||
expect(isWriteBlockException(res.body.error!)).toEqual(true); | ||
}); | ||
|
||
it('correctly identify errors from create operations', async () => { | ||
const res = await client.create( | ||
{ | ||
index: 'existing_index_with_write_block', | ||
id: 'some-id', | ||
body: { | ||
hello: 'dolly', | ||
}, | ||
}, | ||
{ ignore: [403] } | ||
); | ||
|
||
expect(isWriteBlockException(res.body.error!)).toEqual(true); | ||
}); | ||
|
||
it('correctly identify errors from bulk index operations', async () => { | ||
const res = await client.bulk({ | ||
refresh: 'wait_for', | ||
body: [ | ||
{ | ||
index: { | ||
_index: 'existing_index_with_write_block', | ||
_id: 'some-id', | ||
}, | ||
}, | ||
{ | ||
hello: 'dolly', | ||
}, | ||
], | ||
}); | ||
|
||
const cause = res.body.items[0].index!.error!; | ||
|
||
expect(isWriteBlockException(cause)).toEqual(true); | ||
}); | ||
|
||
it('correctly identify errors from bulk create operations', async () => { | ||
const res = await client.bulk({ | ||
refresh: 'wait_for', | ||
body: [ | ||
{ | ||
create: { | ||
_index: 'existing_index_with_write_block', | ||
_id: 'some-id', | ||
op_type: 'index', | ||
}, | ||
}, | ||
{ | ||
hello: 'dolly', | ||
}, | ||
], | ||
}); | ||
|
||
const cause = res.body.items[0].create!.error!; | ||
|
||
expect(isWriteBlockException(cause)).toEqual(true); | ||
}); | ||
}); | ||
}); |