This commit is contained in:
Aliaksandr Valialkin 2024-05-20 21:47:30 +02:00
parent fbf1485f14
commit c5c96d8016
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
4 changed files with 116 additions and 2 deletions

View file

@ -4,6 +4,107 @@ import (
"testing"
)
func TestParsePipeDeleteSuccess(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeSuccess(t, pipeStr)
}
f(`delete f1`)
f(`delete f1, f2`)
}
func TestParsePipeDeleteFailure(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeFailure(t, pipeStr)
}
f(`delete`)
f(`delete x y`)
}
func TestPipeDelete(t *testing.T) {
f := func(pipeStr string, rows, rowsExpected [][]Field) {
t.Helper()
expectPipeResults(t, pipeStr, rows, rowsExpected)
}
// single row, drop existing field
f("delete _msg", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
{"a", `test`},
},
})
// single row, drop existing field multiple times
f("delete _msg, _msg", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
{"a", `test`},
},
})
// single row, drop all the fields
f("delete a, _msg", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{})
// delete non-existing fields
f("delete foo, _msg, bar", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
{"a", `test`},
},
})
// Multiple rows
f("delete _msg, a", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
{
{"a", `foobar`},
},
{
{"b", `baz`},
{"c", "d"},
{"e", "afdf"},
},
{
{"c", "dss"},
{"b", "df"},
},
}, [][]Field{
{
{"b", `baz`},
{"c", "d"},
{"e", "afdf"},
},
{
{"c", "dss"},
{"b", "df"},
},
})
}
func TestPipeDeleteUpdateNeededFields(t *testing.T) {
f := func(s, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) {
t.Helper()

View file

@ -56,6 +56,19 @@ func TestPipeFields(t *testing.T) {
},
})
// single row, no existing fields
f("fields x, y", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
{"x", ``},
{"y", ``},
},
})
// single row, mention existing field multiple times
f("fileds a, a", [][]Field{
{