From 998b4a0eeffe04f60c82e42534676027673654f2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 19 May 2024 23:58:38 +0200 Subject: [PATCH] wip --- lib/logstorage/pipe_limit_test.go | 32 ++++++++++++++++++++++++++++++ lib/logstorage/pipe_offset_test.go | 32 ++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 lib/logstorage/pipe_limit_test.go create mode 100644 lib/logstorage/pipe_offset_test.go diff --git a/lib/logstorage/pipe_limit_test.go b/lib/logstorage/pipe_limit_test.go new file mode 100644 index 000000000..b19a567e0 --- /dev/null +++ b/lib/logstorage/pipe_limit_test.go @@ -0,0 +1,32 @@ +package logstorage + +import ( + "testing" +) + +func TestPipeLimitUpdateNeededFields(t *testing.T) { + f := func(s, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) { + t.Helper() + + nfs := newTestFieldsSet(neededFields) + unfs := newTestFieldsSet(unneededFields) + + lex := newLexer(s) + p, err := parsePipeLimit(lex) + if err != nil { + t.Fatalf("cannot parse %s: %s", s, err) + } + p.updateNeededFields(nfs, unfs) + + assertNeededFields(t, nfs, unfs, neededFieldsExpected, unneededFieldsExpected) + } + + // all the needed fields + f("limit 10", "*", "", "*", "") + + // all the needed fields, plus unneeded fields + f("limit 10", "*", "f1,f2", "*", "f1,f2") + + // needed fields + f("limit 10", "f1,f2", "", "f1,f2", "") +} diff --git a/lib/logstorage/pipe_offset_test.go b/lib/logstorage/pipe_offset_test.go new file mode 100644 index 000000000..63eba3407 --- /dev/null +++ b/lib/logstorage/pipe_offset_test.go @@ -0,0 +1,32 @@ +package logstorage + +import ( + "testing" +) + +func TestPipeOffsetUpdateNeededFields(t *testing.T) { + f := func(s, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) { + t.Helper() + + nfs := newTestFieldsSet(neededFields) + unfs := newTestFieldsSet(unneededFields) + + lex := newLexer(s) + p, err := parsePipeOffset(lex) + if err != nil { + t.Fatalf("cannot parse %s: %s", s, err) + } + p.updateNeededFields(nfs, unfs) + + assertNeededFields(t, nfs, unfs, neededFieldsExpected, unneededFieldsExpected) + } + + // all the needed fields + f("offset 10", "*", "", "*", "") + + // all the needed fields, plus unneeded fields + f("offset 10", "*", "f1,f2", "*", "f1,f2") + + // needed fields + f("offset 10", "f1,f2", "", "f1,f2", "") +}