Skip to content

Commit

Permalink
backport of commit 1410297
Browse files Browse the repository at this point in the history
  • Loading branch information
thevilledev committed Jul 25, 2023
1 parent e5c14e4 commit 7e69402
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion command/agent/variable_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (s *HTTPServer) VariablesListRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method != "GET" {
if req.Method != http.MethodGet {
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 @@ -38,15 +38,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("GET", "/v1/vars?wait=99a", nil)
req, err := http.NewRequest(http.MethodGet, "/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("GET", "/v1/vars?region=bad", nil)
req, err := http.NewRequest(http.MethodGet, "/v1/vars?region=bad", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariablesListRequest(respW, req)
Expand All @@ -55,7 +55,7 @@ func TestHTTP_Variables(t *testing.T) {
})
t.Run("list", func(t *testing.T) {
// Test the empty list case
req, err := http.NewRequest("GET", "/v1/vars", nil)
req, err := http.NewRequest(http.MethodGet, "/v1/vars", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()

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

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

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

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

Expand All @@ -109,15 +109,15 @@ func TestHTTP_Variables(t *testing.T) {
require.Nil(t, obj)
})
t.Run("error_parse_query", func(t *testing.T) {
req, err := http.NewRequest("GET", "/v1/var/does/not/exist?wait=99a", nil)
req, err := http.NewRequest(http.MethodGet, "/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("GET", "/v1/var/does/not/exist?region=bad", nil)
req, err := http.NewRequest(http.MethodGet, "/v1/var/does/not/exist?region=bad", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -126,7 +126,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("GET", "/v1/var/", nil)
req, err := http.NewRequest(http.MethodGet, "/v1/var/", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -135,7 +135,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("GET", "/v1/var/not/real", nil)
req, err := http.NewRequest(http.MethodGet, "/v1/var/not/real", nil)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -149,7 +149,7 @@ func TestHTTP_Variables(t *testing.T) {
require.NoError(t, rpcWriteSV(s, sv1, out))

// Query a variable
req, err := http.NewRequest("GET", "/v1/var/"+sv1.Path, nil)
req, err := http.NewRequest(http.MethodGet, "/v1/var/"+sv1.Path, nil)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -168,7 +168,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("PUT", "/v1/var/"+sv1.Path, buf)
req, err := http.NewRequest(http.MethodPut, "/v1/var/"+sv1.Path, buf)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -177,7 +177,7 @@ func TestHTTP_Variables(t *testing.T) {
})
t.Run("error_rpc_create", func(t *testing.T) {
buf := encodeReq(sv1)
req, err := http.NewRequest("PUT", "/v1/var/does/not/exist?region=bad", buf)
req, err := http.NewRequest(http.MethodPut, "/v1/var/does/not/exist?region=bad", buf)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -188,7 +188,7 @@ func TestHTTP_Variables(t *testing.T) {
sv2 := sv1.Copy()
sv2.Items = nil
buf := encodeReq(sv2)
req, err := http.NewRequest("PUT", "/v1/var/"+sv1.Path, buf)
req, err := http.NewRequest(http.MethodPut, "/v1/var/"+sv1.Path, buf)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand All @@ -197,7 +197,7 @@ func TestHTTP_Variables(t *testing.T) {
})
t.Run("create", func(t *testing.T) {
buf := encodeReq(sv1)
req, err := http.NewRequest("PUT", "/v1/var/"+sv1.Path, buf)
req, err := http.NewRequest(http.MethodPut, "/v1/var/"+sv1.Path, buf)
require.NoError(t, err)
respW := httptest.NewRecorder()
obj, err := s.Server.VariableSpecificRequest(respW, req)
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestHTTP_Variables(t *testing.T) {
// break the request body
badBuf := encodeBrokenReq(&sv1U)

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

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

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

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

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

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

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

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

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

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

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

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

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

Expand Down

0 comments on commit 7e69402

Please sign in to comment.