Generalize test case

This commit is contained in:
Paul Seiffert 2017-07-12 17:29:56 +02:00
parent 4c4851c96a
commit 5f89343f84
No known key found for this signature in database
GPG Key ID: C9F76DC911D6EA29
1 changed files with 15 additions and 4 deletions

View File

@ -84,13 +84,24 @@ func TestEscaping_DefaultQuoteCharacter(t *testing.T) {
} }
} }
func TestEscaping_Time(t *testing.T) { func TestEscaping_Interface(t *testing.T) {
tf := &TextFormatter{DisableColors: true} tf := &TextFormatter{DisableColors: true}
ts := time.Now() ts := time.Now()
b, _ := tf.Format(WithField("test", ts)) testCases := []struct {
if !bytes.Contains(b, []byte(fmt.Sprintf("\"%s\"", ts.Format("2006-01-02 15:04:05.999999999 -0700 MST")))) { value interface{}
t.Errorf("escaping expected for %q (result was %q)", ts, string(b)) expected string
}{
{ts, fmt.Sprintf("\"%s\"", ts.String())},
{errors.New("error: something went wrong"), "\"error: something went wrong\""},
}
for _, tc := range testCases {
b, _ := tf.Format(WithField("test", tc.value))
if !bytes.Contains(b, []byte(tc.expected)) {
t.Errorf("escaping expected for %q (result was %q instead of %q)", tc.value, string(b), tc.expected)
}
} }
} }