This commit is contained in:
Aliaksandr Valialkin 2024-05-20 22:09:54 +02:00
parent 25d8f2d180
commit 13b55a338b
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -4,6 +4,92 @@ import (
"testing"
)
func TestParsePipeOffsetSuccess(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeSuccess(t, pipeStr)
}
f(`offset 10`)
f(`offset 10000`)
}
func TestParsePipeOffsetFailure(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeFailure(t, pipeStr)
}
f(`offset`)
f(`offset -10`)
f(`offset foo`)
}
func TestPipeOffset(t *testing.T) {
f := func(pipeStr string, rows, rowsExpected [][]Field) {
t.Helper()
expectPipeResults(t, pipeStr, rows, rowsExpected)
}
f("offset 100", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{})
f("offset 0", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
})
f("offset 1", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
{
{"_msg", `abc`},
{"a", `aiewr`},
},
}, [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
})
f("offset 2", [][]Field{
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
{
{"_msg", `sdfsd`},
{"adffd", `aiewr`},
{"assdff", "fsf"},
},
{
{"_msg", `abc`},
{"a", `aiewr`},
{"asdf", "fsf"},
},
}, [][]Field{
{
{"_msg", `abc`},
{"a", `aiewr`},
{"asdf", "fsf"},
},
})
}
func TestPipeOffsetUpdateNeededFields(t *testing.T) {
f := func(s, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) {
t.Helper()