From 5f89343f84f01bd781cfc680d045148ea0a6d178 Mon Sep 17 00:00:00 2001 From: Paul Seiffert Date: Wed, 12 Jul 2017 17:29:56 +0200 Subject: [PATCH] Generalize test case --- text_formatter_test.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/text_formatter_test.go b/text_formatter_test.go index 93f47b7..d7b3bcb 100644 --- a/text_formatter_test.go +++ b/text_formatter_test.go @@ -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} + ts := time.Now() - b, _ := tf.Format(WithField("test", ts)) - if !bytes.Contains(b, []byte(fmt.Sprintf("\"%s\"", ts.Format("2006-01-02 15:04:05.999999999 -0700 MST")))) { - t.Errorf("escaping expected for %q (result was %q)", ts, string(b)) + testCases := []struct { + value interface{} + 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) + } } }