This commit is contained in:
Aliaksandr Valialkin 2024-05-20 22:02:09 +02:00
parent c5c96d8016
commit eeadefbca0
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
2 changed files with 155 additions and 0 deletions

View file

@ -4,6 +4,64 @@ import (
"testing" "testing"
) )
func TestParsePipeFieldNamesSuccess(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeSuccess(t, pipeStr)
}
f(`field_names as x`)
}
func TestParsePipeFieldNamesFailure(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeFailure(t, pipeStr)
}
f(`field_names`)
f(`field_names(foo)`)
f(`field_names a b`)
f(`field_names as`)
}
func TestPipeFieldNames(t *testing.T) {
f := func(pipeStr string, rows, rowsExpected [][]Field) {
t.Helper()
expectPipeResults(t, pipeStr, rows, rowsExpected)
}
// single row, result column doesn't clash with original columns
f("field_names as x", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
{"x", "_msg"},
},
{
{"x", "a"},
},
})
// single row, result column do clashes with original columns
f("field_names as _msg", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
{"_msg", "_msg"},
},
{
{"_msg", "a"},
},
})
}
func TestPipeFieldNamesUpdateNeededFields(t *testing.T) { func TestPipeFieldNamesUpdateNeededFields(t *testing.T) {
f := func(s string, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) { f := func(s string, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) {
t.Helper() t.Helper()

View file

@ -4,6 +4,103 @@ import (
"testing" "testing"
) )
func TestParsePipeFilterSuccess(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeSuccess(t, pipeStr)
}
f(`filter *`)
f(`filter foo bar`)
f(`filter a:b or c:d in(x,y) z:>343`)
}
func TestParsePipeFilterFailure(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeFailure(t, pipeStr)
}
f(`filter`)
f(`filter |`)
f(`filter ()`)
}
func TestPipeFilter(t *testing.T) {
f := func(pipeStr string, rows, rowsExpected [][]Field) {
t.Helper()
expectPipeResults(t, pipeStr, rows, rowsExpected)
}
// filter mismatch
f("filter abc", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{})
// filter match
f("filter _msg:foo", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
})
// multiple rows
f("filter x:foo y:bar", [][]Field{
{
{"a", "f1"},
{"x", "foo"},
{"y", "bar"},
},
{
{"a", "f2"},
{"x", "x foo bar"},
{"y", "aa bar bbb"},
{"z", "iwert"},
},
{
{"a", "f3"},
{"x", "x fo bar"},
{"y", "aa bar bbb"},
{"z", "it"},
},
{
{"a", "f4"},
{"x", "x foo bar"},
{"y", "aa ba bbb"},
{"z", "t"},
},
{
{"x", "x foo"},
{"y", "aa bar"},
},
}, [][]Field{
{
{"a", "f1"},
{"x", "foo"},
{"y", "bar"},
},
{
{"a", "f2"},
{"x", "x foo bar"},
{"y", "aa bar bbb"},
{"z", "iwert"},
},
{
{"x", "x foo"},
{"y", "aa bar"},
},
})
}
func TestPipeFilterUpdateNeededFields(t *testing.T) { func TestPipeFilterUpdateNeededFields(t *testing.T) {
f := func(s string, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) { f := func(s string, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) {
t.Helper() t.Helper()