Files
logrus/text_formatter_test.go
T
Giovanni Bajo a3ef049df9 Avoid extra quotes where not strictly necessary.
It's not necessary to enclose in quotes every single string value
in log2met format; when using basic words, it's possible to not
quote it (as heroku does for its own logging). This keeps the
logs easier on the human eye.
2014-12-15 20:20:33 +01:00

34 lines
699 B
Go

package logrus
import (
"bytes"
"errors"
"testing"
)
func TestQuoting(t *testing.T) {
tf := new(TextFormatter)
checkQuoting := func(q bool, value interface{}) {
b, _ := tf.Format(WithField("test", value))
idx := bytes.LastIndex(b, []byte{'='})
cont := bytes.Contains(b[idx:], []byte{'"'})
if cont != q {
if q {
t.Errorf("quoting expected for: %#v", value)
} else {
t.Errorf("quoting not expected for: %#v", value)
}
}
}
checkQuoting(false, "abcd")
checkQuoting(false, "v1.0")
checkQuoting(true, "/foobar")
checkQuoting(true, "x y")
checkQuoting(true, "x,y")
checkQuoting(false, errors.New("invalid"))
checkQuoting(true, errors.New("invalid argument"))
}