Browse Source

agent: accept connect param for execute

pull/4275/head
Mitchell Hashimoto 7 years ago committed by Jack Pearkes
parent
commit
62d4aaa33e
  1. 10
      agent/prepared_query_endpoint.go
  2. 23
      agent/prepared_query_endpoint_test.go

10
agent/prepared_query_endpoint.go

@ -107,6 +107,16 @@ func (s *HTTPServer) preparedQueryExecute(id string, resp http.ResponseWriter, r
return nil, fmt.Errorf("Bad limit: %s", err) return nil, fmt.Errorf("Bad limit: %s", err)
} }
params := req.URL.Query()
if raw := params.Get("connect"); raw != "" {
val, err := strconv.ParseBool(raw)
if err != nil {
return nil, fmt.Errorf("Error parsing 'connect' value: %s", err)
}
args.Connect = val
}
var reply structs.PreparedQueryExecuteResponse var reply structs.PreparedQueryExecuteResponse
defer setMeta(resp, &reply.QueryMeta) defer setMeta(resp, &reply.QueryMeta)
RETRY_ONCE: RETRY_ONCE:

23
agent/prepared_query_endpoint_test.go

@ -11,6 +11,7 @@ import (
"github.com/hashicorp/consul/agent/structs" "github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/types" "github.com/hashicorp/consul/types"
"github.com/stretchr/testify/require"
) )
// MockPreparedQuery is a fake endpoint that we inject into the Consul server // MockPreparedQuery is a fake endpoint that we inject into the Consul server
@ -678,6 +679,28 @@ func TestPreparedQuery_Explain(t *testing.T) {
t.Fatalf("bad code: %d", resp.Code) t.Fatalf("bad code: %d", resp.Code)
} }
}) })
// Ensure that Connect is passed through
t.Run("", func(t *testing.T) {
a := NewTestAgent(t.Name(), "")
defer a.Shutdown()
require := require.New(t)
m := MockPreparedQuery{
executeFn: func(args *structs.PreparedQueryExecuteRequest, reply *structs.PreparedQueryExecuteResponse) error {
require.True(args.Connect)
return nil
},
}
require.NoError(a.registerEndpoint("PreparedQuery", &m))
body := bytes.NewBuffer(nil)
req, _ := http.NewRequest("GET", "/v1/query/my-id/execute?connect=true", body)
resp := httptest.NewRecorder()
_, err := a.srv.PreparedQuerySpecific(resp, req)
require.NoError(err)
require.Equal(200, resp.Code)
})
} }
func TestPreparedQuery_Get(t *testing.T) { func TestPreparedQuery_Get(t *testing.T) {

Loading…
Cancel
Save