[test] Rewrite URLSession cookie tests to be independent. #2527
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some cookie tests were depending on previously run tests to be
successful. Rewrite all the tests to be independent from each other.
The first change is that all the tests that deal with cookies try to
clean their cookie storages before starting the testing. This should
avoid previous state leaking into the current test.
Some other changes are made to clarify how the cookie tests are actually
performed. To check that the cookies are set by URLSession, an special
endpoint that echoes back the request header are used. To make it clear,
that endpoint has changed names.
In the cases that we were checking that the response headers were
setting the cookies, we actually check for the right headers to been
set, not some random data in the response (because for some reason, the
request headers were also being echo in another endpoint, which might
have created false positives).
There is also some cleaning of unused variables and var that should have
been let.
I tested this by running all the tests in TestURLSession in the same
run, and also running the individual tests one by one from the command
line.
I recommend reading this diff with whitespace changes disabled (
?w=1
in the address bar).