From b2f4c821f3140acbc329082eb934444df56ed9d2 Mon Sep 17 00:00:00 2001 From: Frank Hassanabad Date: Thu, 28 Oct 2021 07:27:45 -0600 Subject: [PATCH] [Security Solutions] Adds console logging and relaxes the 200 checks in a 2 areas of the e2e tests (#116548) ## Summary Adds console logging and relaxes a few 200 checks in the end to end tests in two areas of: * createExceptionListItem * importFile As recently the tests are failing around these parts and possibly we can get information on the next failures if it is from these two areas or if it's from somewhere else we are not expecting. Also outputs the body message so if it fails in these areas we can see the message with the conflict that might help us see where the issue is arising. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --- .../detection_engine_api_integration/utils.ts | 26 ++++++++++++++----- x-pack/test/lists_api_integration/utils.ts | 14 +++++++--- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/x-pack/test/detection_engine_api_integration/utils.ts b/x-pack/test/detection_engine_api_integration/utils.ts index 095c4f2cb59d..4781df7993a4 100644 --- a/x-pack/test/detection_engine_api_integration/utils.ts +++ b/x-pack/test/detection_engine_api_integration/utils.ts @@ -962,7 +962,9 @@ export const deleteRule = async ( if (response.status !== 200) { // eslint-disable-next-line no-console console.log( - 'Did not get an expected 200 "ok" when deleting the rule. CI issues could happen. Suspect this line if you are seeing CI issues.' + `Did not get an expected 200 "ok" when deleting the rule. CI issues could happen. Suspect this line if you are seeing CI issues. body: ${JSON.stringify( + response.body + )}, status: ${JSON.stringify(response.status)}` ); } @@ -1111,7 +1113,7 @@ export const createExceptionList = async ( }; /** - * Helper to cut down on the noise in some of the tests. Does a delete of a rule. + * Helper to cut down on the noise in some of the tests. Does a delete of an exception list. * It does not check for a 200 "ok" on this. * @param supertest The supertest deps * @param id The rule id to delete @@ -1126,7 +1128,9 @@ export const deleteExceptionList = async ( if (response.status !== 200) { // eslint-disable-next-line no-console console.log( - 'Did not get an expected 200 "ok" when deleting an exception list. CI issues could happen. Suspect this line if you are seeing CI issues.' + `Did not get an expected 200 "ok" when deleting an exception list. CI issues could happen. Suspect this line if you are seeing CI issues. body: ${JSON.stringify( + response.body + )}, status: ${JSON.stringify(response.status)}` ); } @@ -1143,12 +1147,20 @@ export const createExceptionListItem = async ( supertest: SuperTest.SuperTest, exceptionListItem: CreateExceptionListItemSchema ): Promise => { - const { body } = await supertest + const response = await supertest .post(EXCEPTION_LIST_ITEM_URL) .set('kbn-xsrf', 'true') - .send(exceptionListItem) - .expect(200); - return body; + .send(exceptionListItem); + + if (response.status !== 200) { + // eslint-disable-next-line no-console + console.log( + `Did not get an expected 200 "ok" when creating an exception list item. CI issues could happen. Suspect this line if you are seeing CI issues. body: ${JSON.stringify( + response.body + )}, status: ${JSON.stringify(response.status)}` + ); + } + return response.body; }; /** diff --git a/x-pack/test/lists_api_integration/utils.ts b/x-pack/test/lists_api_integration/utils.ts index c8c1acb9f0e8..eda32c7fe9fb 100644 --- a/x-pack/test/lists_api_integration/utils.ts +++ b/x-pack/test/lists_api_integration/utils.ts @@ -210,12 +210,20 @@ export const importFile = async ( fileName: string, testValues?: string[] ): Promise => { - await supertest + const response = await supertest .post(`${LIST_ITEM_URL}/_import?type=${type}`) .set('kbn-xsrf', 'true') .attach('file', getImportListItemAsBuffer(contents), fileName) - .expect('Content-Type', 'application/json; charset=utf-8') - .expect(200); + .expect('Content-Type', 'application/json; charset=utf-8'); + + if (response.status !== 200) { + // eslint-disable-next-line no-console + console.log( + `Did not get an expected 200 "ok" When importing a file. CI issues could happen. Suspect this line if you are seeing CI issues. body: ${JSON.stringify( + response.body + )}, status: ${JSON.stringify(response.status)}` + ); + } // although we have pushed the list and its items, it is async so we // have to wait for the contents before continuing