mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-06-05 01:52:47 +03:00
…9cbb1518e71fba36b This fixes tests failing https://github.com/VictoriaMetrics/VictoriaMetrics/actions/runs/12827319722/job/35769125733?pr=8073#step:5:197 ### Describe Your Changes Please provide a brief description of the changes you made. Be as specific as possible to help others understand the purpose and impact of your modifications. ### Checklist The following checks are **mandatory**: - [ ] My change adheres [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/contributing/). Signed-off-by: hagen1778 <roman@victoriametrics.com>
104 lines
2.2 KiB
Go
104 lines
2.2 KiB
Go
package logsql
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseExtraFilters_Success(t *testing.T) {
|
|
f := func(s, resultExpected string) {
|
|
t.Helper()
|
|
|
|
f, err := parseExtraFilters(s)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error in parseExtraFilters: %s", err)
|
|
}
|
|
result := f.String()
|
|
if result != resultExpected {
|
|
t.Fatalf("unexpected result\ngot\n%s\nwant\n%s", result, resultExpected)
|
|
}
|
|
}
|
|
|
|
f("", "")
|
|
|
|
// JSON string
|
|
f(`{"foo":"bar"}`, `foo:=bar`)
|
|
f(`{"foo":["bar","baz"]}`, `foo:in(bar,baz)`)
|
|
f(`{"z":"=b ","c":["d","e,"],"a":[],"_msg":"x"}`, `z:="=b " c:in(d,"e,") =x`)
|
|
|
|
// LogsQL filter
|
|
f(`foobar`, `foobar`)
|
|
f(`foo:bar`, `foo:bar`)
|
|
f(`foo:(bar or baz) error _time:5m {"foo"=bar,baz="z"}`, `{foo="bar",baz="z"} (foo:bar or foo:baz) error _time:5m`)
|
|
}
|
|
|
|
func TestParseExtraFilters_Failure(t *testing.T) {
|
|
f := func(s string) {
|
|
t.Helper()
|
|
|
|
_, err := parseExtraFilters(s)
|
|
if err == nil {
|
|
t.Fatalf("expecting non-nil error")
|
|
}
|
|
}
|
|
|
|
// Invalid JSON
|
|
f(`{"foo"}`)
|
|
f(`[1,2]`)
|
|
f(`{"foo":[1]}`)
|
|
|
|
// Invliad LogsQL filter
|
|
f(`foo:(bar`)
|
|
|
|
// excess pipe
|
|
f(`foo | count()`)
|
|
}
|
|
|
|
func TestParseExtraStreamFilters_Success(t *testing.T) {
|
|
f := func(s, resultExpected string) {
|
|
t.Helper()
|
|
|
|
f, err := parseExtraStreamFilters(s)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error in parseExtraStreamFilters: %s", err)
|
|
}
|
|
result := f.String()
|
|
if result != resultExpected {
|
|
t.Fatalf("unexpected result;\ngot\n%s\nwant\n%s", result, resultExpected)
|
|
}
|
|
}
|
|
|
|
f("", "")
|
|
|
|
// JSON string
|
|
f(`{"foo":"bar"}`, `{foo="bar"}`)
|
|
f(`{"foo":["bar","baz"]}`, `{foo=~"bar|baz"}`)
|
|
f(`{"z":"b","c":["d","e|\""],"a":[],"_msg":"x"}`, `{z="b",c=~"d|e\\|\"",_msg="x"}`)
|
|
|
|
// LogsQL filter
|
|
f(`foobar`, `foobar`)
|
|
f(`foo:bar`, `foo:bar`)
|
|
f(`foo:(bar or baz) error _time:5m {"foo"=bar,baz="z"}`, `{foo="bar",baz="z"} (foo:bar or foo:baz) error _time:5m`)
|
|
}
|
|
|
|
func TestParseExtraStreamFilters_Failure(t *testing.T) {
|
|
f := func(s string) {
|
|
t.Helper()
|
|
|
|
_, err := parseExtraStreamFilters(s)
|
|
if err == nil {
|
|
t.Fatalf("expecting non-nil error")
|
|
}
|
|
}
|
|
|
|
// Invalid JSON
|
|
f(`{"foo"}`)
|
|
f(`[1,2]`)
|
|
f(`{"foo":[1]}`)
|
|
|
|
// Invliad LogsQL filter
|
|
f(`foo:(bar`)
|
|
|
|
// excess pipe
|
|
f(`foo | count()`)
|
|
}
|