The server.py script starts a web server with two endpoints:
POST /login- Returns a 302 redirect to/meand sets alogged_in=truecookieGET /me- Returns "You are logged in" if thelogged_in=truecookie is present, otherwise returns "Please log in"
All Swift test functions send a POST /login request and expect a "You are logged in" response. This works because URLSession automatically:
- Follows the 302 redirect from
/loginto/me - Includes cookies set by the
/loginresponse in the subsequent request to/me
The tests pass on macOS but fail on Linux. Specifically, the test that uses dataTask(...) with a custom delegate fails on Linux.
Assuming you are using macOS.
- Start the web server:
python server.py - Run
swift testto verify all tests pass on macOS. - Run
swift teston a Docker image to reproduce the issue on Linux:
docker run --rm -v "$PWD:/app" -w /app --network host swift:6.2 swift test