diff --git a/lib/logstorage/pipe_offset_test.go b/lib/logstorage/pipe_offset_test.go index 53b22af61..87d111ce0 100644 --- a/lib/logstorage/pipe_offset_test.go +++ b/lib/logstorage/pipe_offset_test.go @@ -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()