field definitions require an action

This commit is contained in:
Michael Baird 2017-06-29 13:16:05 -05:00
parent 7abab7b795
commit fb7e1091b5
4 changed files with 21 additions and 8 deletions

View file

@ -1319,7 +1319,7 @@ func TestHandler_GetInputDefinition(t *testing.T) {
t.Fatalf("unexpected body: %s, expect: %s", body, string(expect))
}
// Check nonexistant definition.
// Check nonexistent definition.
w = httptest.NewRecorder()
h.ServeHTTP(w, MustNewHTTPRequest("GET", "/index/i0/input-definition/foo", strings.NewReader("")))
if w.Code != http.StatusNotFound {
@ -1439,7 +1439,7 @@ func TestHandler_CreateInput(t *testing.T) {
t.Fatalf("unexpected body: %s, expect: %s", body, pilosa.ErrIndexNotFound)
}
// Check nonexistant definition.
// Check nonexistent definition.
w = httptest.NewRecorder()
h.ServeHTTP(w, MustNewHTTPRequest("POST", "/index/i0/input/input2", bytes.NewBuffer(inputBody)))
if w.Code != http.StatusNotFound {

View file

@ -278,13 +278,9 @@ func (i *InputDefinitionInfo) Validate(columnLabel string) error {
// Validate columnLabel and duplicate primaryKey.
for _, field := range i.Fields {
if field.PrimaryKey {
numPrimaryKey++
if field.Name != columnLabel {
return ErrInputDefinitionColumnLabel
}
}
var actionCount int
for _, action := range field.Actions {
actionCount++
if err := action.Validate(); err != nil {
return err
}
@ -299,6 +295,14 @@ func (i *InputDefinitionInfo) Validate(columnLabel string) error {
accountRowID[action.Frame] = convert(action.RowID)
}
}
if field.PrimaryKey {
numPrimaryKey++
if field.Name != columnLabel {
return ErrInputDefinitionColumnLabel
}
} else if actionCount == 0 {
return ErrInputDefinitionActionRequired
}
}
if len(i.Fields) > 0 && numPrimaryKey == 0 {

View file

@ -180,6 +180,14 @@ func TestActionValidation(t *testing.T) {
if !strings.Contains(err.Error(), "duplicate rowID with other field") {
t.Fatalf("Expected duplicate rowID with other field error, actual error: %s", err)
}
field = pilosa.InputDefinitionField{Name: "id", PrimaryKey: true}
field1 = pilosa.InputDefinitionField{Name: "test", PrimaryKey: false}
info = pilosa.InputDefinitionInfo{Frames: []pilosa.InputFrame{frame}, Fields: []pilosa.InputDefinitionField{field, field1}}
err = info.Validate("id")
if err != pilosa.ErrInputDefinitionActionRequired {
t.Fatalf("Expect error: %s, actual err: %s", pilosa.ErrInputDefinitionActionRequired, err)
}
}
func TestHandleAction(t *testing.T) {

View file

@ -43,6 +43,7 @@ var (
ErrInputDefinitionNameRequired = errors.New("input-definition name required")
ErrInputDefinitionAttrsRequired = errors.New("frames and fields are required")
ErrInputDefinitionValueMap = errors.New("valueMap required for map")
ErrInputDefinitionActionRequired = errors.New("field definitions require an action")
ErrFieldNameRequired = errors.New("field name required")
ErrInvalidFieldType = errors.New("invalid field type")