-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Alerting] add functional tests for index threshold alertType #60597
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,20 +4,18 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export const ES_TEST_INDEX_NAME = '.kibaka-alerting-test-data'; | ||
export const ES_TEST_INDEX_NAME = '.kibana-alerting-test-data'; | ||
|
||
export class ESTestIndexTool { | ||
private readonly es: any; | ||
private readonly retry: any; | ||
|
||
constructor(es: any, retry: any) { | ||
this.es = es; | ||
this.retry = retry; | ||
} | ||
constructor( | ||
private readonly es: any, | ||
private readonly retry: any, | ||
private readonly index: string = ES_TEST_INDEX_NAME | ||
) {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL, you can define right in the constructor! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not often we get to do this, since we often pass an object with props as the constructor arg, and I don't think you can use this trick for that. But I try to use it wherever I can! |
||
|
||
async setup() { | ||
return await this.es.indices.create({ | ||
index: ES_TEST_INDEX_NAME, | ||
index: this.index, | ||
body: { | ||
mappings: { | ||
properties: { | ||
|
@@ -56,12 +54,13 @@ export class ESTestIndexTool { | |
} | ||
|
||
async destroy() { | ||
return await this.es.indices.delete({ index: ES_TEST_INDEX_NAME, ignore: [404] }); | ||
return await this.es.indices.delete({ index: this.index, ignore: [404] }); | ||
} | ||
|
||
async search(source: string, reference: string) { | ||
return await this.es.search({ | ||
index: ES_TEST_INDEX_NAME, | ||
index: this.index, | ||
size: 1000, | ||
body: { | ||
query: { | ||
bool: { | ||
|
@@ -86,7 +85,7 @@ export class ESTestIndexTool { | |
async waitForDocs(source: string, reference: string, numDocs: number = 1) { | ||
return await this.retry.try(async () => { | ||
const searchResult = await this.search(source, reference); | ||
if (searchResult.hits.total.value !== numDocs) { | ||
if (searchResult.hits.total.value < numDocs) { | ||
throw new Error(`Expected ${numDocs} but received ${searchResult.hits.total.value}.`); | ||
} | ||
return searchResult.hits.hits; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
been meaning to change this for a while :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ go kibaka!