Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Fang-
Copy link
Collaborator

@Fang- Fang- commented Oct 30, 2024

Cookies have been the bane of eyre tests for a while. We had resorted to
hard-coding the couple of expected cookie values and being careful about
passing them in the right place, right time. This was very finicky.

Here, we update the state that's passed continuously to include a value
for the "live" cookie. The rest of the testing code and helpers are
updated to keep this value updated according to the responses emitted by
eyre, and to inject the cookie into requests we simulate. This way, we
get the desired behavior of remembering the cookie like a browser would.

We get to remove the hard-coded cookie values from most tests. In the
process, we clean up the helpers a little bit, but unfortunately also
have to add more complex helpers for pulling the cookie from state.

All in all, tests should be more robust/flexible, at a small complexity
cost. The pattern here (moving over operations, updating & accumulating
state, occasional temporary config changes) might be better implemented as the state machine core (aka abet)
pattern, but that would be a bigger rewrite.

Includes an additional test for #7076, which prompted these changes, and which this PR targets for that reason. Submitting this as a separate PR because it's otherwise unrelated, and should be reviewed in isolation.

Fang- added 5 commits October 30, 2024 22:26
In practice, header ordering doesn't actually matter. Needing to specify
the headers in the exact order made testing them more difficult than it
should've been.

Here, we alphabetically sort the headers before testing them. (+ex-204-2
is to be removed in a future commit, so is ignored here.)

We do take care to preserve relative ordering between headers that have
the exact same field-name value, because that case _does_ matter.
Cookies have been the bane of eyre tests for a while. We had resorted to
hard-coding the couple of expected cookie values and being careful about
passing them in the right place, right time. This was very finicky.

Here, we update the state that's passed continuously to include a value
for the "live" cookie. The rest of the testing code and helpers are
updated to keep this value updated according to the responses emitted by
eyre, and to inject the cookie into requests we simulate. This way, we
get the desired behavior of remembering the cookie like a browser would.

We get to remove the hard-coded cookie values from most tests. In the
process, we clean up the helpers a little bit, but unfortunately also
have to add more complex helpers for pulling the cookie from state.

All in all, tests should be more robust/flexible, at a small complexity
cost. The pattern here (moving over operations, updating & accumulating
state) might be better implemented as the state machine core (aka abet)
pattern, but that would be a bigger rewrite.
@Fang- Fang- requested review from arthyn and pkova October 30, 2024 22:47
@Fang- Fang- changed the title eyre: improve test ergonomics eyre: improve test ergonomics slightly Oct 30, 2024
@pkova pkova merged commit fc8a811 into m/eyre-401 Nov 1, 2024
@pkova pkova deleted the m/eyre-test-cookie-jar branch November 1, 2024 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants