From 0e813523e7bab30545612ee088f72df313a9d66d Mon Sep 17 00:00:00 2001 From: Joseph Little Date: Wed, 24 Jul 2024 14:29:39 +0100 Subject: [PATCH] testing facilitation --- httpclient/client.go | 6 +++--- httpclient/http.go | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/httpclient/client.go b/httpclient/client.go index 27e2c8b..92d1b8a 100644 --- a/httpclient/client.go +++ b/httpclient/client.go @@ -97,6 +97,8 @@ type ClientConfig struct { // RetryEligiableRequests when false bypasses any retry logic for a simpler request flow. RetryEligiableRequests bool `json:"retry_eligiable_requests"` + + HTTPExecutor HTTPExecutor } // BuildClient creates a new HTTP client with the provided configuration. @@ -120,9 +122,7 @@ func (c *ClientConfig) Build() (*Client, error) { c.Sugar.Debug("configuration valid") - httpClient := &prodClient{ - &http.Client{}, - } + httpClient := c.HTTPExecutor cookieJar, err := cookiejar.New(nil) if err != nil { diff --git a/httpclient/http.go b/httpclient/http.go index 4ff4dfd..598dcb1 100644 --- a/httpclient/http.go +++ b/httpclient/http.go @@ -29,3 +29,11 @@ func (c *prodClient) Cookies(url *url.URL) []*http.Cookie { func (c *prodClient) SetRedirectPolicy(policy *func(req *http.Request, via []*http.Request) error) { c.CheckRedirect = *policy } + +type testClient struct { +} + +func (m *testClient) Do(req *http.Request) (*http.Response, error) { + // do some stuff which makes a response you like + return nil, nil +}