Skip to content

Commit

Permalink
Fix some messages and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
exekias committed Jun 15, 2017
1 parent 164a83c commit 0df8b11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions libbeat/processors/actions/extract_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ func NewExtractField(c common.Config) (processors.Processor, error) {
func (f extract_field) Run(event common.MapStr) (common.MapStr, error) {
fieldValue, err := event.GetValue(f.Field)
if err != nil {
return nil, fmt.Errorf("Error getting field '%s' from event", f.Field)
return nil, fmt.Errorf("error getting field '%s' from event", f.Field)
}

value, ok := fieldValue.(string)
if !ok {
return nil, fmt.Errorf("Could not get a string from field '%s'", f.Field)
return nil, fmt.Errorf("could not get a string from field '%s'", f.Field)
}

parts := strings.Split(value, f.Separator)
parts = deleteEmpty(parts)
if len(parts) < f.Index+1 {
return nil, fmt.Errorf("Index is out of range for field '%s'", f.Field)
return nil, fmt.Errorf("index is out of range for field '%s'", f.Field)
}

event.Put(f.Target, parts[f.Index])
Expand Down
11 changes: 7 additions & 4 deletions libbeat/processors/actions/extract_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func TestCommonPaths(t *testing.T) {
actual := runExtractField(t, testConfig, input)

result, err := actual.GetValue(test.Target)
assert.NoError(t, err)
if err != nil {
t.Fatalf("could not get target field: %s", err)
}
assert.Equal(t, result.(string), test.Result)
}
}
Expand All @@ -76,12 +78,13 @@ func runExtractField(t *testing.T, config *common.Config, input common.MapStr) c

p, err := NewExtractField(*config)
if err != nil {
logp.Err("Error initializing decode_json_fields")
t.Fatal(err)
t.Fatalf("error initializing extract_field: %s", err)
}

actual, err := p.Run(input)
assert.NoError(t, err)
if err != nil {
t.Fatalf("error running extract_field: %s", err)
}

return actual
}

0 comments on commit 0df8b11

Please sign in to comment.