| Conditions | 4 |
| Total Lines | 69 |
| Code Lines | 47 |
| 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 |
||
| 39 | func TestShouldForwardProvidedCookiesWhenUsingJar(t *testing.T) { |
||
| 40 | const ( |
||
| 41 | serverCookieName = "server_cookie_name" |
||
| 42 | serverCookieValue = "server_cookie_value" |
||
| 43 | ) |
||
| 44 | |||
| 45 | testServer, serverAssertion := test.NewServerWithAssertion( |
||
| 46 | http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
||
| 47 | http.SetCookie( |
||
| 48 | w, |
||
| 49 | &http.Cookie{ |
||
| 50 | Name: serverCookieName, |
||
| 51 | Value: serverCookieValue, |
||
| 52 | Expires: time.Now().AddDate(0, 1, 0), |
||
| 53 | }, |
||
| 54 | ) |
||
| 55 | }), |
||
| 56 | ) |
||
| 57 | defer testServer.Close() |
||
| 58 | |||
| 59 | u, err := url.Parse(testServer.URL) |
||
| 60 | assert.NoError(t, err) |
||
| 61 | |||
| 62 | cookies := []*http.Cookie{ |
||
| 63 | { |
||
| 64 | Name: "a_cookie_name", |
||
| 65 | Value: "a_cookie_value", |
||
| 66 | }, |
||
| 67 | } |
||
| 68 | |||
| 69 | c, err := client.NewClientFromConfig( |
||
| 70 | 100, |
||
| 71 | nil, |
||
| 72 | "", |
||
| 73 | true, |
||
| 74 | cookies, |
||
| 75 | u, |
||
| 76 | ) |
||
| 77 | assert.NoError(t, err) |
||
| 78 | |||
| 79 | res, err := c.Get(testServer.URL) |
||
| 80 | assert.NoError(t, err) |
||
| 81 | assert.NotNil(t, res) |
||
| 82 | |||
| 83 | assert.Equal(t, 1, serverAssertion.Len()) |
||
| 84 | |||
| 85 | serverAssertion.At(0, func(r http.Request) { |
||
| 86 | assert.Equal(t, 1, len(r.Cookies())) |
||
| 87 | |||
| 88 | assert.Equal(t, r.Cookies()[0].Name, cookies[0].Name) |
||
| 89 | assert.Equal(t, r.Cookies()[0].Value, cookies[0].Value) |
||
| 90 | assert.Equal(t, r.Cookies()[0].Expires, cookies[0].Expires) |
||
| 91 | }) |
||
| 92 | |||
| 93 | res, err = c.Get(testServer.URL) |
||
| 94 | assert.NoError(t, err) |
||
| 95 | assert.NotNil(t, res) |
||
| 96 | |||
| 97 | assert.Equal(t, 2, serverAssertion.Len()) |
||
| 98 | |||
| 99 | serverAssertion.At(1, func(r http.Request) { |
||
| 100 | assert.Equal(t, 2, len(r.Cookies())) |
||
| 101 | |||
| 102 | assert.Equal(t, r.Cookies()[0].Name, cookies[0].Name) |
||
| 103 | assert.Equal(t, r.Cookies()[0].Value, cookies[0].Value) |
||
| 104 | assert.Equal(t, r.Cookies()[0].Expires, cookies[0].Expires) |
||
| 105 | |||
| 106 | assert.Equal(t, r.Cookies()[1].Name, serverCookieName) |
||
| 107 | assert.Equal(t, r.Cookies()[1].Value, serverCookieValue) |
||
| 108 | }) |
||
| 168 |