Record and replay HTTP response for testing
Replay HTTP response or fetch from the remote:
import (
"net/http"
"testing"
httpreplay "github.com/aereal/go-http-replay"
)
func Test_http_lib(t *testing.T) {
httpClient := &http.Client{
Transport: httpreplay.NewReplayOrFetchTransport("./testdata", http.DefaultClient),
}
// httpClient will behave like the client that created from NewReplayTransport but DO actual request if local cache is missing.
}
Only replay HTTP response from cache:
import (
"net/http"
"testing"
httpreplay "github.com/aereal/go-http-replay"
)
func Test_http_lib(t *testing.T) {
httpClient := &http.Client{
Transport: httpreplay.NewReplayTransport("./testdata"),
}
// httpClient will not do actual request to remote sites but returns the response from local cache files.
}
- https://github.com/vcr/vcr - go-http-replay is heavily inspired from this project
- aereal