-
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
[Security Solution] Minimize the use of es_archiver on cypress tests #85019
[Security Solution] Minimize the use of es_archiver on cypress tests #85019
Conversation
ba61b7c
to
2eccf8a
Compare
x-pack/plugins/security_solution/cypress/integration/timelines_export.spec.ts
Outdated
Show resolved
Hide resolved
…_export.spec.ts Co-authored-by: Patryk Kopyciński <contact@patrykkopycinski.com>
savedObjectId: timelineId, | ||
templateTimelineId, | ||
} = response!.body.data.persistTimeline.timeline; | ||
const jsonTemplate = JSON.parse(JSON.stringify(template)); |
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.
JSON.parse
is opposite to JSON.stringify
, so seems you don't need any of these as template
is the same as JSON.parse(JSON.stringify(template))
cy.intercept( | ||
'POST', | ||
'/api/detection_engine/rules/_export?exclude_export_details=false&file_name=rules_export.ndjson' | ||
'**api/detection_engine/rules/_export?exclude_export_details=false&file_name=rules_export.ndjson*' |
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.
no need for **
@@ -319,3 +320,9 @@ export const editedRule = { | |||
description: 'Edited Rule description', | |||
tags: [...existingRule.tags, 'edited'], | |||
}; | |||
|
|||
export const expectedExportedRule = (rule: string) => { | |||
const jsonrule = JSON.parse(JSON.stringify(rule)); |
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.
const jsonrule = rule; should be fine
body: { | ||
operationName: 'DeleteTimelineMutation', | ||
variables: { | ||
id: [`${timelineId}`], |
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.
seems timelineId
is a string already, so we could just do [timelineId]
here
@elasticmachine merge upstream |
merge conflict between base and head |
@MadameSheema I'm getting test failures on usage of these new As indicated by the error, I don't think we can return/await a promise as those helpers are currently expecting; if we need to pass information from the request to the test, we'll have to alias and retrieve the response. |
|
||
before(async () => { | ||
const createdTimeline = await createTimeline(newRule.timeline); | ||
rule = deepMerge(newRule, { timeline: { id: createdTimeline[0] } }); |
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.
Nit: I don't think deepmerge
is strictly necessary, here:
rule = { ...newRule, { timeline: { ...newRule.timeline, id: timelineId } } }
I would go that route for now and keep dependencies to a minimum.
const timelineId = response.body.data.persistTimeline.timeline.savedObjectId; | ||
const timelineBody = response.body.data.persistTimeline.timeline; | ||
|
||
return [timelineId, timelineBody]; |
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.
As per my comment about promises/errors, ideally these methods just return cy.request()
and these custom types go away. However, in the case that they don't, I don't believe that timelineBody
is a string
here as the types indicate.
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.
We also don't seem to be using timelineBody
, so 🤷♂️
@rylnd lots of thanks for taking a look to the code, with the latest changes the PR got really broke, I'm working to fix it ASAP |
@ryland with this library |
@angorayc @patrykkopycinski @rylnd I tried to follow all your suggestions, can you please take a look to the PR again? Lots of thanks 😊 |
NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS | ||
); | ||
}); | ||
cy.get(NUMBER_OF_ALERTS).should('have.text', NUMBER_OF_AUDITBEAT_EXCEPTIONS_ALERTS); |
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.
❤️
@elasticmachine merge upstream |
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.
Thank you @MadameSheema 💪
💚 Build SucceededMetrics [docs]Distributable file count
History
To update your PR or re-run it, just comment with: |
…lastic#85019) * minimizes the uses of es_archiver * refactor * fixes merge issue * fixes typecheck issue * Update x-pack/plugins/security_solution/cypress/integration/timelines_export.spec.ts Co-authored-by: Patryk Kopyciński <contact@patrykkopycinski.com> * final refactor * final touches * unskips skipped tests * removes async * fixes typo * removes unused lines * fixes failing test * fixes timelines failing tests * fixes merge issue Co-authored-by: Patryk Kopyciński <contact@patrykkopycinski.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
…85019) (#85612) * minimizes the uses of es_archiver * refactor * fixes merge issue * fixes typecheck issue * Update x-pack/plugins/security_solution/cypress/integration/timelines_export.spec.ts Co-authored-by: Patryk Kopyciński <contact@patrykkopycinski.com> * final refactor * final touches * unskips skipped tests * removes async * fixes typo * removes unused lines * fixes failing test * fixes timelines failing tests * fixes merge issue Co-authored-by: Patryk Kopyciński <contact@patrykkopycinski.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Patryk Kopyciński <contact@patrykkopycinski.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Summary
In this PR we are minimising the use of es_archiver creating the data we need when possible using our own APIs. Wit this refactor: