From d7eb0304331576fddf8ffbe9d26bf5d8a1c328d9 Mon Sep 17 00:00:00 2001 From: "Ariel Shaqed (Scolnicov)" Date: Tue, 13 Oct 2020 17:14:34 +0300 Subject: [PATCH] [CR] improve and refine error reporting in tests --- parade/parade_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/parade/parade_test.go b/parade/parade_test.go index 761b085f535..bac49f62f8e 100644 --- a/parade/parade_test.go +++ b/parade/parade_test.go @@ -137,7 +137,7 @@ func scanIDs(t *testing.T, prefix string) []parade.TaskID { t.Helper() rows, err := db.Query(`SELECT id FROM tasks WHERE id LIKE format('%s%%', $1::text)`, prefix) if err != nil { - t.Errorf("[I] select remaining IDs for prefix %s: %s", prefix, err) + t.Fatalf("[I] select remaining IDs for prefix %s: %s", prefix, err) } defer func() { @@ -153,6 +153,9 @@ func scanIDs(t *testing.T, prefix string) []parade.TaskID { } gotIDs = append(gotIDs, id) } + if err = rows.Err(); err != nil { + t.Fatalf("[I] scan rows: %s", err) + } return gotIDs } @@ -252,14 +255,12 @@ func TestTaskStatusCodeValueScan(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { var dst parade.TaskStatusCodeValue - if err := dst.Scan(c.in); err != nil { - if !errors.Is(err, c.err) { - t.Errorf("got err %v, expected %v", err, c.err) - } - } else { - if dst != c.out { - t.Errorf("expected %s, got %s", c.out, dst) - } + err := dst.Scan(c.in) + if !errors.Is(err, c.err) { + t.Errorf("got err %v, expected %v", err, c.err) + } + if err == nil && dst != c.out { + t.Errorf("expected %s, got %s", c.out, dst) } }) }