agent: accept connect param for execute

This commit is contained in:
Mitchell Hashimoto 2018-06-05 16:04:50 -07:00 committed by Jack Pearkes
parent 52c10d2208
commit e016f37ae7
2 changed files with 33 additions and 0 deletions

View File

@ -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:

View File

@ -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) {