From 689b755186f4a8725aee1d38e057f4c54e03df79 Mon Sep 17 00:00:00 2001 From: Anton Baklanov Date: Sun, 14 May 2017 19:24:18 +0300 Subject: [PATCH 1/3] Allow setting any `http.RoundTripper` as transport Instead of limiting users to `*http.Transport` only. --- client.go | 68 ++++++++++++++++++++++++++++++++++++-------------- client_test.go | 28 ++++++++++++++++----- default.go | 8 +++--- resty_test.go | 18 ++++++++++--- 4 files changed, 89 insertions(+), 33 deletions(-) diff --git a/client.go b/client.go index 187d71ba..92a42721 100644 --- a/client.go +++ b/client.go @@ -10,6 +10,7 @@ import ( "crypto/x509" "encoding/json" "encoding/xml" + "errors" "fmt" "io" "io/ioutil" @@ -88,7 +89,6 @@ type Client struct { RetryConditions []RetryConditionFunc httpClient *http.Client - transport *http.Transport setContentLength bool isHTTPMode bool outputDirectory string @@ -538,8 +538,12 @@ func (c *Client) Mode() string { // Note: This method overwrites existing `TLSClientConfig`. // func (c *Client) SetTLSClientConfig(config *tls.Config) *Client { - c.transport.TLSClientConfig = config - c.httpClient.Transport = c.transport + transport, err := c.getHttpTransport() + if err != nil { + c.Log.Printf("ERROR [%v]", err) + return c + } + transport.TLSClientConfig = config return c } @@ -550,10 +554,14 @@ func (c *Client) SetTLSClientConfig(config *tls.Config) *Client { // you can also set Proxy via environment variable. By default `Go` uses setting from `HTTP_PROXY`. // func (c *Client) SetProxy(proxyURL string) *Client { + transport, err := c.getHttpTransport() + if err != nil { + c.Log.Printf("ERROR [%v]", err) + return c + } if pURL, err := url.Parse(proxyURL); err == nil { c.proxyURL = pURL - c.transport.Proxy = http.ProxyURL(c.proxyURL) - c.httpClient.Transport = c.transport + transport.Proxy = http.ProxyURL(c.proxyURL) } else { c.Log.Printf("ERROR [%v]", err) c.RemoveProxy() @@ -566,17 +574,24 @@ func (c *Client) SetProxy(proxyURL string) *Client { // resty.RemoveProxy() // func (c *Client) RemoveProxy() *Client { + transport, err := c.getHttpTransport() + if err != nil { + c.Log.Printf("ERROR [%v]", err) + return c + } c.proxyURL = nil - c.transport.Proxy = nil - c.httpClient.Transport = c.transport - + transport.Proxy = nil return c } // SetCertificates method helps to set client certificates into resty conveniently. // func (c *Client) SetCertificates(certs ...tls.Certificate) *Client { - config := c.getTLSConfig() + config, err := c.getTLSConfig() + if err != nil { + c.Log.Printf("ERROR [%v]", err) + return c + } config.Certificates = append(config.Certificates, certs...) return c } @@ -591,7 +606,11 @@ func (c *Client) SetRootCertificate(pemFilePath string) *Client { return c } - config := c.getTLSConfig() + config, err := c.getTLSConfig() + if err != nil { + c.Log.Printf("ERROR [%v]", err) + return c + } if config.RootCAs == nil { config.RootCAs = x509.NewCertPool() } @@ -629,12 +648,10 @@ func (c *Client) SetOutputDirectory(dirPath string) *Client { // // resty.SetTransport(transport) // -func (c *Client) SetTransport(transport *http.Transport) *Client { +func (c *Client) SetTransport(transport http.RoundTripper) *Client { if transport != nil { - c.transport = transport - c.httpClient.Transport = c.transport + c.httpClient.Transport = transport } - return c } @@ -737,12 +754,25 @@ func (c *Client) disableLogPrefix() { } // getting TLS client config if not exists then create one -func (c *Client) getTLSConfig() *tls.Config { - if c.transport.TLSClientConfig == nil { - c.transport.TLSClientConfig = &tls.Config{} - c.httpClient.Transport = c.transport +func (c *Client) getTLSConfig() (*tls.Config, error) { + transport, err := c.getHttpTransport() + if err != nil { + return nil, err + } + if transport.TLSClientConfig == nil { + transport.TLSClientConfig = &tls.Config{} + } + return transport.TLSClientConfig, nil +} + +// returns `*http.Transport` currently in use or error +// in case currently used `transport` is not an `*http.Transport` +func (c *Client) getHttpTransport() (*http.Transport, error) { + if transport, ok := c.httpClient.Transport.(*http.Transport); ok { + return transport, nil + } else { + return nil, errors.New("Current transport is not an *http.Transport") } - return c.transport.TLSClientConfig } // diff --git a/client_test.go b/client_test.go index 9c97fb56..82209831 100644 --- a/client_test.go +++ b/client_test.go @@ -152,21 +152,30 @@ func TestSetCertificates(t *testing.T) { DefaultClient = dc() SetCertificates(tls.Certificate{}) - assertEqual(t, 1, len(DefaultClient.transport.TLSClientConfig.Certificates)) + transport, err := DefaultClient.getHttpTransport() + + assertNil(t, err) + assertEqual(t, 1, len(transport.TLSClientConfig.Certificates)) } func TestSetRootCertificate(t *testing.T) { DefaultClient = dc() SetRootCertificate(getTestDataPath() + "/sample-root.pem") - assertEqual(t, true, DefaultClient.transport.TLSClientConfig.RootCAs != nil) + transport, err := DefaultClient.getHttpTransport() + + assertNil(t, err) + assertEqual(t, true, transport.TLSClientConfig.RootCAs != nil) } func TestSetRootCertificateNotExists(t *testing.T) { DefaultClient = dc() SetRootCertificate(getTestDataPath() + "/not-exists-sample-root.pem") - assertEqual(t, true, DefaultClient.transport.TLSClientConfig == nil) + transport, err := DefaultClient.getHttpTransport() + + assertNil(t, err) + assertEqual(t, true, transport.TLSClientConfig == nil) } func TestOnBeforeRequestModification(t *testing.T) { @@ -196,14 +205,18 @@ func TestSetTransport(t *testing.T) { DefaultClient = dc() transport := &http.Transport{ - // somthing like Proxying to httptest.Server, etc... + // something like Proxying to httptest.Server, etc... Proxy: func(req *http.Request) (*url.URL, error) { return url.Parse(ts.URL) }, } SetTransport(transport) - assertEqual(t, true, DefaultClient.transport != nil) + transportInUse, err := DefaultClient.getHttpTransport() + + assertNil(t, err) + + assertEqual(t, true, transport == transportInUse) } func TestSetScheme(t *testing.T) { @@ -296,7 +309,10 @@ func TestClientOptions(t *testing.T) { } SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}) - assertEqual(t, true, DefaultClient.transport.TLSClientConfig.InsecureSkipVerify) + transport, transportErr := DefaultClient.getHttpTransport() + + assertNil(t, transportErr) + assertEqual(t, true, transport.TLSClientConfig.InsecureSkipVerify) OnBeforeRequest(func(c *Client, r *Request) error { c.Log.Println("I'm in Request middleware") diff --git a/default.go b/default.go index 2c4cffa4..df0914c7 100644 --- a/default.go +++ b/default.go @@ -37,10 +37,10 @@ func New() *Client { RetryWaitTime: defaultWaitTime, RetryMaxWaitTime: defaultMaxWaitTime, httpClient: &http.Client{Jar: cookieJar}, - transport: &http.Transport{}, } - c.httpClient.Transport = c.transport + // Default transport + c.SetTransport(&http.Transport{}) // Default redirect policy c.SetRedirectPolicy(NoRedirectPolicy()) @@ -236,9 +236,9 @@ func SetOutputDirectory(dirPath string) *Client { return DefaultClient.SetOutputDirectory(dirPath) } -// SetTransport method sets custom *http.Transport in the resty client. +// SetTransport method sets custom http.RoundTripper in the resty client. // See `Client.SetTransport` for more information. -func SetTransport(transport *http.Transport) *Client { +func SetTransport(transport http.RoundTripper) *Client { return DefaultClient.SetTransport(transport) } diff --git a/resty_test.go b/resty_test.go index df3bb8f2..01e68fae 100644 --- a/resty_test.go +++ b/resty_test.go @@ -850,22 +850,26 @@ func TestRawFileUploadByBody(t *testing.T) { func TestProxySetting(t *testing.T) { c := dc() + transport, err := c.getHttpTransport() + + assertNil(t, err) + assertEqual(t, false, c.IsProxySet()) - assertEqual(t, true, (c.transport.Proxy == nil)) + assertEqual(t, true, (transport.Proxy == nil)) c.SetProxy("http://sampleproxy:8888") assertEqual(t, true, c.IsProxySet()) - assertEqual(t, false, (c.transport.Proxy == nil)) + assertEqual(t, false, (transport.Proxy == nil)) c.SetProxy("//not.a.user@%66%6f%6f.com:8888") assertEqual(t, false, c.IsProxySet()) - assertEqual(t, true, (c.transport.Proxy == nil)) + assertEqual(t, true, (transport.Proxy == nil)) SetProxy("http://sampleproxy:8888") assertEqual(t, true, IsProxySet()) RemoveProxy() assertEqual(t, true, (DefaultClient.proxyURL == nil)) - assertEqual(t, true, (DefaultClient.transport.Proxy == nil)) + assertEqual(t, true, (transport.Proxy == nil)) } func TestIncorrectURL(t *testing.T) { @@ -1550,6 +1554,12 @@ func dclr() *Request { return c.R() } +func assertNil(t *testing.T, x interface{}) { + if x != nil { + t.Errorf("[%v] was expected to be nil", x) + } +} + func assertError(t *testing.T, err error) { if err != nil { t.Errorf("Error occurred [%v]", err) From ad4060c3fdfca6e801b03cbe2ca5789ba3f31878 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Thu, 17 Aug 2017 12:01:26 -0700 Subject: [PATCH 2/3] godoc, naming and test case update --- client.go | 24 +++++++++++------- client_test.go | 67 +++++++++++++++++++++++++++++++++++--------------- default.go | 3 ++- resty_test.go | 67 +++++++++++++++++++++++++------------------------- retry_test.go | 6 ++--- 5 files changed, 100 insertions(+), 67 deletions(-) diff --git a/client.go b/client.go index 159bc296..e85088b4 100644 --- a/client.go +++ b/client.go @@ -555,7 +555,7 @@ func (c *Client) Mode() string { // Note: This method overwrites existing `TLSClientConfig`. // func (c *Client) SetTLSClientConfig(config *tls.Config) *Client { - transport, err := c.getHttpTransport() + transport, err := c.getTransport() if err != nil { c.Log.Printf("ERROR [%v]", err) return c @@ -571,7 +571,7 @@ func (c *Client) SetTLSClientConfig(config *tls.Config) *Client { // you can also set Proxy via environment variable. By default `Go` uses setting from `HTTP_PROXY`. // func (c *Client) SetProxy(proxyURL string) *Client { - transport, err := c.getHttpTransport() + transport, err := c.getTransport() if err != nil { c.Log.Printf("ERROR [%v]", err) return c @@ -591,7 +591,7 @@ func (c *Client) SetProxy(proxyURL string) *Client { // resty.RemoveProxy() // func (c *Client) RemoveProxy() *Client { - transport, err := c.getHttpTransport() + transport, err := c.getTransport() if err != nil { c.Log.Printf("ERROR [%v]", err) return c @@ -653,9 +653,16 @@ func (c *Client) SetOutputDirectory(dirPath string) *Client { return c } -// SetTransport method sets custom *http.Transport in the resty client. Its way to override default. +// SetTransport method sets custom `*http.Transport` or any `http.RoundTripper` +// compatible interface implementation in the resty client. +// +// Please Note: +// +// - If transport is not type of `*http.Transport` then you may not be able to +// take advantage of some of the `resty` client settings. +// +// - It overwrites the resty client transport instance and it's configurations. // -// **Note:** It overwrites the default resty transport instance and its configurations. // transport := &http.Transport{ // // somthing like Proxying to httptest.Server, etc... // Proxy: func(req *http.Request) (*url.URL, error) { @@ -787,7 +794,7 @@ func (c *Client) disableLogPrefix() { // getting TLS client config if not exists then create one func (c *Client) getTLSConfig() (*tls.Config, error) { - transport, err := c.getHttpTransport() + transport, err := c.getTransport() if err != nil { return nil, err } @@ -799,12 +806,11 @@ func (c *Client) getTLSConfig() (*tls.Config, error) { // returns `*http.Transport` currently in use or error // in case currently used `transport` is not an `*http.Transport` -func (c *Client) getHttpTransport() (*http.Transport, error) { +func (c *Client) getTransport() (*http.Transport, error) { if transport, ok := c.httpClient.Transport.(*http.Transport); ok { return transport, nil - } else { - return nil, errors.New("Current transport is not an *http.Transport") } + return nil, errors.New("current transport is not an *http.Transport instance") } // diff --git a/client_test.go b/client_test.go index 3607aea5..c5bd5130 100644 --- a/client_test.go +++ b/client_test.go @@ -136,49 +136,49 @@ func TestClientProxy(t *testing.T) { c.SetProxy("http://sampleproxy:8888") resp, err := c.R().Get(ts.URL) - assertEqual(t, true, resp != nil) - assertEqual(t, true, err != nil) + assertNotNil(t, resp) + assertNotNil(t, err) // Error c.SetProxy("//not.a.user@%66%6f%6f.com:8888") resp, err = c.R(). Get(ts.URL) - assertEqual(t, true, err == nil) - assertEqual(t, false, resp == nil) + assertNil(t, err) + assertNil(t, resp) } -func TestSetCertificates(t *testing.T) { +func TestClientSetCertificates(t *testing.T) { DefaultClient = dc() SetCertificates(tls.Certificate{}) - transport, err := DefaultClient.getHttpTransport() + transport, err := DefaultClient.getTransport() assertNil(t, err) assertEqual(t, 1, len(transport.TLSClientConfig.Certificates)) } -func TestSetRootCertificate(t *testing.T) { +func TestClientSetRootCertificate(t *testing.T) { DefaultClient = dc() SetRootCertificate(getTestDataPath() + "/sample-root.pem") - transport, err := DefaultClient.getHttpTransport() + transport, err := DefaultClient.getTransport() assertNil(t, err) - assertEqual(t, true, transport.TLSClientConfig.RootCAs != nil) + assertNotNil(t, transport.TLSClientConfig.RootCAs) } -func TestSetRootCertificateNotExists(t *testing.T) { +func TestClientSetRootCertificateNotExists(t *testing.T) { DefaultClient = dc() SetRootCertificate(getTestDataPath() + "/not-exists-sample-root.pem") - transport, err := DefaultClient.getHttpTransport() + transport, err := DefaultClient.getTransport() assertNil(t, err) - assertEqual(t, true, transport.TLSClientConfig == nil) + assertNil(t, transport.TLSClientConfig) } -func TestOnBeforeRequestModification(t *testing.T) { +func TestClientOnBeforeRequestModification(t *testing.T) { tc := New() tc.OnBeforeRequest(func(c *Client, r *Request) error { r.SetAuthToken("This is test auth token") @@ -193,13 +193,13 @@ func TestOnBeforeRequestModification(t *testing.T) { assertError(t, err) assertEqual(t, http.StatusOK, resp.StatusCode()) assertEqual(t, "200 OK", resp.Status()) - assertEqual(t, true, resp.Body() != nil) + assertNotNil(t, resp.Body()) assertEqual(t, "TestGet: text response", resp.String()) logResponse(t, resp) } -func TestSetTransport(t *testing.T) { +func TestClientSetTransport(t *testing.T) { ts := createGetServer(t) defer ts.Close() DefaultClient = dc() @@ -212,14 +212,14 @@ func TestSetTransport(t *testing.T) { } SetTransport(transport) - transportInUse, err := DefaultClient.getHttpTransport() + transportInUse, err := DefaultClient.getTransport() assertNil(t, err) assertEqual(t, true, transport == transportInUse) } -func TestSetScheme(t *testing.T) { +func TestClientSetScheme(t *testing.T) { DefaultClient = dc() SetScheme("http") @@ -227,12 +227,12 @@ func TestSetScheme(t *testing.T) { assertEqual(t, true, DefaultClient.scheme == "http") } -func TestSetCookieJar(t *testing.T) { +func TestClientSetCookieJar(t *testing.T) { DefaultClient = dc() backupJar := DefaultClient.httpClient.Jar SetCookieJar(nil) - assertEqual(t, true, DefaultClient.httpClient.Jar == nil) + assertNil(t, DefaultClient.httpClient.Jar) SetCookieJar(backupJar) assertEqual(t, true, DefaultClient.httpClient.Jar == backupJar) @@ -317,7 +317,7 @@ func TestClientOptions(t *testing.T) { } SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}) - transport, transportErr := DefaultClient.getHttpTransport() + transport, transportErr := DefaultClient.getTransport() assertNil(t, transportErr) assertEqual(t, true, transport.TLSClientConfig.InsecureSkipVerify) @@ -379,3 +379,30 @@ func TestClientAllowsGetMethodPayload(t *testing.T) { assertEqual(t, http.StatusOK, resp.StatusCode()) assertEqual(t, payload, resp.String()) } + +func TestClientRoundTripper(t *testing.T) { + c := New() + + rt := &CustomRoundTripper{} + c.SetTransport(rt) + + ct, err := c.getTransport() + assertNotNil(t, err) + assertNil(t, ct) + assertEqual(t, "current transport is not an *http.Transport instance", err.Error()) + + c.SetTLSClientConfig(&tls.Config{}) + c.SetProxy("http://localhost:9090") + c.RemoveProxy() + c.SetCertificates(tls.Certificate{}) + c.SetRootCertificate(getTestDataPath() + "/sample-root.pem") +} + +// CustomRoundTripper just for test +type CustomRoundTripper struct { +} + +// RoundTrip just for test +func (rt *CustomRoundTripper) RoundTrip(_ *http.Request) (*http.Response, error) { + return &http.Response{}, nil +} diff --git a/default.go b/default.go index 906b3ab8..420059ae 100644 --- a/default.go +++ b/default.go @@ -254,7 +254,8 @@ func SetOutputDirectory(dirPath string) *Client { return DefaultClient.SetOutputDirectory(dirPath) } -// SetTransport method sets custom http.RoundTripper in the resty client. +// SetTransport method sets custom `*http.Transport` or any `http.RoundTripper` +// compatible interface implementation in the resty client. // See `Client.SetTransport` for more information. func SetTransport(transport http.RoundTripper) *Client { return DefaultClient.SetTransport(transport) diff --git a/resty_test.go b/resty_test.go index a7fd8aff..9d38c511 100644 --- a/resty_test.go +++ b/resty_test.go @@ -45,7 +45,7 @@ func TestGet(t *testing.T) { assertError(t, err) assertEqual(t, http.StatusOK, resp.StatusCode()) assertEqual(t, "200 OK", resp.Status()) - assertEqual(t, true, resp.Body() != nil) + assertNotNil(t, resp.Body()) assertEqual(t, "TestGet: text response", resp.String()) logResponse(t, resp) @@ -791,7 +791,7 @@ func TestHostCheckRedirectPolicy(t *testing.T) { _, err := c.R().Get(ts.URL + "/redirect-host-check-1") - assertEqual(t, true, err != nil) + assertNotNil(t, err) assertEqual(t, true, strings.Contains(err.Error(), "Redirect is not allowed as per DomainCheckRedirectPolicy")) } @@ -850,26 +850,26 @@ func TestRawFileUploadByBody(t *testing.T) { func TestProxySetting(t *testing.T) { c := dc() - transport, err := c.getHttpTransport() + transport, err := c.getTransport() assertNil(t, err) assertEqual(t, false, c.IsProxySet()) - assertEqual(t, true, (transport.Proxy == nil)) + assertNil(t, transport.Proxy) c.SetProxy("http://sampleproxy:8888") assertEqual(t, true, c.IsProxySet()) - assertEqual(t, false, (transport.Proxy == nil)) + assertNotNil(t, transport.Proxy) c.SetProxy("//not.a.user@%66%6f%6f.com:8888") assertEqual(t, false, c.IsProxySet()) - assertEqual(t, true, (transport.Proxy == nil)) + assertNil(t, transport.Proxy) SetProxy("http://sampleproxy:8888") assertEqual(t, true, IsProxySet()) RemoveProxy() - assertEqual(t, true, (DefaultClient.proxyURL == nil)) - assertEqual(t, true, (transport.Proxy == nil)) + assertNil(t, DefaultClient.proxyURL) + assertNil(t, transport.Proxy) } func TestIncorrectURL(t *testing.T) { @@ -1127,7 +1127,7 @@ func TestSRV(t *testing.T) { resp, err := r.Get("/") assertError(t, err) - assertEqual(t, true, (resp != nil)) + assertNotNil(t, resp) if resp != nil { assertEqual(t, http.StatusOK, resp.StatusCode()) } @@ -1138,7 +1138,7 @@ func TestSRVInvalidService(t *testing.T) { SetSRV(&SRVRecord{"nonexistantservice", "sampledomain"}). Get("/") - assertEqual(t, true, (err != nil)) + assertNotNil(t, err) assertEqual(t, true, strings.Contains(err.Error(), "no such host")) } @@ -1185,7 +1185,7 @@ func TestRequestDoNotParseResponse(t *testing.T) { assertError(t, err) resp.RawResponse = nil - assertEqual(t, true, resp.RawBody() == nil) + assertNil(t, resp.RawBody()) // just set test part SetDoNotParseResponse(true) @@ -1618,9 +1618,15 @@ func dclr() *Request { return c.R() } -func assertNil(t *testing.T, x interface{}) { - if x != nil { - t.Errorf("[%v] was expected to be nil", x) +func assertNil(t *testing.T, v interface{}) { + if !isNil(v) { + t.Errorf("[%v] was expected to be nil", v) + } +} + +func assertNotNil(t *testing.T, v interface{}) { + if isNil(v) { + t.Errorf("[%v] was expected to be non-nil", v) } } @@ -1631,8 +1637,7 @@ func assertError(t *testing.T, err error) { } func assertEqual(t *testing.T, e, g interface{}) (r bool) { - r = compare(e, g) - if !r { + if !equal(e, g) { t.Errorf("Expected [%v], got [%v]", e, g) } @@ -1640,7 +1645,7 @@ func assertEqual(t *testing.T, e, g interface{}) (r bool) { } func assertNotEqual(t *testing.T, e, g interface{}) (r bool) { - if compare(e, g) { + if equal(e, g) { t.Errorf("Expected [%v], got [%v]", e, g) } else { r = true @@ -1649,28 +1654,22 @@ func assertNotEqual(t *testing.T, e, g interface{}) (r bool) { return } -func compare(e, g interface{}) (r bool) { - ev := reflect.ValueOf(e) - gv := reflect.ValueOf(g) +func equal(expected, got interface{}) bool { + return reflect.DeepEqual(expected, got) +} - if ev.Kind() != gv.Kind() { - return +func isNil(v interface{}) bool { + if v == nil { + return true } - switch ev.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - r = (ev.Int() == gv.Int()) - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - r = (ev.Uint() == gv.Uint()) - case reflect.Float32, reflect.Float64: - r = (ev.Float() == gv.Float()) - case reflect.String: - r = (ev.String() == gv.String()) - case reflect.Bool: - r = (ev.Bool() == gv.Bool()) + rv := reflect.ValueOf(v) + kind := rv.Kind() + if kind >= reflect.Chan && kind <= reflect.Slice && rv.IsNil() { + return true } - return + return false } func logResponse(t *testing.T, resp *Response) { diff --git a/retry_test.go b/retry_test.go index 854853b1..5a5f9b6a 100644 --- a/retry_test.go +++ b/retry_test.go @@ -120,7 +120,7 @@ func TestConditionalGet(t *testing.T) { assertError(t, err) assertEqual(t, http.StatusOK, resp.StatusCode()) assertEqual(t, "200 OK", resp.Status()) - assertEqual(t, true, resp.Body() != nil) + assertNotNil(t, resp.Body()) assertEqual(t, "TestGet: text response", resp.String()) assertEqual(t, externalCounter, attemptCount) @@ -154,7 +154,7 @@ func TestConditionalGetDefaultClient(t *testing.T) { assertError(t, err) assertEqual(t, http.StatusOK, resp.StatusCode()) assertEqual(t, "200 OK", resp.Status()) - assertEqual(t, true, resp.Body() != nil) + assertNotNil(t, resp.Body()) assertEqual(t, "TestGet: text response", resp.String()) assertEqual(t, externalCounter, attemptCount) @@ -174,7 +174,7 @@ func TestClientRetryGet(t *testing.T) { assertEqual(t, "", resp.Status()) assertEqual(t, 0, resp.StatusCode()) assertEqual(t, 0, len(resp.Cookies())) - assertEqual(t, true, resp.Body() != nil) + assertNotNil(t, resp.Body()) assertEqual(t, 0, len(resp.Header())) assertEqual(t, true, strings.HasPrefix(err.Error(), "Get "+ts.URL+"/set-retrycount-test")) From cc88910b6f1795e4007b3c6c93126494e64870ac Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Thu, 17 Aug 2017 12:18:25 -0700 Subject: [PATCH 3/3] test case update --- client_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client_test.go b/client_test.go index c5bd5130..49e4b19e 100644 --- a/client_test.go +++ b/client_test.go @@ -145,7 +145,7 @@ func TestClientProxy(t *testing.T) { resp, err = c.R(). Get(ts.URL) assertNil(t, err) - assertNil(t, resp) + assertNotNil(t, resp) } func TestClientSetCertificates(t *testing.T) {