2024-05-22 19:01:20 +00:00
|
|
|
package logstorage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLogfmtParser(t *testing.T) {
|
|
|
|
f := func(s, resultExpected string) {
|
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
p := getLogfmtParser()
|
|
|
|
defer putLogfmtParser(p)
|
|
|
|
|
|
|
|
p.parse(s)
|
2024-10-14 21:39:29 +00:00
|
|
|
result := MarshalFieldsToLogfmt(nil, p.fields)
|
2024-05-22 19:01:20 +00:00
|
|
|
if string(result) != resultExpected {
|
|
|
|
t.Fatalf("unexpected result when parsing [%s]; got\n%s\nwant\n%s\n", s, result, resultExpected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-14 21:39:29 +00:00
|
|
|
f(``, ``)
|
|
|
|
f(`foo=bar`, `foo=bar`)
|
|
|
|
f(`foo="bar=baz x=y"`, `foo="bar=baz x=y"`)
|
|
|
|
f(`foo=`, `foo=`)
|
|
|
|
f(`foo`, `foo=`)
|
|
|
|
f(`foo bar`, `foo= bar=`)
|
|
|
|
f(`foo bar=baz`, `foo= bar=baz`)
|
|
|
|
f(`foo=bar baz="x y" a=b`, `foo=bar baz="x y" a=b`)
|
|
|
|
f(` foo=bar baz=x =z qwe`, `foo=bar baz=x _msg=z qwe=`)
|
2024-05-22 19:01:20 +00:00
|
|
|
}
|