VictoriaMetrics/lib/logstorage/pipe_extract_test.go

40 lines
1.4 KiB
Go
Raw Normal View History

2024-05-19 02:24:32 +00:00
package logstorage
import (
"testing"
)
2024-05-19 13:11:17 +00:00
func TestPipeExtractUpdateNeededFields(t *testing.T) {
f := func(s string, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) {
t.Helper()
2024-05-19 22:05:07 +00:00
expectPipeNeededFields(t, s, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected)
2024-05-19 13:11:17 +00:00
}
// all the needed fields
2024-05-19 19:25:52 +00:00
f("extract from x '<foo>'", "*", "", "*", "foo")
2024-05-19 13:11:17 +00:00
// all the needed fields, unneeded fields do not intersect with fromField and output fields
2024-05-19 19:25:52 +00:00
f("extract from x '<foo>'", "*", "f1,f2", "*", "f1,f2,foo")
2024-05-19 13:11:17 +00:00
// all the needed fields, unneeded fields intersect with fromField
2024-05-19 19:25:52 +00:00
f("extract from x '<foo>'", "*", "f2,x", "*", "f2,foo")
2024-05-19 13:11:17 +00:00
// all the needed fields, unneeded fields intersect with output fields
2024-05-19 19:25:52 +00:00
f("extract from x '<foo>x<bar>'", "*", "f2,foo", "*", "bar,f2,foo")
2024-05-19 13:11:17 +00:00
// all the needed fields, unneeded fields intersect with all the output fields
2024-05-19 19:25:52 +00:00
f("extract from x '<foo>x<bar>'", "*", "f2,foo,bar", "*", "bar,f2,foo,x")
2024-05-19 13:11:17 +00:00
// needed fields do not intersect with fromField and output fields
f("extract from x '<foo>x<bar>'", "f1,f2", "", "f1,f2", "")
// needed fields intersect with fromField
f("extract from x '<foo>x<bar>'", "f2,x", "", "f2,x", "")
// needed fields intersect with output fields
f("extract from x '<foo>x<bar>'", "f2,foo", "", "f2,x", "")
// needed fields intersect with fromField and output fields
f("extract from x '<foo>x<bar>'", "f2,foo,x,y", "", "f2,x,y", "")
}