mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
Input definition GET and DELETE handle the case when the definition does not exist
This commit is contained in:
parent
56f8705407
commit
8e87969933
2 changed files with 24 additions and 10 deletions
21
handler.go
21
handler.go
|
|
@ -1566,8 +1566,13 @@ func (h *Handler) handleGetInputDefinition(w http.ResponseWriter, r *http.Reques
|
|||
return
|
||||
}
|
||||
|
||||
inputDef, _ := index.inputDefinitions[inputDefName]
|
||||
if err := json.NewEncoder(w).Encode(InputDefinitionInfo{
|
||||
inputDef, err := index.InputDefinition(inputDefName)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
if err = json.NewEncoder(w).Encode(InputDefinitionInfo{
|
||||
Frames: inputDef.frames,
|
||||
Fields: inputDef.fields,
|
||||
}); err != nil {
|
||||
|
|
@ -1629,7 +1634,7 @@ func (h *Handler) handlePostInput(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
for _, req := range reqs {
|
||||
bits, err := h.InputJsonDataParser(req.(map[string]interface{}), index, inputDefName)
|
||||
bits, err := h.InputJSONDataParser(req.(map[string]interface{}), index, inputDefName)
|
||||
if err == ErrInputDefinitionNotFound {
|
||||
http.Error(w, err.Error(), http.StatusNotFound)
|
||||
return
|
||||
|
|
@ -1650,11 +1655,11 @@ func (h *Handler) handlePostInput(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// InputJsonDataParser validate input json file and execute SetBit
|
||||
func (h *Handler) InputJsonDataParser(req map[string]interface{}, index *Index, name string) (map[string][]*Bit, error) {
|
||||
inputDef := index.inputDefinition(name)
|
||||
if inputDef == nil {
|
||||
return nil, ErrInputDefinitionNotFound
|
||||
// InputJSONDataParser validate input json file and execute SetBit
|
||||
func (h *Handler) InputJSONDataParser(req map[string]interface{}, index *Index, name string) (map[string][]*Bit, error) {
|
||||
inputDef, err := index.InputDefinition(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// if field in input data is not in defined definition, return error
|
||||
var columnLabel string
|
||||
|
|
|
|||
|
|
@ -1253,8 +1253,10 @@ func TestHandler_DeleteInputDefinition(t *testing.T) {
|
|||
t.Fatalf("unexpected status code: %d", w.Code)
|
||||
} else if body := w.Body.String(); body != `{}`+"\n" {
|
||||
t.Fatalf("unexpected body: %s", body)
|
||||
} else if index.InputDefinition("test") != nil {
|
||||
t.Fatalf("unexpected result: %v", index.InputDefinition("test"))
|
||||
}
|
||||
_, err = index.InputDefinition("test")
|
||||
if err != pilosa.ErrInputDefinitionNotFound {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1299,6 +1301,13 @@ func TestHandler_GetInputDefinition(t *testing.T) {
|
|||
} else if body := w.Body.String(); body != string(expect)+"\n" {
|
||||
t.Fatalf("unexpected body: %s, expect: %s", body, string(expect))
|
||||
}
|
||||
|
||||
// Check non existant definition
|
||||
w = httptest.NewRecorder()
|
||||
h.ServeHTTP(w, MustNewHTTPRequest("GET", "/index/i0/input-definition/foo", strings.NewReader("")))
|
||||
if w.Code != http.StatusNotFound {
|
||||
t.Fatalf("unexpected status code: %d", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
var defaultBody = `
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue