agent: accept connect param for execute
This commit is contained in:
parent
52c10d2208
commit
e016f37ae7
|
@ -107,6 +107,16 @@ func (s *HTTPServer) preparedQueryExecute(id string, resp http.ResponseWriter, r
|
|||
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
|
||||
defer setMeta(resp, &reply.QueryMeta)
|
||||
RETRY_ONCE:
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/consul/agent/structs"
|
||||
"github.com/hashicorp/consul/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// 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)
|
||||
}
|
||||
})
|
||||
|
||||
// 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) {
|
||||
|
|
Loading…
Reference in New Issue