Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Bypass provides a quick way to create a custom plug that can be put in place instead of an actual HTTP server to return prebaked responses to client requests.
| Date | Stars |
|---|---|
| 2026-07-24 | 997 |
| 2026-07-25 | 997 |
| 2026-07-28 | 997 |
| 2026-07-30 | 997 |
| 2026-08-06 | 997 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
# Bypass
<!-- MDOC !-->
[](https://github.com/PSPDFKit-labs/bypass/actions)
[](https://hex.pm/packages/bypass)
[](https://hexdocs.pm/bypass/)
[](https://hex.pm/packages/bypass)
[](https://github.com/PSPDFKit-labs/bypass/blob/master/LICENSE)
[](https://github.com/PSPDFKit-labs/bypass/commits/master)
`Bypass` provides a quick way to create a custom plug that can be put in place
instead of an actual HTTP server to return prebaked responses to client
requests. This is most useful in tests, when you want to create a mock HTTP
server and test how your HTTP client handles different types of responses from
the server.
Bypass supports Elixir 1.10 and OTP 21 and up. It works with Cowboy 2.
## Usage
To use Bypass in a test case, open a connection and use its port to connect your
client to it.
If you want to test what happens when the HTTP server goes down, use
`Bypass.down/1` to close the TCP socket and `Bypass.up/1` to start listening on
the same port again. Both functions block until the socket updates its state.
### Expect Functions
You can take any of the following approaches:
* `expect/2` or `expect_once/2` to install a generic function that all calls to
bypass will use
* `expect/4` and/or `expect_once/4` to install specific routes (method and path)
* `stub/4` to install specific routes without expectations
* a combination of the above, where the routes will be used first, and then the
generic version will be used as default
### Example
In the following example `TwitterClient.start_link()` takes the endpoint URL as
its argument allowing us to make sure it will connect to the running instance of
Bypass.
```elixir
defmodule TwitterClientTest do
use ExUnit.Case, async: true
setup do
bypass = Bypass.open()
{:ok, bypass: bypass}
end
test "client can handle an error response", %{bypass: bypass} do
Bypass.expect_once(bypass, "POST", "/1.1/statuses/update.json", fn conn ->
Plug.Conn.resp(conn, 429, ~s<{"errors": [{"code": 88, "message": "Rate limit exceeded"}]}>)
end)
{:ok, client} = TwitterClient.start_link(url: endpoint_url(bypass.port))
assert {:error, :rate_limited} == TwitterClient.post_tweet(client, "Elixir is awesome!")
end
test "client can recover from server downtime", %{bypass: bypass} do
Bypass.expect(bypass, fn conn ->
# We don't care about `request_path` or `method` for this test.
Plug.Conn.resp(conn, 200, "")
end)
{:ok, client} = TwitterClient.start_link(url: endpoint_url(bypass.port))
assert :ok == TwitterClient.post_tweet(client, "Elixir is awesome!")
# Blocks until the TCP socket is closed.
Bypass.down(bypass)
assert {:error, :noconnect} == TwitterClient.post_tweet(client, "Elixir is awesome!")
Bypass.up(bypass)
# When testing a real client that is using e.g. https://github.com/fishcakez/connection
# with https://github.com/ferd/backoff to handle reconnecting, we'd have to loop for
# a while until the client has reconnected.
assert :ok == TwitterClient.post_tweet(client, "Elixir is awesome!")
end
defp endpoint_url(port), do: "http://localhost:#{port}/"
end
```
That's all you need to do. Bypass automatically sets up an `on_exit` hook to
close its socket when the test finishes running.
Multiple concurrent Bypass instances are supported, all will have a different
unique port. Concurrent requests are also supported on the same instance.
> Note: `Bypass.open/0` **must not** be called in a `setup_all` blocks due to
> the way Bypass verifies the expectations at the end oExcerpt of 6,460 characters
Read on GitHubWould you bet a product on this? Bounded 0–100 and slow moving.
matched fp:379fe5c9f63b56de, topic:testing