Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(nodepool): Go stdlib vars for HTTP methods and status codes #18061

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions command/agent/node_pool_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (

func (s *HTTPServer) NodePoolsRequest(resp http.ResponseWriter, req *http.Request) (any, error) {
switch req.Method {
case "GET":
case http.MethodGet:
return s.nodePoolList(resp, req)
case "PUT", "POST":
case http.MethodPut, http.MethodPost:
return s.nodePoolUpsert(resp, req, "")
default:
return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod)
Expand All @@ -38,11 +38,11 @@ func (s *HTTPServer) NodePoolSpecificRequest(resp http.ResponseWriter, req *http

func (s *HTTPServer) nodePoolCRUD(resp http.ResponseWriter, req *http.Request, poolName string) (any, error) {
switch req.Method {
case "GET":
case http.MethodGet:
return s.nodePoolQuery(resp, req, poolName)
case "PUT", "POST":
case http.MethodPut, http.MethodPost:
return s.nodePoolUpsert(resp, req, poolName)
case "DELETE":
case http.MethodDelete:
return s.nodePoolDelete(resp, req, poolName)
default:
return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod)
Expand Down
20 changes: 10 additions & 10 deletions command/agent/node_pool_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestHTTP_NodePool_List(t *testing.T) {
must.NoError(t, err)

// Make HTTP request.
req, err := http.NewRequest("GET", "/v1/node/pools", nil)
req, err := http.NewRequest(http.MethodGet, "/v1/node/pools", nil)
must.NoError(t, err)
respW := httptest.NewRecorder()

Expand Down Expand Up @@ -63,7 +63,7 @@ func TestHTTP_NodePool_Info(t *testing.T) {

t.Run("test pool", func(t *testing.T) {
// Make HTTP request for test pool.
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/node/pool/%s", pool.Name), nil)
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("/v1/node/pool/%s", pool.Name), nil)
must.NoError(t, err)
respW := httptest.NewRecorder()

Expand All @@ -86,7 +86,7 @@ func TestHTTP_NodePool_Info(t *testing.T) {

t.Run("built-in pool", func(t *testing.T) {
// Make HTTP request for built-in pool.
req, err := http.NewRequest("GET", fmt.Sprintf("/v1/node/pool/%s", structs.NodePoolAll), nil)
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("/v1/node/pool/%s", structs.NodePoolAll), nil)
must.NoError(t, err)
respW := httptest.NewRecorder()

Expand All @@ -104,7 +104,7 @@ func TestHTTP_NodePool_Info(t *testing.T) {

t.Run("invalid pool", func(t *testing.T) {
// Make HTTP request for built-in pool.
req, err := http.NewRequest("GET", "/v1/node/pool/doesn-exist", nil)
req, err := http.NewRequest(http.MethodGet, "/v1/node/pool/doesn-exist", nil)
must.NoError(t, err)
respW := httptest.NewRecorder()

Expand All @@ -126,7 +126,7 @@ func TestHTTP_NodePool_Create(t *testing.T) {
// Create test node pool.
pool := mock.NodePool()
buf := encodeReq(pool)
req, err := http.NewRequest("PUT", "/v1/node/pools", buf)
req, err := http.NewRequest(http.MethodPut, "/v1/node/pools", buf)
must.NoError(t, err)

respW := httptest.NewRecorder()
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestHTTP_NodePool_Update(t *testing.T) {
}

buf := encodeReq(updated)
req, err := http.NewRequest("PUT", fmt.Sprintf("/v1/node/pool/%s", updated.Name), buf)
req, err := http.NewRequest(http.MethodPut, fmt.Sprintf("/v1/node/pool/%s", updated.Name), buf)
must.NoError(t, err)

respW := httptest.NewRecorder()
Expand Down Expand Up @@ -218,7 +218,7 @@ func TestHTTP_NodePool_Update(t *testing.T) {
}

buf := encodeReq(updated)
req, err := http.NewRequest("PUT", "/v1/node/pool/", buf)
req, err := http.NewRequest(http.MethodPut, "/v1/node/pool/", buf)
must.NoError(t, err)

respW := httptest.NewRecorder()
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestHTTP_NodePool_Update(t *testing.T) {

// Make request with the wrong path.
buf := encodeReq(updated)
req, err := http.NewRequest("PUT", "/v1/node/pool/wrong", buf)
req, err := http.NewRequest(http.MethodPut, "/v1/node/pool/wrong", buf)
must.NoError(t, err)

respW := httptest.NewRecorder()
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestHTTP_NodePool_Delete(t *testing.T) {
must.NoError(t, err)

// Delete test node pool.
req, err := http.NewRequest("DELETE", fmt.Sprintf("/v1/node/pool/%s", pool.Name), nil)
req, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("/v1/node/pool/%s", pool.Name), nil)
must.NoError(t, err)

respW := httptest.NewRecorder()
Expand Down Expand Up @@ -383,7 +383,7 @@ func TestHTTP_NodePool_NodesList(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
// Make HTTP request.
path := fmt.Sprintf("/v1/node/pool/%s/nodes?%s", tc.pool, tc.args)
req, err := http.NewRequest("GET", path, nil)
req, err := http.NewRequest(http.MethodGet, path, nil)
must.NoError(t, err)
respW := httptest.NewRecorder()

Expand Down
Loading