You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I notice I keep running into this, so let me open an issue;
When writing table-tests, I usually combine "happy" and "unhappy" tests, which means that for some tests, I'd be checking for an error, and for the happy tests, check that no error occurs.
I'd like to get rid of the if test.errString != "" { in these tests;
Initially thought; let's use assert.Error(t, err, test.errString), which fails, because a nil error is not the same as an empty error-string. Using assert.ErrorContains(t, err, test.errString) has the same issue, because "" must be included in the error (which isn't the case if there's no error at all)
Wondering if there's a better approach, or if a new utility should be added that accepts "empty error string" as "no error is produced".
write success cases in a separate table from error cases; or
use an if in the test body, similar to what you have illustrated above, except I will generally return after assert because the test is in a t.Run(); or
I notice I keep running into this, so let me open an issue;
When writing table-tests, I usually combine "happy" and "unhappy" tests, which means that for some tests, I'd be checking for an error, and for the happy tests, check that no error occurs.
For example;
I'd like to get rid of the
if test.errString != "" {
in these tests;Initially thought; let's use
assert.Error(t, err, test.errString)
, which fails, because anil
error is not the same as an empty error-string. Usingassert.ErrorContains(t, err, test.errString)
has the same issue, because""
must be included in the error (which isn't the case if there's no error at all)Wondering if there's a better approach, or if a new utility should be added that accepts "empty error string" as "no error is produced".
@vdemeester @dnephin
The text was updated successfully, but these errors were encountered: