From 6ad880ce57f42586729e0e7e90be1bceefa68a68 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Mon, 11 May 2020 02:37:57 -0700 Subject: [PATCH] Improving test case coverage --- request_test.go | 36 ++++++++++++++++++++---------------- retry_test.go | 2 ++ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/request_test.go b/request_test.go index ba437516..89760454 100644 --- a/request_test.go +++ b/request_test.go @@ -828,20 +828,8 @@ func TestGetWithCookies(t *testing.T) { ts := createGetServer(t) defer ts.Close() - cookies := []*http.Cookie{ - { - Name: "go-resty-1", - Value: "This is cookie 1 value", - }, - { - Name: "go-resty-2", - Value: "This is cookie 2 value", - }, - } - c := dc() - c.SetHostURL(ts.URL). - SetCookies(cookies) + c.SetHostURL(ts.URL).SetDebug(true) tu, _ := url.Parse(ts.URL) c.GetClient().Jar.SetCookies(tu, []*http.Cookie{ @@ -855,10 +843,26 @@ func TestGetWithCookies(t *testing.T) { }, }) - resp, err := c.R(). - SetCookie(&http.Cookie{ + resp, err := c.R().SetHeader("Cookie", "").Get("mypage2") + assertError(t, err) + assertEqual(t, http.StatusOK, resp.StatusCode()) + + // Client cookies + c.SetCookies([]*http.Cookie{ + { Name: "go-resty-1", - Value: "This is cookie 1 value additional append", + Value: "This is cookie 1 value", + }, + { + Name: "go-resty-2", + Value: "This is cookie 2 value", + }, + }) + + resp, err = c.R(). + SetCookie(&http.Cookie{ + Name: "req-go-resty-1", + Value: "This is request cookie 1 value additional append", }). Get("mypage2") diff --git a/retry_test.go b/retry_test.go index a078b52b..b9b36dcd 100644 --- a/retry_test.go +++ b/retry_test.go @@ -146,6 +146,7 @@ func TestClientRetryGet(t *testing.T) { resp, err := c.R().Get(ts.URL + "/set-retrycount-test") assertEqual(t, "", resp.Status()) + assertEqual(t, "", resp.Proto()) assertEqual(t, 0, resp.StatusCode()) assertEqual(t, 0, len(resp.Cookies())) assertNotNil(t, resp.Body()) @@ -609,6 +610,7 @@ func TestClientRetryCount(t *testing.T) { resp, err := c.R().Get(ts.URL + "/set-retrycount-test") assertEqual(t, "", resp.Status()) + assertEqual(t, "", resp.Proto()) assertEqual(t, 0, resp.StatusCode()) assertEqual(t, 0, len(resp.Cookies())) assertNotNil(t, resp.Body())