Browse code

client: use constants for http methods

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/10/13 03:41:14
Showing 42 changed files
... ...
@@ -42,7 +42,7 @@ func TestCheckpointCreate(t *testing.T) {
42 42
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
43 43
 			}
44 44
 
45
-			if req.Method != "POST" {
45
+			if req.Method != http.MethodPost {
46 46
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
47 47
 			}
48 48
 
... ...
@@ -38,7 +38,7 @@ func TestCheckpointDelete(t *testing.T) {
38 38
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
39 39
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
40 40
 			}
41
-			if req.Method != "DELETE" {
41
+			if req.Method != http.MethodDelete {
42 42
 				return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
43 43
 			}
44 44
 			return &http.Response{
... ...
@@ -48,7 +48,7 @@ func TestConfigCreate(t *testing.T) {
48 48
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
49 49
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
50 50
 			}
51
-			if req.Method != "POST" {
51
+			if req.Method != http.MethodPost {
52 52
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
53 53
 			}
54 54
 			b, err := json.Marshal(types.ConfigCreateResponse{
... ...
@@ -47,7 +47,7 @@ func TestConfigRemove(t *testing.T) {
47 47
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
48 48
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
49 49
 			}
50
-			if req.Method != "DELETE" {
50
+			if req.Method != http.MethodDelete {
51 51
 				return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
52 52
 			}
53 53
 			return &http.Response{
... ...
@@ -48,7 +48,7 @@ func TestConfigUpdate(t *testing.T) {
48 48
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
49 49
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
50 50
 			}
51
-			if req.Method != "POST" {
51
+			if req.Method != http.MethodPost {
52 52
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
53 53
 			}
54 54
 			return &http.Response{
... ...
@@ -61,7 +61,7 @@ func TestContainerStatPath(t *testing.T) {
61 61
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
62 62
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
63 63
 			}
64
-			if req.Method != "HEAD" {
64
+			if req.Method != http.MethodHead {
65 65
 				return nil, fmt.Errorf("expected HEAD method, got %s", req.Method)
66 66
 			}
67 67
 			query := req.URL.Query()
... ...
@@ -140,7 +140,7 @@ func TestCopyToContainer(t *testing.T) {
140 140
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
141 141
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
142 142
 			}
143
-			if req.Method != "PUT" {
143
+			if req.Method != http.MethodPut {
144 144
 				return nil, fmt.Errorf("expected PUT method, got %s", req.Method)
145 145
 			}
146 146
 			query := req.URL.Query()
... ...
@@ -235,7 +235,7 @@ func TestCopyFromContainer(t *testing.T) {
235 235
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
236 236
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
237 237
 			}
238
-			if req.Method != "GET" {
238
+			if req.Method != http.MethodGet {
239 239
 				return nil, fmt.Errorf("expected GET method, got %s", req.Method)
240 240
 			}
241 241
 			query := req.URL.Query()
... ...
@@ -34,7 +34,7 @@ func TestContainerExecCreate(t *testing.T) {
34 34
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
35 35
 				return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL)
36 36
 			}
37
-			if req.Method != "POST" {
37
+			if req.Method != http.MethodPost {
38 38
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
39 39
 			}
40 40
 			// FIXME validate the content is the given ExecConfig ?
... ...
@@ -24,7 +24,7 @@ func (cli *Client) postHijacked(ctx context.Context, path string, query url.Valu
24 24
 	}
25 25
 
26 26
 	apiPath := cli.getAPIPath(ctx, path, query)
27
-	req, err := http.NewRequest("POST", apiPath, bodyEncoded)
27
+	req, err := http.NewRequest(http.MethodPost, apiPath, bodyEncoded)
28 28
 	if err != nil {
29 29
 		return types.HijackedResponse{}, err
30 30
 	}
... ...
@@ -40,7 +40,7 @@ func (cli *Client) postHijacked(ctx context.Context, path string, query url.Valu
40 40
 
41 41
 // DialHijack returns a hijacked connection with negotiated protocol proto.
42 42
 func (cli *Client) DialHijack(ctx context.Context, url, proto string, meta map[string][]string) (net.Conn, error) {
43
-	req, err := http.NewRequest("POST", url, nil)
43
+	req, err := http.NewRequest(http.MethodPost, url, nil)
44 44
 	if err != nil {
45 45
 		return nil, err
46 46
 	}
... ...
@@ -63,7 +63,7 @@ func TestImageRemove(t *testing.T) {
63 63
 				if !strings.HasPrefix(req.URL.Path, expectedURL) {
64 64
 					return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL)
65 65
 				}
66
-				if req.Method != "DELETE" {
66
+				if req.Method != http.MethodDelete {
67 67
 					return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
68 68
 				}
69 69
 				query := req.URL.Query()
... ...
@@ -123,7 +123,7 @@ func TestImageTag(t *testing.T) {
123 123
 				if !strings.HasPrefix(req.URL.Path, expectedURL) {
124 124
 					return nil, fmt.Errorf("expected URL '%s', got '%s'", expectedURL, req.URL)
125 125
 				}
126
-				if req.Method != "POST" {
126
+				if req.Method != http.MethodPost {
127 127
 					return nil, fmt.Errorf("expected POST method, got %s", req.Method)
128 128
 				}
129 129
 				query := req.URL.Query()
... ...
@@ -38,7 +38,7 @@ func TestNetworkConnectEmptyNilEndpointSettings(t *testing.T) {
38 38
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
39 39
 			}
40 40
 
41
-			if req.Method != "POST" {
41
+			if req.Method != http.MethodPost {
42 42
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
43 43
 			}
44 44
 
... ...
@@ -77,7 +77,7 @@ func TestNetworkConnect(t *testing.T) {
77 77
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
78 78
 			}
79 79
 
80
-			if req.Method != "POST" {
80
+			if req.Method != http.MethodPost {
81 81
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
82 82
 			}
83 83
 
... ...
@@ -37,7 +37,7 @@ func TestNetworkCreate(t *testing.T) {
37 37
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
38 38
 			}
39 39
 
40
-			if req.Method != "POST" {
40
+			if req.Method != http.MethodPost {
41 41
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
42 42
 			}
43 43
 
... ...
@@ -37,7 +37,7 @@ func TestNetworkDisconnect(t *testing.T) {
37 37
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
38 38
 			}
39 39
 
40
-			if req.Method != "POST" {
40
+			if req.Method != http.MethodPost {
41 41
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
42 42
 			}
43 43
 
... ...
@@ -55,7 +55,7 @@ func TestNetworkInspect(t *testing.T) {
55 55
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
56 56
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
57 57
 			}
58
-			if req.Method != "GET" {
58
+			if req.Method != http.MethodGet {
59 59
 				return nil, fmt.Errorf("expected GET method, got %s", req.Method)
60 60
 			}
61 61
 
... ...
@@ -77,7 +77,7 @@ func TestNetworkList(t *testing.T) {
77 77
 				if !strings.HasPrefix(req.URL.Path, expectedURL) {
78 78
 					return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
79 79
 				}
80
-				if req.Method != "GET" {
80
+				if req.Method != http.MethodGet {
81 81
 					return nil, fmt.Errorf("expected GET method, got %s", req.Method)
82 82
 				}
83 83
 				query := req.URL.Query()
... ...
@@ -34,7 +34,7 @@ func TestNetworkRemove(t *testing.T) {
34 34
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
35 35
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
36 36
 			}
37
-			if req.Method != "DELETE" {
37
+			if req.Method != http.MethodDelete {
38 38
 				return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
39 39
 			}
40 40
 			return &http.Response{
... ...
@@ -49,7 +49,7 @@ func TestNodeRemove(t *testing.T) {
49 49
 				if !strings.HasPrefix(req.URL.Path, expectedURL) {
50 50
 					return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
51 51
 				}
52
-				if req.Method != "DELETE" {
52
+				if req.Method != http.MethodDelete {
53 53
 					return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
54 54
 				}
55 55
 				force := req.URL.Query().Get("force")
... ...
@@ -35,7 +35,7 @@ func TestNodeUpdate(t *testing.T) {
35 35
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
36 36
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
37 37
 			}
38
-			if req.Method != "POST" {
38
+			if req.Method != http.MethodPost {
39 39
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
40 40
 			}
41 41
 			return &http.Response{
... ...
@@ -19,7 +19,7 @@ func (cli *Client) Ping(ctx context.Context) (types.Ping, error) {
19 19
 	// Using cli.buildRequest() + cli.doRequest() instead of cli.sendRequest()
20 20
 	// because ping requests are used during  API version negotiation, so we want
21 21
 	// to hit the non-versioned /_ping endpoint, not /v1.xx/_ping
22
-	req, err := cli.buildRequest("HEAD", path.Join(cli.basePath, "/_ping"), nil, nil)
22
+	req, err := cli.buildRequest(http.MethodHead, path.Join(cli.basePath, "/_ping"), nil, nil)
23 23
 	if err != nil {
24 24
 		return ping, err
25 25
 	}
... ...
@@ -35,7 +35,7 @@ func (cli *Client) Ping(ctx context.Context) (types.Ping, error) {
35 35
 		return ping, err
36 36
 	}
37 37
 
38
-	req, err = cli.buildRequest("GET", path.Join(cli.basePath, "/_ping"), nil, nil)
38
+	req, err = cli.buildRequest(http.MethodGet, path.Join(cli.basePath, "/_ping"), nil, nil)
39 39
 	if err != nil {
40 40
 		return ping, err
41 41
 	}
... ...
@@ -90,11 +90,11 @@ func TestPingHeadFallback(t *testing.T) {
90 90
 	}{
91 91
 		{
92 92
 			status:   http.StatusOK,
93
-			expected: "HEAD",
93
+			expected: http.MethodHead,
94 94
 		},
95 95
 		{
96 96
 			status:   http.StatusInternalServerError,
97
-			expected: "HEAD",
97
+			expected: http.MethodHead,
98 98
 		},
99 99
 		{
100 100
 			status:   http.StatusNotFound,
... ...
@@ -35,7 +35,7 @@ func TestPluginDisable(t *testing.T) {
35 35
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
36 36
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
37 37
 			}
38
-			if req.Method != "POST" {
38
+			if req.Method != http.MethodPost {
39 39
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
40 40
 			}
41 41
 			return &http.Response{
... ...
@@ -35,7 +35,7 @@ func TestPluginEnable(t *testing.T) {
35 35
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
36 36
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
37 37
 			}
38
-			if req.Method != "POST" {
38
+			if req.Method != http.MethodPost {
39 39
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
40 40
 			}
41 41
 			return &http.Response{
... ...
@@ -34,7 +34,7 @@ func TestPluginPush(t *testing.T) {
34 34
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
35 35
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
36 36
 			}
37
-			if req.Method != "POST" {
37
+			if req.Method != http.MethodPost {
38 38
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
39 39
 			}
40 40
 			auth := req.Header.Get("X-Registry-Auth")
... ...
@@ -35,7 +35,7 @@ func TestPluginRemove(t *testing.T) {
35 35
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
36 36
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
37 37
 			}
38
-			if req.Method != "DELETE" {
38
+			if req.Method != http.MethodDelete {
39 39
 				return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
40 40
 			}
41 41
 			return &http.Response{
... ...
@@ -34,7 +34,7 @@ func TestPluginSet(t *testing.T) {
34 34
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
35 35
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
36 36
 			}
37
-			if req.Method != "POST" {
37
+			if req.Method != http.MethodPost {
38 38
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
39 39
 			}
40 40
 			return &http.Response{
... ...
@@ -29,12 +29,12 @@ type serverResponse struct {
29 29
 
30 30
 // head sends an http request to the docker API using the method HEAD.
31 31
 func (cli *Client) head(ctx context.Context, path string, query url.Values, headers map[string][]string) (serverResponse, error) {
32
-	return cli.sendRequest(ctx, "HEAD", path, query, nil, headers)
32
+	return cli.sendRequest(ctx, http.MethodHead, path, query, nil, headers)
33 33
 }
34 34
 
35 35
 // get sends an http request to the docker API using the method GET with a specific Go context.
36 36
 func (cli *Client) get(ctx context.Context, path string, query url.Values, headers map[string][]string) (serverResponse, error) {
37
-	return cli.sendRequest(ctx, "GET", path, query, nil, headers)
37
+	return cli.sendRequest(ctx, http.MethodGet, path, query, nil, headers)
38 38
 }
39 39
 
40 40
 // post sends an http request to the docker API using the method POST with a specific Go context.
... ...
@@ -43,21 +43,21 @@ func (cli *Client) post(ctx context.Context, path string, query url.Values, obj
43 43
 	if err != nil {
44 44
 		return serverResponse{}, err
45 45
 	}
46
-	return cli.sendRequest(ctx, "POST", path, query, body, headers)
46
+	return cli.sendRequest(ctx, http.MethodPost, path, query, body, headers)
47 47
 }
48 48
 
49 49
 func (cli *Client) postRaw(ctx context.Context, path string, query url.Values, body io.Reader, headers map[string][]string) (serverResponse, error) {
50
-	return cli.sendRequest(ctx, "POST", path, query, body, headers)
50
+	return cli.sendRequest(ctx, http.MethodPost, path, query, body, headers)
51 51
 }
52 52
 
53 53
 // putRaw sends an http request to the docker API using the method PUT.
54 54
 func (cli *Client) putRaw(ctx context.Context, path string, query url.Values, body io.Reader, headers map[string][]string) (serverResponse, error) {
55
-	return cli.sendRequest(ctx, "PUT", path, query, body, headers)
55
+	return cli.sendRequest(ctx, http.MethodPut, path, query, body, headers)
56 56
 }
57 57
 
58 58
 // delete sends an http request to the docker API using the method DELETE.
59 59
 func (cli *Client) delete(ctx context.Context, path string, query url.Values, headers map[string][]string) (serverResponse, error) {
60
-	return cli.sendRequest(ctx, "DELETE", path, query, nil, headers)
60
+	return cli.sendRequest(ctx, http.MethodDelete, path, query, nil, headers)
61 61
 }
62 62
 
63 63
 type headers map[string][]string
... ...
@@ -79,7 +79,7 @@ func encodeBody(obj interface{}, headers headers) (io.Reader, headers, error) {
79 79
 }
80 80
 
81 81
 func (cli *Client) buildRequest(method, path string, body io.Reader, headers headers) (*http.Request, error) {
82
-	expectedPayload := (method == "POST" || method == "PUT")
82
+	expectedPayload := (method == http.MethodPost || method == http.MethodPut)
83 83
 	if expectedPayload && body == nil {
84 84
 		body = bytes.NewReader([]byte{})
85 85
 	}
... ...
@@ -73,7 +73,7 @@ func TestSetHostHeader(t *testing.T) {
73 73
 			basePath: hostURL.Path,
74 74
 		}
75 75
 
76
-		_, err = client.sendRequest(context.Background(), "GET", testURL, nil, nil, nil)
76
+		_, err = client.sendRequest(context.Background(), http.MethodGet, testURL, nil, nil, nil)
77 77
 		assert.NilError(t, err)
78 78
 	}
79 79
 }
... ...
@@ -48,7 +48,7 @@ func TestSecretCreate(t *testing.T) {
48 48
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
49 49
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
50 50
 			}
51
-			if req.Method != "POST" {
51
+			if req.Method != http.MethodPost {
52 52
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
53 53
 			}
54 54
 			b, err := json.Marshal(types.SecretCreateResponse{
... ...
@@ -47,7 +47,7 @@ func TestSecretRemove(t *testing.T) {
47 47
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
48 48
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
49 49
 			}
50
-			if req.Method != "DELETE" {
50
+			if req.Method != http.MethodDelete {
51 51
 				return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
52 52
 			}
53 53
 			return &http.Response{
... ...
@@ -48,7 +48,7 @@ func TestSecretUpdate(t *testing.T) {
48 48
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
49 49
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
50 50
 			}
51
-			if req.Method != "POST" {
51
+			if req.Method != http.MethodPost {
52 52
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
53 53
 			}
54 54
 			return &http.Response{
... ...
@@ -40,7 +40,7 @@ func TestServiceCreate(t *testing.T) {
40 40
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
41 41
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
42 42
 			}
43
-			if req.Method != "POST" {
43
+			if req.Method != http.MethodPost {
44 44
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
45 45
 			}
46 46
 			b, err := json.Marshal(types.ServiceCreateResponse{
... ...
@@ -40,7 +40,7 @@ func TestServiceRemove(t *testing.T) {
40 40
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
41 41
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
42 42
 			}
43
-			if req.Method != "DELETE" {
43
+			if req.Method != http.MethodDelete {
44 44
 				return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
45 45
 			}
46 46
 			return &http.Response{
... ...
@@ -58,7 +58,7 @@ func TestServiceUpdate(t *testing.T) {
58 58
 				if !strings.HasPrefix(req.URL.Path, expectedURL) {
59 59
 					return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
60 60
 				}
61
-				if req.Method != "POST" {
61
+				if req.Method != http.MethodPost {
62 62
 					return nil, fmt.Errorf("expected POST method, got %s", req.Method)
63 63
 				}
64 64
 				version := req.URL.Query().Get("version")
... ...
@@ -33,7 +33,7 @@ func TestSwarmGetUnlockKey(t *testing.T) {
33 33
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
34 34
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
35 35
 			}
36
-			if req.Method != "GET" {
36
+			if req.Method != http.MethodGet {
37 37
 				return nil, fmt.Errorf("expected GET method, got %s", req.Method)
38 38
 			}
39 39
 
... ...
@@ -35,7 +35,7 @@ func TestSwarmInit(t *testing.T) {
35 35
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
36 36
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
37 37
 			}
38
-			if req.Method != "POST" {
38
+			if req.Method != http.MethodPost {
39 39
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
40 40
 			}
41 41
 			return &http.Response{
... ...
@@ -35,7 +35,7 @@ func TestSwarmJoin(t *testing.T) {
35 35
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
36 36
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
37 37
 			}
38
-			if req.Method != "POST" {
38
+			if req.Method != http.MethodPost {
39 39
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
40 40
 			}
41 41
 			return &http.Response{
... ...
@@ -48,7 +48,7 @@ func TestSwarmLeave(t *testing.T) {
48 48
 				if !strings.HasPrefix(req.URL.Path, expectedURL) {
49 49
 					return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
50 50
 				}
51
-				if req.Method != "POST" {
51
+				if req.Method != http.MethodPost {
52 52
 					return nil, fmt.Errorf("expected POST method, got %s", req.Method)
53 53
 				}
54 54
 				force := req.URL.Query().Get("force")
... ...
@@ -35,7 +35,7 @@ func TestSwarmUnlock(t *testing.T) {
35 35
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
36 36
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
37 37
 			}
38
-			if req.Method != "POST" {
38
+			if req.Method != http.MethodPost {
39 39
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
40 40
 			}
41 41
 			return &http.Response{
... ...
@@ -35,7 +35,7 @@ func TestSwarmUpdate(t *testing.T) {
35 35
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
36 36
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
37 37
 			}
38
-			if req.Method != "POST" {
38
+			if req.Method != http.MethodPost {
39 39
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
40 40
 			}
41 41
 			return &http.Response{
... ...
@@ -38,7 +38,7 @@ func TestVolumeCreate(t *testing.T) {
38 38
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
39 39
 			}
40 40
 
41
-			if req.Method != "POST" {
41
+			if req.Method != http.MethodPost {
42 42
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
43 43
 			}
44 44
 
... ...
@@ -59,7 +59,7 @@ func TestVolumeInspect(t *testing.T) {
59 59
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
60 60
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
61 61
 			}
62
-			if req.Method != "GET" {
62
+			if req.Method != http.MethodGet {
63 63
 				return nil, fmt.Errorf("expected GET method, got %s", req.Method)
64 64
 			}
65 65
 			content, err := json.Marshal(expected)
... ...
@@ -34,7 +34,7 @@ func TestVolumeRemove(t *testing.T) {
34 34
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
35 35
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
36 36
 			}
37
-			if req.Method != "DELETE" {
37
+			if req.Method != http.MethodDelete {
38 38
 				return nil, fmt.Errorf("expected DELETE method, got %s", req.Method)
39 39
 			}
40 40
 			return &http.Response{