Aduket is a straight-forward HTTP client testing tool for Go. It provides a lean way to spin up a mock HTTP server to imitate different responses and assert that your HTTP client is behaving as expected.
- Lean Mock Server: Easily spin up HTTP or HTTPS (TLS) servers.
- Expectations: Register expectations for specific methods, paths, and query parameters.
- Simulated Delays: Test how your client handles slow responses.
- Dynamic Responders: Use full
http.HandlerFunclogic for complex responses. - WebSocket Support: Easily test WebSocket connections and message flows.
- Request Recording: Every request is recorded and can be retrieved for detailed inspection.
- Assertion Helpers: Built-in helpers for status codes, call counts, and JSON bodies.
go get github.com/ismailtsdln/adukets := aduket.NewServer()
defer s.Close()
s.Expect("GET", "/hello").Response(http.StatusOK, "world")
resp, _ := http.Get(s.URL + "/hello")
// ...
s.AssertCalled(t, "GET", "/hello")s.Expect("GET", "/slow").
Delay(2 * time.Second).
Response(http.StatusOK, "slow response")s.Expect("GET", "/ws").RespondWith(func(w http.ResponseWriter, r *http.Request) {
conn, _ := s.Upgrade(w, r)
defer conn.Close()
// Handle websocket...
})s.Expect("POST", "/api/user").Response(http.StatusCreated, "Created")
// After making a request with JSON body:
s.AssertRequestBodyJSON(t, 0, map[string]interface{}{
"name": "ismail",
})s.Expect("GET", "/search").
WithQuery("q", "aduket").
Response(http.StatusOK, "found")s := aduket.NewTLSServer()
defer s.Close()
// Use s.URL with a client configured to Trust the server (or InsecureSkipVerify)Aduket comes with a visually rich TUI for real-time monitoring of your mock server.
go run cmd/aduket/main.goYou can load expectations from a JSON file:
{
"expectations": [
{
"method": "GET",
"path": "/api/v1/health",
"status": 200,
"response": "{\"status\":\"ok\"}"
}
]
}Run with:
go run cmd/aduket/main.go -config config.json-
Real-time Monitoring: See requests as they hit the server.
-
Request Inspection: Select a request to see full headers and body.
-
Side-by-side Layout: Modern dashboard with filter/search capabilities.
-
Visual Feedback: Color-coded HTTP methods and premium styling.
-
Panic Recovery: The mock server automatically recovers from panics in your responders and returns a 500 status.
-
Request Size Limiting: Control memory usage with
s.MaxRequestBodySize. -
Automatic Verification: Use
s.Verify(t)at the end of your test to ensure all registered expectations were met. -
Improved Errors: Clear error messages when no expectation matches provide details about the received method and path.
-
Validation: Empty method expectations will trigger a panic to catch configuration errors early.
MIT