2024-05-20 04:08:30 +02:00
|
|
|
package logstorage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2024-05-22 21:01:20 +02:00
|
|
|
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 -10`)
|
|
|
|
f(`limit foo`)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPipeLimit(t *testing.T) {
|
|
|
|
f := func(pipeStr string, rows, rowsExpected [][]Field) {
|
|
|
|
t.Helper()
|
|
|
|
expectPipeResults(t, pipeStr, rows, rowsExpected)
|
|
|
|
}
|
2024-05-28 19:29:41 +02:00
|
|
|
f("limit", [][]Field{
|
|
|
|
{
|
|
|
|
{"_msg", `{"foo":"bar"}`},
|
|
|
|
{"a", `test`},
|
|
|
|
},
|
|
|
|
}, [][]Field{
|
|
|
|
{
|
|
|
|
{"_msg", `{"foo":"bar"}`},
|
|
|
|
{"a", `test`},
|
|
|
|
},
|
|
|
|
})
|
2024-05-22 21:01:20 +02:00
|
|
|
|
|
|
|
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`},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-20 04:08:30 +02:00
|
|
|
func TestPipeLimitUpdateNeededFields(t *testing.T) {
|
|
|
|
f := func(s, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) {
|
|
|
|
t.Helper()
|
|
|
|
expectPipeNeededFields(t, s, neededFields, unneededFields, 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", "")
|
|
|
|
}
|