From 25d8f2d1800b2f86b34a2e14b9ac29438c441a17 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 20 May 2024 22:06:03 +0200 Subject: [PATCH] wip --- lib/logstorage/pipe_limit_test.go | 92 +++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/lib/logstorage/pipe_limit_test.go b/lib/logstorage/pipe_limit_test.go index 49e79d5d2..bc7afa4fd 100644 --- a/lib/logstorage/pipe_limit_test.go +++ b/lib/logstorage/pipe_limit_test.go @@ -4,6 +4,98 @@ import ( "testing" ) +func TestParsePipeLimitSuccess(t *testing.T) { + f := func(pipeStr string) { + t.Helper() + expectParsePipeSuccess(t, pipeStr) + } + + f(`limit 10`) + f(`limit 10000`) +} + +func TestParsePipeLimitFailure(t *testing.T) { + f := func(pipeStr string) { + t.Helper() + expectParsePipeFailure(t, pipeStr) + } + + f(`limit`) + f(`limit -10`) + f(`limit foo`) +} + +func TestPipeLimit(t *testing.T) { + f := func(pipeStr string, rows, rowsExpected [][]Field) { + t.Helper() + expectPipeResults(t, pipeStr, rows, rowsExpected) + } + + f("limit 100", [][]Field{ + { + {"_msg", `{"foo":"bar"}`}, + {"a", `test`}, + }, + }, [][]Field{ + { + {"_msg", `{"foo":"bar"}`}, + {"a", `test`}, + }, + }) + + f("limit 1", [][]Field{ + { + {"_msg", `{"foo":"bar"}`}, + {"a", `test`}, + }, + }, [][]Field{ + { + {"_msg", `{"foo":"bar"}`}, + {"a", `test`}, + }, + }) + + f("limit 0", [][]Field{ + { + {"_msg", `{"foo":"bar"}`}, + {"a", `test`}, + }, + }, [][]Field{}) + + f("limit 1", [][]Field{ + { + {"_msg", `{"foo":"bar"}`}, + {"a", `test`}, + }, + { + {"_msg", `abc`}, + {"a", `aiewr`}, + }, + }, [][]Field{ + { + {"_msg", `{"foo":"bar"}`}, + {"a", `test`}, + }, + }) + + f("limit 1", [][]Field{ + { + {"_msg", `{"foo":"bar"}`}, + {"a", `test`}, + }, + { + {"_msg", `abc`}, + {"a", `aiewr`}, + {"asdf", "fsf"}, + }, + }, [][]Field{ + { + {"_msg", `{"foo":"bar"}`}, + {"a", `test`}, + }, + }) +} + func TestPipeLimitUpdateNeededFields(t *testing.T) { f := func(s, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) { t.Helper()