From ad48e464a0a996093b631791187840927a1516e1 Mon Sep 17 00:00:00 2001 From: "Alan D. Cabrera" Date: Fri, 15 Jan 2021 07:02:35 -0800 Subject: [PATCH] Fix ExpectedExec Stringer implementation Sometimes the result is incorrectly set, so the cast that takes place in the String() method returns nil. --- expectations.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/expectations.go b/expectations.go index 5c82c7b..5adf608 100644 --- a/expectations.go +++ b/expectations.go @@ -230,12 +230,13 @@ func (e *ExpectedExec) String() string { } if e.result != nil { - res, _ := e.result.(*result) - msg += "\n - should return Result having:" - msg += fmt.Sprintf("\n LastInsertId: %d", res.insertID) - msg += fmt.Sprintf("\n RowsAffected: %d", res.rowsAffected) - if res.err != nil { - msg += fmt.Sprintf("\n Error: %s", res.err) + if res, ok := e.result.(*result); ok { + msg += "\n - should return Result having:" + msg += fmt.Sprintf("\n LastInsertId: %d", res.insertID) + msg += fmt.Sprintf("\n RowsAffected: %d", res.rowsAffected) + if res.err != nil { + msg += fmt.Sprintf("\n Error: %s", res.err) + } } }