From f4ac7c50b670363462327bf694834132697eb621 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 20 May 2024 16:49:51 +0200 Subject: [PATCH] wip --- lib/logstorage/pipe_extract_test.go | 5 ++++- lib/logstorage/pipe_unpack_json_test.go | 27 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/logstorage/pipe_extract_test.go b/lib/logstorage/pipe_extract_test.go index 6635bc096..86c7de364 100644 --- a/lib/logstorage/pipe_extract_test.go +++ b/lib/logstorage/pipe_extract_test.go @@ -246,7 +246,7 @@ func expectParsePipeFailure(t *testing.T, pipeStr string) { lex := newLexer(pipeStr) p, err := parsePipe(lex) - if err == nil { + if err == nil && lex.isEnd() { t.Fatalf("expecting error when parsing [%s]; parsed result: [%s]", pipeStr, p) } } @@ -259,6 +259,9 @@ func expectParsePipeSuccess(t *testing.T, pipeStr string) { if err != nil { t.Fatalf("cannot parse [%s]: %s", pipeStr, err) } + if !lex.isEnd() { + t.Fatalf("unexpected tail after parsing [%s]: [%s]", pipeStr, lex.s) + } pipeStrResult := p.String() if pipeStrResult != pipeStr { diff --git a/lib/logstorage/pipe_unpack_json_test.go b/lib/logstorage/pipe_unpack_json_test.go index 99e0fccd3..abaa2c811 100644 --- a/lib/logstorage/pipe_unpack_json_test.go +++ b/lib/logstorage/pipe_unpack_json_test.go @@ -8,6 +8,33 @@ import ( "testing" ) +func TestParsePipeUnpackJSONSuccess(t *testing.T) { + f := func(pipeStr string) { + t.Helper() + expectParsePipeSuccess(t, pipeStr) + } + + f(`unpack_json`) + f(`unpack_json from x`) + f(`unpack_json from x result_prefix abc`) + f(`unpack_json result_prefix abc`) +} + +func TestParsePipeUnpackJSONFailure(t *testing.T) { + f := func(pipeStr string) { + t.Helper() + expectParsePipeFailure(t, pipeStr) + } + + f(`unpack_json foo`) + f(`unpack_json from`) + f(`unpack_json from x y`) + f(`unpack_json from x result_prefix`) + f(`unpack_json from x result_prefix a b`) + f(`unpack_json result_prefix`) + f(`unpack_json result_prefix a b`) +} + func TestPipeUnpackJSON(t *testing.T) { f := func(pipeStr string, rows, rowsExpected [][]Field) { t.Helper()