forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[index patterns] Add pattern validation method to index patterns fetc…
…her (elastic#90170)
- Loading branch information
1 parent
a59ce61
commit e923e54
Showing
6 changed files
with
197 additions
and
51 deletions.
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
...na-plugin-plugins-data-server.indexpatternsfetcher.validatepatternlistactive.md
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,24 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IndexPatternsFetcher](./kibana-plugin-plugins-data-server.indexpatternsfetcher.md) > [validatePatternListActive](./kibana-plugin-plugins-data-server.indexpatternsfetcher.validatepatternlistactive.md) | ||
|
||
## IndexPatternsFetcher.validatePatternListActive() method | ||
|
||
Returns an index pattern list of only those index pattern strings in the given list that return indices | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
validatePatternListActive(patternList: string[]): Promise<string[]>; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| patternList | <code>string[]</code> | | | ||
|
||
<b>Returns:</b> | ||
|
||
`Promise<string[]>` | ||
|
72 changes: 72 additions & 0 deletions
72
src/plugins/data/server/index_patterns/fetcher/index_patterns_fetcher.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,72 @@ | ||
/* | ||
* 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 { IndexPatternsFetcher } from '.'; | ||
import { ElasticsearchClient } from 'kibana/server'; | ||
import * as indexNotFoundException from '../../../common/search/test_data/index_not_found_exception.json'; | ||
|
||
describe('Index Pattern Fetcher - server', () => { | ||
let indexPatterns: IndexPatternsFetcher; | ||
let esClient: ElasticsearchClient; | ||
const emptyResponse = { | ||
body: { | ||
count: 0, | ||
}, | ||
}; | ||
const response = { | ||
body: { | ||
count: 1115, | ||
}, | ||
}; | ||
const patternList = ['a', 'b', 'c']; | ||
beforeEach(() => { | ||
esClient = ({ | ||
count: jest.fn().mockResolvedValueOnce(emptyResponse).mockResolvedValue(response), | ||
} as unknown) as ElasticsearchClient; | ||
indexPatterns = new IndexPatternsFetcher(esClient); | ||
}); | ||
|
||
it('Removes pattern without matching indices', async () => { | ||
const result = await indexPatterns.validatePatternListActive(patternList); | ||
expect(result).toEqual(['b', 'c']); | ||
}); | ||
|
||
it('Returns all patterns when all match indices', async () => { | ||
esClient = ({ | ||
count: jest.fn().mockResolvedValue(response), | ||
} as unknown) as ElasticsearchClient; | ||
indexPatterns = new IndexPatternsFetcher(esClient); | ||
const result = await indexPatterns.validatePatternListActive(patternList); | ||
expect(result).toEqual(patternList); | ||
}); | ||
it('Removes pattern when "index_not_found_exception" error is thrown', async () => { | ||
class ServerError extends Error { | ||
public body?: Record<string, any>; | ||
constructor( | ||
message: string, | ||
public readonly statusCode: number, | ||
errBody?: Record<string, any> | ||
) { | ||
super(message); | ||
this.body = errBody; | ||
} | ||
} | ||
|
||
esClient = ({ | ||
count: jest | ||
.fn() | ||
.mockResolvedValueOnce(response) | ||
.mockRejectedValue( | ||
new ServerError('index_not_found_exception', 404, indexNotFoundException) | ||
), | ||
} as unknown) as ElasticsearchClient; | ||
indexPatterns = new IndexPatternsFetcher(esClient); | ||
const result = await indexPatterns.validatePatternListActive(patternList); | ||
expect(result).toEqual([patternList[0]]); | ||
}); | ||
}); |
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
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
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