Skip to content

Commit

Permalink
add tests for parser suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
kvch committed Jul 15, 2021
1 parent ba77a50 commit d14cfb1
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions libbeat/reader/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,75 @@ import (
"github.com/elastic/beats/v7/libbeat/reader/readfile/encoding"
)

func TestParsersConfigSuffix(t *testing.T) {
tests := map[string]struct {
parsers map[string]interface{}
expectedSuffix string
expectedError string
}{
"parsers with no suffix config": {
parsers: map[string]interface{}{
"parsers": []map[string]interface{}{
map[string]interface{}{
"container": map[string]interface{}{
"stream": "all",
},
},
},
},
},
"parsers with correct suffix config": {
parsers: map[string]interface{}{
"parsers": []map[string]interface{}{
map[string]interface{}{
"container": map[string]interface{}{
"stream": "stdout",
},
},
},
},
expectedSuffix: "stdout",
},
"parsers with multiple suffix config": {
parsers: map[string]interface{}{
"parsers": []map[string]interface{}{
map[string]interface{}{
"container": map[string]interface{}{
"stream": "stdout",
},
},
map[string]interface{}{
"container": map[string]interface{}{
"stream": "stderr",
},
},
},
},
expectedError: "only one stream selection is allowed",
},
}

for name, test := range tests {
test := test
t.Run(name, func(t *testing.T) {
cfg := common.MustNewConfigFrom(test.parsers)
var parsersConfig testParsersConfig
err := cfg.Unpack(&parsersConfig)
require.NoError(t, err)
c, err := NewConfig(CommonConfig{MaxBytes: 1024, LineTerminator: readfile.AutoLineTerminator}, parsersConfig.Parsers)

if test.expectedError == "" {
require.NoError(t, err)
} else {
require.Contains(t, err.Error(), test.expectedError)
return
}
require.Equal(t, c.Suffix, test.expectedSuffix)
})
}

}

func TestParsersConfigAndReading(t *testing.T) {
tests := map[string]struct {
lines string
Expand Down

0 comments on commit d14cfb1

Please sign in to comment.