-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
package logstorage
import (
"testing"
)
func TestLogfmtParser(t *testing.T) {
f := func(given, want string) {
t.Helper() // to get the test case's exact loc
p := getLogfmtParser()
defer putLogfmtParser(p)
p.parse(given)
got := MarshalFieldsToJSON(nil, p.fields)
if string(got) != want {
t.Errorf("MarshalFieldsToJSON [%s]:\ngot:%s\nwant:%s\n", given, got, want)
}
}
// f(given, want)
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":""}`)
}Reactions are currently unavailable