2024-05-22 21:01:20 +02: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-06-04 00:59:25 +02:00
|
|
|
result := MarshalFieldsToJSON(nil, p.fields)
|
2024-05-22 21:01:20 +02:00
|
|
|
if string(result) != resultExpected {
|
|
|
|
t.Fatalf("unexpected result when parsing [%s]; got\n%s\nwant\n%s\n", s, result, resultExpected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f(``, `{}`)
|
|
|
|
f(`foo=bar`, `{"foo":"bar"}`)
|
|
|
|
f(`foo="bar=baz x=y"`, `{"foo":"bar=baz x=y"}`)
|
|
|
|
f(`foo=`, `{"foo":""}`)
|
2024-06-04 00:59:25 +02:00
|
|
|
f(`foo`, `{"foo":""}`)
|
|
|
|
f(`foo bar`, `{"foo":"","bar":""}`)
|
|
|
|
f(`foo bar=baz`, `{"foo":"","bar":"baz"}`)
|
2024-05-22 21:01:20 +02:00
|
|
|
f(`foo=bar baz="x y" a=b`, `{"foo":"bar","baz":"x y","a":"b"}`)
|
2024-06-17 12:13:18 +02:00
|
|
|
f(` foo=bar baz=x =z qwe`, `{"foo":"bar","baz":"x","_msg":"z","qwe":""}`)
|
2024-05-22 21:01:20 +02:00
|
|
|
}
|