| Conditions | 4 |
| Total Lines | 70 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | package client_test |
||
| 40 | func TestShouldForwardProvidedCookiesWhenUsingJar(t *testing.T) { |
||
| 41 | const ( |
||
| 42 | serverCookieName = "server_cookie_name" |
||
| 43 | serverCookieValue = "server_cookie_value" |
||
| 44 | ) |
||
| 45 | |||
| 46 | testServer, serverAssertion := test.NewServerWithAssertion( |
||
| 47 | http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
||
| 48 | http.SetCookie( |
||
| 49 | w, |
||
| 50 | &http.Cookie{ |
||
| 51 | Name: serverCookieName, |
||
| 52 | Value: serverCookieValue, |
||
| 53 | Expires: time.Now().AddDate(0, 1, 0), |
||
| 54 | }, |
||
| 55 | ) |
||
| 56 | }), |
||
| 57 | ) |
||
| 58 | defer testServer.Close() |
||
| 59 | |||
| 60 | u, err := url.Parse(testServer.URL) |
||
| 61 | assert.NoError(t, err) |
||
| 62 | |||
| 63 | cookies := []*http.Cookie{ |
||
| 64 | { |
||
| 65 | Name: "a_cookie_name", |
||
| 66 | Value: "a_cookie_value", |
||
| 67 | }, |
||
| 68 | } |
||
| 69 | |||
| 70 | c, err := client.NewClientFromConfig( |
||
| 71 | 100, |
||
| 72 | nil, |
||
| 73 | "", |
||
| 74 | true, |
||
| 75 | cookies, |
||
| 76 | map[string]string{}, |
||
| 77 | u, |
||
| 78 | ) |
||
| 79 | assert.NoError(t, err) |
||
| 80 | |||
| 81 | res, err := c.Get(testServer.URL) |
||
| 82 | assert.NoError(t, err) |
||
| 83 | assert.NotNil(t, res) |
||
| 84 | |||
| 85 | assert.Equal(t, 1, serverAssertion.Len()) |
||
| 86 | |||
| 87 | serverAssertion.At(0, func(r http.Request) { |
||
| 88 | assert.Equal(t, 1, len(r.Cookies())) |
||
| 89 | |||
| 90 | assert.Equal(t, r.Cookies()[0].Name, cookies[0].Name) |
||
| 91 | assert.Equal(t, r.Cookies()[0].Value, cookies[0].Value) |
||
| 92 | assert.Equal(t, r.Cookies()[0].Expires, cookies[0].Expires) |
||
| 93 | }) |
||
| 94 | |||
| 95 | res, err = c.Get(testServer.URL) |
||
| 96 | assert.NoError(t, err) |
||
| 97 | assert.NotNil(t, res) |
||
| 98 | |||
| 99 | assert.Equal(t, 2, serverAssertion.Len()) |
||
| 100 | |||
| 101 | serverAssertion.At(1, func(r http.Request) { |
||
| 102 | assert.Equal(t, 2, len(r.Cookies())) |
||
| 103 | |||
| 104 | assert.Equal(t, r.Cookies()[0].Name, cookies[0].Name) |
||
| 105 | assert.Equal(t, r.Cookies()[0].Value, cookies[0].Value) |
||
| 106 | assert.Equal(t, r.Cookies()[0].Expires, cookies[0].Expires) |
||
| 107 | |||
| 108 | assert.Equal(t, r.Cookies()[1].Name, serverCookieName) |
||
| 109 | assert.Equal(t, r.Cookies()[1].Value, serverCookieValue) |
||
| 110 | }) |
||
| 208 |