This commit is contained in:
Aliaksandr Valialkin 2024-05-20 21:41:37 +02:00
parent ae4f92f4cd
commit fbf1485f14
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -4,6 +4,122 @@ import (
"testing"
)
func TestParsePipeFieldsSuccess(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeSuccess(t, pipeStr)
}
f(`fields *`)
f(`fields f1`)
f(`fields f1, f2, f3`)
}
func TestParsePipeFieldsFailure(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeFailure(t, pipeStr)
}
f(`fields`)
f(`fields x y`)
}
func TestPipeFields(t *testing.T) {
f := func(pipeStr string, rows, rowsExpected [][]Field) {
t.Helper()
expectPipeResults(t, pipeStr, rows, rowsExpected)
}
// single row, star
f("fields *", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
})
// single row, leave existing field
f("fields a", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
{"a", `test`},
},
})
// single row, mention existing field multiple times
f("fileds a, a", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
{"a", `test`},
},
})
// mention non-existing fields
f("fields foo, a, bar", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
{"foo", ""},
{"bar", ""},
{"a", `test`},
},
})
// Multiple rows
f("fields a, b", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
{
{"a", `foobar`},
},
{
{"b", `baz`},
{"c", "d"},
{"e", "afdf"},
},
{
{"c", "dss"},
{"b", "df"},
},
}, [][]Field{
{
{"a", `test`},
{"b", `test`},
},
{
{"a", `foobar`},
{"b", `foobar`},
},
{
{"a", ""},
{"b", ""},
},
{
{"a", ""},
{"b", "df"},
},
})
}
func TestPipeFieldsUpdateNeededFields(t *testing.T) {
f := func(s, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) {
t.Helper()