@@ -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
1413type ProdExecutor struct {
1514 * http.Client
1615}
1716
17+ // SetCookieJar func to wrap c.Jar = jar
1818func (c * ProdExecutor ) SetCookieJar (jar http.CookieJar ) {
1919 c .Jar = jar
2020}
2121
22+ // SetCookies wraps http.Client.Jar.SetCookies
2223func (c * ProdExecutor ) SetCookies (url * url.URL , cookies []* http.Cookie ) {
2324 c .Jar .SetCookies (url , cookies )
2425}
2526
27+ // SetCustomTimeout wraps http.Client.Timeout = timeout
2628func (c * ProdExecutor ) SetCustomTimeout (timeout time.Duration ) {
2729 c .Timeout = timeout
2830}
2931
32+ // Cookies wraps http.Client.Jar.Cookies()
3033func (c * ProdExecutor ) Cookies (url * url.URL ) []* http.Cookie {
3134 return c .Jar .Cookies (url )
3235}
3336
37+ // SetRedirectPolicy wraps http.Client.Jar.CheckRedirect =
3438func (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
4045type MockExecutor struct {
4146 LockedResponseCode int
4247 ResponseBody string
4348}
4449
50+ // CloseIdleConnections does nothing.
4551func (m * MockExecutor ) CloseIdleConnections () {
46- panic ("invalid function call" )
4752}
4853
54+ // Do returns a http.Response with controllable body and status code.
4955func (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
6572func (m * MockExecutor ) Get (_ string ) (* http.Response , error ) {
6673 return m .Do (nil )
6774}
6875
76+ // Head returns Do
6977func (m * MockExecutor ) Head (_ string ) (* http.Response , error ) {
7078 return m .Do (nil )
7179}
7280
81+ // Post returns Do
7382func (m * MockExecutor ) Post (_ string , _ string , _ io.Reader ) (* http.Response , error ) {
7483 return m .Do (nil )
7584}
7685
86+ // PostForm returns Do
7787func (m * MockExecutor ) PostForm (_ string , _ url.Values ) (* http.Response , error ) {
7888 return m .Do (nil )
7989}
8090
91+ // SetCookieJar does nothing yet
8192func (m * MockExecutor ) SetCookieJar (jar http.CookieJar ) {}
8293
94+ // SetCookies does nothing yet
8395func (m * MockExecutor ) SetCookies (url * url.URL , cookies []* http.Cookie ) {}
8496
97+ // SetCustomTimeout does nothing yet
8598func (m * MockExecutor ) SetCustomTimeout (time.Duration ) {}
8699
100+ // Cookies does nothing yet
87101func (m * MockExecutor ) Cookies (* url.URL ) []* http.Cookie {
88102 return nil
89103}
90104
105+ // SetRedirectPolicy does nothing
91106func (m * MockExecutor ) SetRedirectPolicy (* func (req * http.Request , via []* http.Request ) error ) {}
0 commit comments