Skip to content

Commit

Permalink
[Alerting] Using new es client in alerting functional tests (elastic#…
Browse files Browse the repository at this point in the history
…102349)

* Switching to new es client in alerting tests

* Fixing types

* Updating functional test

* Updating functional test

* Updating functional test

* Fixing error handling

* Fixing types

* Fixing error handling

* Fixing functional tests

* Fixing functional tests

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
ymao1 and kibanamachine authored Jun 24, 2021
1 parent aefdb9c commit 7e32f93
Show file tree
Hide file tree
Showing 30 changed files with 206 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export class ESTestIndexTool {
}

async destroy() {
return await this.es.indices.delete({ index: this.index, ignore: [404] });
const indexExists = (await this.es.indices.exists({ index: this.index })).body;
if (indexExists) {
return await this.es.indices.delete({ index: this.index });
}
}

async search(source: string, reference: string) {
Expand Down Expand Up @@ -90,10 +93,10 @@ 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) {
throw new Error(`Expected ${numDocs} but received ${searchResult.hits.total.value}.`);
if (searchResult.body.hits.total.value < numDocs) {
throw new Error(`Expected ${numDocs} but received ${searchResult.body.hits.total.value}.`);
}
return searchResult.hits.hits;
return searchResult.body.hits.hits;
});
}
}
2 changes: 1 addition & 1 deletion x-pack/test/alerting_api_integration/common/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export {
getConsumerUnauthorizedErrorMessage,
getProducerUnauthorizedErrorMessage,
} from './alert_utils';
export { TaskManagerUtils } from './task_manager_utils';
export { TaskManagerUtils, TaskManagerDoc } from './task_manager_utils';
export * from './test_assertions';
export { checkAAD } from './check_aad';
export { getEventLog } from './get_event_log';
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
* 2.0.
*/

import { SerializedConcreteTaskInstance } from '../../../../plugins/task_manager/server/task';

export interface TaskManagerDoc {
type: string;
task: SerializedConcreteTaskInstance;
}
export class TaskManagerUtils {
private readonly es: any;
private readonly retry: any;
Expand Down Expand Up @@ -39,8 +45,8 @@ export class TaskManagerUtils {
},
},
});
if (searchResult.hits.total.value) {
throw new Error(`Expected 0 tasks but received ${searchResult.hits.total.value}`);
if (searchResult.body.hits.total.value) {
throw new Error(`Expected 0 tasks but received ${searchResult.body.hits.total.value}`);
}
});
}
Expand Down Expand Up @@ -77,8 +83,10 @@ export class TaskManagerUtils {
},
},
});
if (searchResult.hits.total.value) {
throw new Error(`Expected 0 non-idle tasks but received ${searchResult.hits.total.value}`);
if (searchResult.body.hits.total.value) {
throw new Error(
`Expected 0 non-idle tasks but received ${searchResult.body.hits.total.value}`
);
}
});
}
Expand Down Expand Up @@ -108,9 +116,9 @@ export class TaskManagerUtils {
},
},
});
if (searchResult.hits.total.value) {
if (searchResult.body.hits.total.value) {
throw new Error(
`Expected 0 action_task_params objects but received ${searchResult.hits.total.value}`
`Expected 0 action_task_params objects but received ${searchResult.body.hits.total.value}`
);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ES_TEST_INDEX_NAME = 'functional-test-actions-index';

// eslint-disable-next-line import/no-default-export
export default function indexTest({ getService }: FtrProviderContext) {
const es = getService('legacyEs');
const es = getService('es');
const supertest = getService('supertest');
const esDeleteAllIndices = getService('esDeleteAllIndices');

Expand Down Expand Up @@ -273,5 +273,5 @@ async function getTestIndexItems(es: any) {
index: ES_TEST_INDEX_NAME,
});

return result.hits.hits;
return result.body.hits.hits;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ES_TEST_INDEX_NAME = 'functional-test-actions-index-preconfigured';

// eslint-disable-next-line import/no-default-export
export default function indexTest({ getService }: FtrProviderContext) {
const es = getService('legacyEs');
const es = getService('es');
const esDeleteAllIndices = getService('esDeleteAllIndices');
const supertest = getService('supertest');

Expand Down Expand Up @@ -57,5 +57,5 @@ async function getTestIndexItems(es: any) {
index: ES_TEST_INDEX_NAME,
});

return result.hits.hits;
return result.body.hits.hits;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const NANOS_IN_MILLIS = 1000 * 1000;
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const supertestWithoutAuth = getService('supertestWithoutAuth');
const es = getService('legacyEs');
const es = getService('es');
const retry = getService('retry');
const esTestIndexTool = new ESTestIndexTool(es, retry);

Expand Down Expand Up @@ -97,8 +97,8 @@ export default function ({ getService }: FtrProviderContext) {
'action:test.index-record',
reference
);
expect(searchResult.hits.total.value).to.eql(1);
const indexedRecord = searchResult.hits.hits[0];
expect(searchResult.body.hits.total.value).to.eql(1);
const indexedRecord = searchResult.body.hits.hits[0];
expect(indexedRecord._source).to.eql({
params: {
reference,
Expand Down Expand Up @@ -250,8 +250,8 @@ export default function ({ getService }: FtrProviderContext) {
'action:test.index-record',
reference
);
expect(searchResult.hits.total.value).to.eql(1);
const indexedRecord = searchResult.hits.hits[0];
expect(searchResult.body.hits.total.value).to.eql(1);
const indexedRecord = searchResult.body.hits.hits[0];
expect(indexedRecord._source).to.eql({
params: {
reference,
Expand Down Expand Up @@ -453,8 +453,8 @@ export default function ({ getService }: FtrProviderContext) {
case 'space_1_all_with_restricted_fixture at space1':
expect(response.statusCode).to.eql(200);
searchResult = await esTestIndexTool.search('action:test.authorization', reference);
expect(searchResult.hits.total.value).to.eql(1);
indexedRecord = searchResult.hits.hits[0];
expect(searchResult.body.hits.total.value).to.eql(1);
indexedRecord = searchResult.body.hits.hits[0];
expect(indexedRecord._source.state).to.eql({
callClusterSuccess: false,
callScopedClusterSuccess: false,
Expand All @@ -477,8 +477,8 @@ export default function ({ getService }: FtrProviderContext) {
case 'superuser at space1':
expect(response.statusCode).to.eql(200);
searchResult = await esTestIndexTool.search('action:test.authorization', reference);
expect(searchResult.hits.total.value).to.eql(1);
indexedRecord = searchResult.hits.hits[0];
expect(searchResult.body.hits.total.value).to.eql(1);
indexedRecord = searchResult.body.hits.hits[0];
expect(indexedRecord._source.state).to.eql({
callClusterSuccess: true,
callScopedClusterSuccess: true,
Expand Down
Loading

0 comments on commit 7e32f93

Please sign in to comment.