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.
HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽
| Date | Stars |
|---|---|
| 2026-07-24 | 2218 |
| 2026-07-25 | 2218 |
| 2026-07-28 | 2218 |
| 2026-07-30 | 2218 |
| 2026-08-06 | 2218 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
# gock [](https://github.com/h2non/gock/releases) [](https://godoc.org/github.com/h2non/gock) [](https://coveralls.io/github/h2non/gock?branch=master) [](https://goreportcard.com/report/github.com/h2non/gock) []()
Versatile HTTP mocking made easy in [Go](https://golang.org) that works with any `net/http` based stdlib implementation.
Heavily inspired by [nock](https://github.com/node-nock/nock).
There is also its Python port, [pook](https://github.com/h2non/pook).
To get started, take a look to the [examples](#examples).
## Features
- Simple, expressive, fluent API.
- Semantic API DSL for declarative HTTP mock declarations.
- Built-in helpers for easy JSON/XML mocking.
- Supports persistent and volatile TTL-limited mocks.
- Full regular expressions capable HTTP request mock matching.
- Designed for both testing and runtime scenarios.
- Match request by method, URL params, headers and bodies.
- Extensible and pluggable HTTP matching rules.
- Ability to switch between mock and real networking modes.
- Ability to filter/map HTTP requests for accurate mock matching.
- Supports map and filters to handle mocks easily.
- Wide compatible HTTP interceptor using `http.RoundTripper` interface.
- Works with any `net/http` compatible client, such as [gentleman](https://github.com/h2non/gentleman).
- Network timeout/cancelation delay simulation.
- Extensible and hackable API.
- Dependency free.
## Installation
```bash
go get -u github.com/h2non/gock
```
## API
See [godoc reference](https://godoc.org/github.com/h2non/gock) for detailed API documentation.
## How it mocks
1. Intercepts any HTTP outgoing request via `http.DefaultTransport` or custom `http.Transport` used by any `http.Client`.
2. Matches outgoing HTTP requests against a pool of defined HTTP mock expectations in FIFO declaration order.
3. If at least one mock matches, it will be used in order to compose the mock HTTP response.
4. If no mock can be matched, it will resolve the request with an error, unless real networking mode is enable, in which case a real HTTP request will be performed.
## Tips
#### Testing
Declare your mocks before you start declaring the concrete test logic:
```go
func TestFoo(t *testing.T) {
defer gock.Off() // Flush pending mocks after test execution
gock.New("http://server.com").
Get("/bar").
Reply(200).
JSON(map[string]string{"foo": "bar"})
// Your test code starts here...
}
```
#### Race conditions
If you're running concurrent code, be aware that your mocks are declared first to avoid unexpected
race conditions while configuring `gock` or intercepting custom HTTP clients.
`gock` is not fully thread-safe, but sensible parts are.
Any help making `gock` more reliable in this sense is appreciated.
#### Define complex mocks first
If you're mocking a bunch of mocks in the same test suite, it's recommended to define the more
concrete mocks first, and then the generic ones.
This approach usually avoids matching unexpected generic mocks (e.g: specific header, body payload...) instead of the generic ones that performs less complex matches.
#### Disable `gock` traffic interception once done
In other to minimize potential side effects within your test code, it's a good practice
disabling `gock` once you are done with your HTTP testing logic.
A Go idiomatic approach for doing this can be using it in a `defer` statement, such as:
```go
func TestGock (t *testing.T) {
defer gock.Off()
// ... my test code goes here
}
```
#### Intercept an `http.Client` just once
You don't need to intercept multiple times the same `http.Client` instance.
Just call `gock.InterceptExcerpt of 9,842 characters
Read on GitHub158
3
2
2
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:2e94803f2d8f28d5, topic:testing