This commit is contained in:
Aliaksandr Valialkin 2024-05-19 23:58:38 +02:00
parent b644169fc4
commit 998b4a0eef
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
2 changed files with 64 additions and 0 deletions

View file

@ -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", "")
}

View file

@ -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", "")
}