mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
Change JSON tag name on WireQueryResponse from execution-time to exec_time (#2394)
* Change JSON response name from exec_time to execution-time Execution time stopped working in the CLI because it uses the latest json tag. * Wait, don't break the interface. * Add a test for the sql response json tags. This is to make sure that if someone like Travis just goes and changes a tag name to be more consistent, that we perhaps catch that before it gets to the end user. * Change exec_time to execution-time after all
This commit is contained in:
parent
e8505d8a53
commit
b5dd3ea02e
3 changed files with 63 additions and 3 deletions
|
|
@ -1438,9 +1438,9 @@ func (h *Handler) handlePostSQL(w http.ResponseWriter, r *http.Request) {
|
|||
var value []byte
|
||||
value, err = json.Marshal(execTime)
|
||||
if err != nil {
|
||||
w.Write([]byte(`,"exec_time": 0`))
|
||||
w.Write([]byte(`,"execution-time": 0`))
|
||||
} else {
|
||||
w.Write([]byte(`,"exec_time":`))
|
||||
w.Write([]byte(`,"execution-time":`))
|
||||
w.Write(value)
|
||||
}
|
||||
w.Write([]byte("}"))
|
||||
|
|
@ -1488,7 +1488,7 @@ func (h *Handler) handlePostSQL(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
planBytes = []byte(`"PROBLEM ENCODING QUERY PLAN"`)
|
||||
}
|
||||
w.Write([]byte(`,"queryPlan":`))
|
||||
w.Write([]byte(`,"query-plan":`))
|
||||
w.Write(planBytes)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"github.com/molecula/featurebase/v3/encoding/proto"
|
||||
"github.com/molecula/featurebase/v3/server"
|
||||
"github.com/molecula/featurebase/v3/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestHandlerOptions(t *testing.T) {
|
||||
|
|
@ -541,6 +542,64 @@ func TestGetViewAndDelete(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestHandlerSQL tests that the json coming back from a POST /sql request has
|
||||
// the expected json tags.
|
||||
func TestHandlerSQL(t *testing.T) {
|
||||
cfg := server.NewConfig()
|
||||
cfg.SQL.EndpointEnabled = true
|
||||
c := test.MustRunCluster(t, 1, []server.CommandOption{
|
||||
server.OptCommandConfig(cfg),
|
||||
})
|
||||
defer c.Close()
|
||||
|
||||
m := c.GetPrimary()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
url string
|
||||
sql string
|
||||
expKeys []string
|
||||
}{
|
||||
{
|
||||
name: "sql",
|
||||
url: "/sql",
|
||||
sql: "show tables",
|
||||
expKeys: []string{"schema", "data", "execution-time"},
|
||||
},
|
||||
{
|
||||
name: "sql-with-plan",
|
||||
url: "/sql?plan=1",
|
||||
sql: "show tables",
|
||||
expKeys: []string{"schema", "data", "query-plan", "execution-time"},
|
||||
},
|
||||
{
|
||||
name: "invalid-sql",
|
||||
url: "/sql",
|
||||
sql: "invalid sql",
|
||||
expKeys: []string{"error", "execution-time"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
sqlURL := fmt.Sprintf("%s%s", m.URL(), tt.url)
|
||||
resp := test.Do(t, "POST", sqlURL, tt.sql)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("post sql, status: %d, body=%s", resp.StatusCode, resp.Body)
|
||||
}
|
||||
|
||||
out := make(map[string]interface{})
|
||||
assert.NoError(t, json.Unmarshal([]byte(resp.Body), &out))
|
||||
|
||||
keys := make([]string, 0, len(out))
|
||||
for k := range out {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
||||
assert.ElementsMatch(t, tt.expKeys, keys)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTranslationHandlers(t *testing.T) {
|
||||
// reusable data for the tests
|
||||
nameBytes, err := json.Marshal([]string{"a", "b", "c"})
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ func OptCommandConfig(config *Config) CommandOption {
|
|||
c.Config.TLS = config.TLS
|
||||
c.Config.MDSAddress = config.MDSAddress
|
||||
c.Config.WriteLogger = config.WriteLogger
|
||||
c.Config.SQL.EndpointEnabled = config.SQL.EndpointEnabled
|
||||
return nil
|
||||
}
|
||||
c.Config = config
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue