Skip to content

Commit

Permalink
revert changes to node pool and variable
Browse files Browse the repository at this point in the history
  • Loading branch information
thevilledev committed Jul 25, 2023
1 parent 4067fd9 commit 6546cd8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
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 http.MethodGet:
case "GET":

Check failure on line 16 in command/agent/node_pool_endpoint.go

View workflow job for this annotation

GitHub Actions / checks / checks

"GET" can be replaced by http.MethodGet (usestdlibvars)
return s.nodePoolList(resp, req)
case http.MethodPut, http.MethodPost:
case "PUT", "POST":

Check failure on line 18 in command/agent/node_pool_endpoint.go

View workflow job for this annotation

GitHub Actions / checks / checks

"PUT" can be replaced by http.MethodPut (usestdlibvars)
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 http.MethodGet:
case "GET":

Check failure on line 41 in command/agent/node_pool_endpoint.go

View workflow job for this annotation

GitHub Actions / checks / checks

"GET" can be replaced by http.MethodGet (usestdlibvars)
return s.nodePoolQuery(resp, req, poolName)
case http.MethodPut, http.MethodPost:
case "PUT", "POST":

Check failure on line 43 in command/agent/node_pool_endpoint.go

View workflow job for this annotation

GitHub Actions / checks / checks

"PUT" can be replaced by http.MethodPut (usestdlibvars)
return s.nodePoolUpsert(resp, req, poolName)
case http.MethodDelete:
case "DELETE":

Check failure on line 45 in command/agent/node_pool_endpoint.go

View workflow job for this annotation

GitHub Actions / checks / checks

"DELETE" can be replaced by http.MethodDelete (usestdlibvars)
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(http.MethodGet, "/v1/node/pools", nil)
req, err := http.NewRequest("GET", "/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(http.MethodGet, fmt.Sprintf("/v1/node/pool/%s", pool.Name), nil)
req, err := http.NewRequest("GET", 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(http.MethodGet, fmt.Sprintf("/v1/node/pool/%s", structs.NodePoolAll), nil)
req, err := http.NewRequest("GET", 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(http.MethodGet, "/v1/node/pool/doesn-exist", nil)
req, err := http.NewRequest("GET", "/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(http.MethodPut, "/v1/node/pools", buf)
req, err := http.NewRequest("PUT", "/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(http.MethodPut, fmt.Sprintf("/v1/node/pool/%s", updated.Name), buf)
req, err := http.NewRequest("PUT", 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(http.MethodPut, "/v1/node/pool/", buf)
req, err := http.NewRequest("PUT", "/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(http.MethodPut, "/v1/node/pool/wrong", buf)
req, err := http.NewRequest("PUT", "/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(http.MethodDelete, fmt.Sprintf("/v1/node/pool/%s", pool.Name), nil)
req, err := http.NewRequest("DELETE", 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(http.MethodGet, path, nil)
req, err := http.NewRequest("GET", path, nil)
must.NoError(t, err)
respW := httptest.NewRecorder()

Expand Down
2 changes: 1 addition & 1 deletion command/agent/variable_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func (s *HTTPServer) VariablesListRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method != http.MethodGet {
if req.Method != "GET" {

Check failure on line 16 in command/agent/variable_endpoint.go

View workflow job for this annotation

GitHub Actions / checks / checks

"GET" can be replaced by http.MethodGet (usestdlibvars)
return nil, CodedError(http.StatusMethodNotAllowed, ErrInvalidMethod)
}

Expand Down
46 changes: 23 additions & 23 deletions command/agent/variable_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ func TestHTTP_Variables(t *testing.T) {
require.EqualError(t, err, ErrInvalidMethod)
})
t.Run("error_parse_list", func(t *testing.T) {
req, err := http.NewRequest(http.MethodGet, "/v1/vars?wait=99a", nil)
req, err := http.NewRequest("GET", "/v1/vars?wait=99a", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()
_, _ = s.Server.VariablesListRequest(respW, req)
require.Equal(t, http.StatusBadRequest, respW.Code)
require.Equal(t, "Invalid wait time", string(respW.Body.Bytes()))
})
t.Run("error_rpc_list", func(t *testing.T) {
req, err := http.NewRequest(http.MethodGet, "/v1/vars?region=bad", nil)
req, err := http.NewRequest("GET", "/v1/vars?region=bad", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariablesListRequest(respW, req)
Expand All @@ -58,7 +58,7 @@ func TestHTTP_Variables(t *testing.T) {
})
t.Run("list", func(t *testing.T) {
// Test the empty list case
req, err := http.NewRequest(http.MethodGet, "/v1/vars", nil)
req, err := http.NewRequest("GET", "/v1/vars", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()

Expand All @@ -75,7 +75,7 @@ func TestHTTP_Variables(t *testing.T) {
}

// Make the HTTP request
req, err = http.NewRequest(http.MethodGet, "/v1/vars", nil)
req, err = http.NewRequest("GET", "/v1/vars", nil)
require.NoError(t, err)
respW = httptest.NewRecorder()

Expand All @@ -92,7 +92,7 @@ func TestHTTP_Variables(t *testing.T) {
require.Len(t, obj.([]*structs.VariableMetadata), 4)

// test prefix query
req, err = http.NewRequest(http.MethodGet, "/v1/vars?prefix="+svs[0].Path, nil)
req, err = http.NewRequest("GET", "/v1/vars?prefix="+svs[0].Path, nil)
require.NoError(t, err)
respW = httptest.NewRecorder()

Expand All @@ -112,15 +112,15 @@ func TestHTTP_Variables(t *testing.T) {
require.Nil(t, obj)
})
t.Run("error_parse_query", func(t *testing.T) {
req, err := http.NewRequest(http.MethodGet, "/v1/var/does/not/exist?wait=99a", nil)
req, err := http.NewRequest("GET", "/v1/var/does/not/exist?wait=99a", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()
_, _ = s.Server.VariableSpecificRequest(respW, req)
require.Equal(t, http.StatusBadRequest, respW.Code)
require.Equal(t, "Invalid wait time", string(respW.Body.Bytes()))
})
t.Run("error_rpc_query", func(t *testing.T) {
req, err := http.NewRequest(http.MethodGet, "/v1/var/does/not/exist?region=bad", nil)
req, err := http.NewRequest("GET", "/v1/var/does/not/exist?region=bad", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -129,7 +129,7 @@ func TestHTTP_Variables(t *testing.T) {
})
t.Run("query_unset_path", func(t *testing.T) {
// Make a request for a non-existing variable
req, err := http.NewRequest(http.MethodGet, "/v1/var/", nil)
req, err := http.NewRequest("GET", "/v1/var/", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -138,7 +138,7 @@ func TestHTTP_Variables(t *testing.T) {
})
t.Run("query_unset_variable", func(t *testing.T) {
// Make a request for a non-existing variable
req, err := http.NewRequest(http.MethodGet, "/v1/var/not/real", nil)
req, err := http.NewRequest("GET", "/v1/var/not/real", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -152,7 +152,7 @@ func TestHTTP_Variables(t *testing.T) {
require.NoError(t, rpcWriteSV(s, sv1, out))

// Query a variable
req, err := http.NewRequest(http.MethodGet, "/v1/var/"+sv1.Path, nil)
req, err := http.NewRequest("GET", "/v1/var/"+sv1.Path, nil)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -171,7 +171,7 @@ func TestHTTP_Variables(t *testing.T) {
sv1 := mock.Variable()
t.Run("error_parse_create", func(t *testing.T) {
buf := encodeBrokenReq(&sv1)
req, err := http.NewRequest(http.MethodPut, "/v1/var/"+sv1.Path, buf)
req, err := http.NewRequest("PUT", "/v1/var/"+sv1.Path, buf)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -180,7 +180,7 @@ func TestHTTP_Variables(t *testing.T) {
})
t.Run("error_rpc_create", func(t *testing.T) {
buf := encodeReq(sv1)
req, err := http.NewRequest(http.MethodPut, "/v1/var/does/not/exist?region=bad", buf)
req, err := http.NewRequest("PUT", "/v1/var/does/not/exist?region=bad", buf)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -191,7 +191,7 @@ func TestHTTP_Variables(t *testing.T) {
sv2 := sv1.Copy()
sv2.Items = nil
buf := encodeReq(sv2)
req, err := http.NewRequest(http.MethodPut, "/v1/var/"+sv1.Path, buf)
req, err := http.NewRequest("PUT", "/v1/var/"+sv1.Path, buf)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -200,7 +200,7 @@ func TestHTTP_Variables(t *testing.T) {
})
t.Run("create", func(t *testing.T) {
buf := encodeReq(sv1)
req, err := http.NewRequest(http.MethodPut, "/v1/var/"+sv1.Path, buf)
req, err := http.NewRequest("PUT", "/v1/var/"+sv1.Path, buf)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestHTTP_Variables(t *testing.T) {
// break the request body
badBuf := encodeBrokenReq(&sv1U)

req, err := http.NewRequest(http.MethodPut, "/v1/var/"+sv1.Path, badBuf)
req, err := http.NewRequest("PUT", "/v1/var/"+sv1.Path, badBuf)
require.NoError(t, err)
respW := httptest.NewRecorder()

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

// test broken rpc error
buf := encodeReq(&sv1U)
req, err := http.NewRequest(http.MethodPut, "/v1/var/"+sv1.Path+"?region=bad", buf)
req, err := http.NewRequest("PUT", "/v1/var/"+sv1.Path+"?region=bad", buf)
require.NoError(t, err)
respW := httptest.NewRecorder()

Expand All @@ -266,7 +266,7 @@ func TestHTTP_Variables(t *testing.T) {
svU.Items["new"] = "new"
// Make the HTTP request
buf := encodeReq(&svU)
req, err := http.NewRequest(http.MethodPut, "/v1/var/"+sv.Path, buf)
req, err := http.NewRequest("PUT", "/v1/var/"+sv.Path, buf)
require.NoError(t, err)
respW := httptest.NewRecorder()

Expand Down Expand Up @@ -304,7 +304,7 @@ func TestHTTP_Variables(t *testing.T) {
// Make the HTTP request
{
buf := encodeReq(&svU)
req, err := http.NewRequest(http.MethodPut, "/v1/var/"+svU.Path+"?cas=1", buf)
req, err := http.NewRequest("PUT", "/v1/var/"+svU.Path+"?cas=1", buf)
require.NoError(t, err)
respW := httptest.NewRecorder()

Expand All @@ -331,7 +331,7 @@ func TestHTTP_Variables(t *testing.T) {
// Make the HTTP request
{
buf := encodeReq(&svU)
req, err := http.NewRequest(http.MethodPut, "/v1/var/"+svU.Path+"?cas="+fmt.Sprint(sv.ModifyIndex), buf)
req, err := http.NewRequest("PUT", "/v1/var/"+svU.Path+"?cas="+fmt.Sprint(sv.ModifyIndex), buf)
require.NoError(t, err)
respW := httptest.NewRecorder()

Expand Down Expand Up @@ -382,7 +382,7 @@ func TestHTTP_Variables(t *testing.T) {
require.NoError(t, rpcWriteSV(s, sv1, nil))

// Make the HTTP request
req, err := http.NewRequest(http.MethodDelete, "/v1/var/"+sv1.Path+"?region=bad", nil)
req, err := http.NewRequest("DELETE", "/v1/var/"+sv1.Path+"?region=bad", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()

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

// Make the HTTP request
{
req, err := http.NewRequest(http.MethodDelete, "/v1/var/"+sv.Path+"?cas=1", nil)
req, err := http.NewRequest("DELETE", "/v1/var/"+sv.Path+"?cas=1", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()

Expand Down Expand Up @@ -427,7 +427,7 @@ func TestHTTP_Variables(t *testing.T) {
}
// Make the HTTP request
{
req, err := http.NewRequest(http.MethodDelete, "/v1/var/"+sv.Path+"?cas="+fmt.Sprint(sv.ModifyIndex), nil)
req, err := http.NewRequest("DELETE", "/v1/var/"+sv.Path+"?cas="+fmt.Sprint(sv.ModifyIndex), nil)
require.NoError(t, err)
respW := httptest.NewRecorder()

Expand All @@ -448,7 +448,7 @@ func TestHTTP_Variables(t *testing.T) {
require.NoError(t, rpcWriteSV(s, sv1, nil))

// Make the HTTP request
req, err := http.NewRequest(http.MethodDelete, "/v1/var/"+sv1.Path, nil)
req, err := http.NewRequest("DELETE", "/v1/var/"+sv1.Path, nil)
require.NoError(t, err)
respW := httptest.NewRecorder()

Expand Down

0 comments on commit 6546cd8

Please sign in to comment.