Skip to content

Commit 4532347

Browse files
committed
mock function comments
1 parent 18b22e0 commit 4532347

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

httpclient/client.go

+2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import (
1919
"go.uber.org/zap"
2020
)
2121

22+
// HTTPExecutor is an interface which wraps http.Client
2223
type HTTPExecutor interface {
24+
2325
// Inherited
2426
CloseIdleConnections()
2527
Do(req *http.Request) (*http.Response, error)

httpclient/cookies.go

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66

77
// loadCustomCookies applies the custom cookies supplied in the config and applies them to the http session.
88
func (c *Client) loadCustomCookies() error {
9-
c.Sugar.Debug("initilizing cookie jar")
10-
119
cookieUrl, err := url.Parse((*c.Integration).GetFQDN())
1210
c.Sugar.Debug("cookie URL set globally to: %s", cookieUrl)
1311
if err != nil {

httpclient/http.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,49 @@ import (
99
"time"
1010
)
1111

12-
// Production
13-
12+
// ProdExecutor wraps http.Client and implements functions to adjust some of it's attrs
1413
type ProdExecutor struct {
1514
*http.Client
1615
}
1716

17+
// SetCookieJar func to wrap c.Jar = jar
1818
func (c *ProdExecutor) SetCookieJar(jar http.CookieJar) {
1919
c.Jar = jar
2020
}
2121

22+
// SetCookies wraps http.Client.Jar.SetCookies
2223
func (c *ProdExecutor) SetCookies(url *url.URL, cookies []*http.Cookie) {
2324
c.Jar.SetCookies(url, cookies)
2425
}
2526

27+
// SetCustomTimeout wraps http.Client.Timeout = timeout
2628
func (c *ProdExecutor) SetCustomTimeout(timeout time.Duration) {
2729
c.Timeout = timeout
2830
}
2931

32+
// Cookies wraps http.Client.Jar.Cookies()
3033
func (c *ProdExecutor) Cookies(url *url.URL) []*http.Cookie {
3134
return c.Jar.Cookies(url)
3235
}
3336

37+
// SetRedirectPolicy wraps http.Client.Jar.CheckRedirect =
3438
func (c *ProdExecutor) SetRedirectPolicy(policy *func(req *http.Request, via []*http.Request) error) {
3539
c.CheckRedirect = *policy
3640
}
3741

3842
// Mocking
3943

44+
// MockExecutor implements the same function pattern above but allows controllable responses for mocking/testing
4045
type MockExecutor struct {
4146
LockedResponseCode int
4247
ResponseBody string
4348
}
4449

50+
// CloseIdleConnections does nothing.
4551
func (m *MockExecutor) CloseIdleConnections() {
46-
panic("invalid function call")
4752
}
4853

54+
// Do returns a http.Response with controllable body and status code.
4955
func (m *MockExecutor) Do(req *http.Request) (*http.Response, error) {
5056
statusString := http.StatusText(m.LockedResponseCode)
5157

@@ -62,30 +68,39 @@ func (m *MockExecutor) Do(req *http.Request) (*http.Response, error) {
6268
return response, nil
6369
}
6470

71+
// Get returns Do
6572
func (m *MockExecutor) Get(_ string) (*http.Response, error) {
6673
return m.Do(nil)
6774
}
6875

76+
// Head returns Do
6977
func (m *MockExecutor) Head(_ string) (*http.Response, error) {
7078
return m.Do(nil)
7179
}
7280

81+
// Post returns Do
7382
func (m *MockExecutor) Post(_ string, _ string, _ io.Reader) (*http.Response, error) {
7483
return m.Do(nil)
7584
}
7685

86+
// PostForm returns Do
7787
func (m *MockExecutor) PostForm(_ string, _ url.Values) (*http.Response, error) {
7888
return m.Do(nil)
7989
}
8090

91+
// SetCookieJar does nothing yet
8192
func (m *MockExecutor) SetCookieJar(jar http.CookieJar) {}
8293

94+
// SetCookies does nothing yet
8395
func (m *MockExecutor) SetCookies(url *url.URL, cookies []*http.Cookie) {}
8496

97+
// SetCustomTimeout does nothing yet
8598
func (m *MockExecutor) SetCustomTimeout(time.Duration) {}
8699

100+
// Cookies does nothing yet
87101
func (m *MockExecutor) Cookies(*url.URL) []*http.Cookie {
88102
return nil
89103
}
90104

105+
// SetRedirectPolicy does nothing
91106
func (m *MockExecutor) SetRedirectPolicy(*func(req *http.Request, via []*http.Request) error) {}

0 commit comments

Comments
 (0)