Skip to content

Replace most external test APIs with local mock server - #57

Merged
lpil merged 1 commit into
gleam-lang:mainfrom
jtdowney:test-server
Sep 7, 2026
Merged

lpil merged 1 commit into
gleam-lang:mainfrom
jtdowney:test-server

Conversation

@jtdowney

Copy link
Copy Markdown
Member

This adds a mock HTTP server that operates similarly to https://httpbin.org. There are two places where it still uses the old tests, but there is a line of sight to moving those over as well.

  1. invalid_tls_test expects a "typical" TLS error like an expired certificate. I felt like it would change the spirit of the test to have it test against an unknown CA. This can move to a local test PKI once Add custom cacert support聽#36 is finished.
  2. ipv6_test could be replaced with a request to http://[::1]:8080 once IPv6 addresses with brackets are not handled correctly. 聽#34 is finished.

With a local test PKI, additional testing could be added for #55 as well.

Closes #56

@lpil

lpil commented Sep 7, 2026

Copy link
Copy Markdown
Member

ipv6_test could be replaced with a request to http://[::1]:8080 once IPv6 addresses with brackets are not handled correctly. #34 is finished.

I tried to add this but I got this failure. Do you know what this might be?

let assert test/gleam_httpc_test.gleam:106
 test: gleam_httpc_test.ipv6_test
 code: let assert Ok(resp) = httpc.send(req)
value: Error(FailedToConnect(Posix("eafnosupport"), Posix("econnrefused")))
 info: Pattern match failed, no pattern matched the value.

@lpil

lpil commented Sep 7, 2026

Copy link
Copy Markdown
Member

Oh I'm a dummy, I used the wrong port, didn't I?

@jtdowney

jtdowney commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

Took me a few minutes to remember what I was doing here. Now that #64 is in, ipv6_literal_host_test is not needed in this branch because ipv6_test is hitting an IPv6 bracketed literal just as it was. It just wasn't cleaned up because this branch predates it.

The only thing we lose, as far as I can tell, is a test that shows a domain name resolves to IPv6 correctly, but that is sort of testing httpc a bit. We have a test that shows httpc can talk IPv6 to a local server.

@lpil lpil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!!!

@lpil
lpil merged commit 0f5f2fd into gleam-lang:main Sep 7, 2026
1 check passed
@jtdowney
jtdowney deleted the test-server branch September 7, 2026 10:19
@jtdowney jtdowney mentioned this pull request Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: use a small test server for testing rather than external services

2 participants