mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-31 15:06:26 +00:00
wip
This commit is contained in:
parent
c5c96d8016
commit
eeadefbca0
2 changed files with 155 additions and 0 deletions
|
@ -4,6 +4,64 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestParsePipeFieldNamesSuccess(t *testing.T) {
|
||||
f := func(pipeStr string) {
|
||||
t.Helper()
|
||||
expectParsePipeSuccess(t, pipeStr)
|
||||
}
|
||||
|
||||
f(`field_names as x`)
|
||||
}
|
||||
|
||||
func TestParsePipeFieldNamesFailure(t *testing.T) {
|
||||
f := func(pipeStr string) {
|
||||
t.Helper()
|
||||
expectParsePipeFailure(t, pipeStr)
|
||||
}
|
||||
|
||||
f(`field_names`)
|
||||
f(`field_names(foo)`)
|
||||
f(`field_names a b`)
|
||||
f(`field_names as`)
|
||||
}
|
||||
|
||||
func TestPipeFieldNames(t *testing.T) {
|
||||
f := func(pipeStr string, rows, rowsExpected [][]Field) {
|
||||
t.Helper()
|
||||
expectPipeResults(t, pipeStr, rows, rowsExpected)
|
||||
}
|
||||
|
||||
// single row, result column doesn't clash with original columns
|
||||
f("field_names as x", [][]Field{
|
||||
{
|
||||
{"_msg", `{"foo":"bar"}`},
|
||||
{"a", `test`},
|
||||
},
|
||||
}, [][]Field{
|
||||
{
|
||||
{"x", "_msg"},
|
||||
},
|
||||
{
|
||||
{"x", "a"},
|
||||
},
|
||||
})
|
||||
|
||||
// single row, result column do clashes with original columns
|
||||
f("field_names as _msg", [][]Field{
|
||||
{
|
||||
{"_msg", `{"foo":"bar"}`},
|
||||
{"a", `test`},
|
||||
},
|
||||
}, [][]Field{
|
||||
{
|
||||
{"_msg", "_msg"},
|
||||
},
|
||||
{
|
||||
{"_msg", "a"},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPipeFieldNamesUpdateNeededFields(t *testing.T) {
|
||||
f := func(s string, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) {
|
||||
t.Helper()
|
||||
|
|
|
@ -4,6 +4,103 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestParsePipeFilterSuccess(t *testing.T) {
|
||||
f := func(pipeStr string) {
|
||||
t.Helper()
|
||||
expectParsePipeSuccess(t, pipeStr)
|
||||
}
|
||||
|
||||
f(`filter *`)
|
||||
f(`filter foo bar`)
|
||||
f(`filter a:b or c:d in(x,y) z:>343`)
|
||||
}
|
||||
|
||||
func TestParsePipeFilterFailure(t *testing.T) {
|
||||
f := func(pipeStr string) {
|
||||
t.Helper()
|
||||
expectParsePipeFailure(t, pipeStr)
|
||||
}
|
||||
|
||||
f(`filter`)
|
||||
f(`filter |`)
|
||||
f(`filter ()`)
|
||||
}
|
||||
|
||||
func TestPipeFilter(t *testing.T) {
|
||||
f := func(pipeStr string, rows, rowsExpected [][]Field) {
|
||||
t.Helper()
|
||||
expectPipeResults(t, pipeStr, rows, rowsExpected)
|
||||
}
|
||||
|
||||
// filter mismatch
|
||||
f("filter abc", [][]Field{
|
||||
{
|
||||
{"_msg", `{"foo":"bar"}`},
|
||||
{"a", `test`},
|
||||
},
|
||||
}, [][]Field{})
|
||||
|
||||
// filter match
|
||||
f("filter _msg:foo", [][]Field{
|
||||
{
|
||||
{"_msg", `{"foo":"bar"}`},
|
||||
{"a", `test`},
|
||||
},
|
||||
}, [][]Field{
|
||||
{
|
||||
{"_msg", `{"foo":"bar"}`},
|
||||
{"a", `test`},
|
||||
},
|
||||
})
|
||||
|
||||
// multiple rows
|
||||
f("filter x:foo y:bar", [][]Field{
|
||||
{
|
||||
{"a", "f1"},
|
||||
{"x", "foo"},
|
||||
{"y", "bar"},
|
||||
},
|
||||
{
|
||||
{"a", "f2"},
|
||||
{"x", "x foo bar"},
|
||||
{"y", "aa bar bbb"},
|
||||
{"z", "iwert"},
|
||||
},
|
||||
{
|
||||
{"a", "f3"},
|
||||
{"x", "x fo bar"},
|
||||
{"y", "aa bar bbb"},
|
||||
{"z", "it"},
|
||||
},
|
||||
{
|
||||
{"a", "f4"},
|
||||
{"x", "x foo bar"},
|
||||
{"y", "aa ba bbb"},
|
||||
{"z", "t"},
|
||||
},
|
||||
{
|
||||
{"x", "x foo"},
|
||||
{"y", "aa bar"},
|
||||
},
|
||||
}, [][]Field{
|
||||
{
|
||||
{"a", "f1"},
|
||||
{"x", "foo"},
|
||||
{"y", "bar"},
|
||||
},
|
||||
{
|
||||
{"a", "f2"},
|
||||
{"x", "x foo bar"},
|
||||
{"y", "aa bar bbb"},
|
||||
{"z", "iwert"},
|
||||
},
|
||||
{
|
||||
{"x", "x foo"},
|
||||
{"y", "aa bar"},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestPipeFilterUpdateNeededFields(t *testing.T) {
|
||||
f := func(s string, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) {
|
||||
t.Helper()
|
||||
|
|
Loading…
Reference in a new issue