aboutsummaryrefslogtreecommitdiff
path: root/assert/errequal_test.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-06-27 23:09:47 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-06-27 23:09:47 +0200
commit62132b9680cbd8cbe6e50a346cc71922812dac00 (patch)
tree6e06a1beee0f088f3834a1db6651b004e00a67e6 /assert/errequal_test.go
parent8e9889d3e5b2874854832d1d882d124132546f49 (diff)
downloadgo-gg-62132b9680cbd8cbe6e50a346cc71922812dac00.tar.gz
add func assert.ErrsEqual
Diffstat (limited to 'assert/errequal_test.go')
-rw-r--r--assert/errequal_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/assert/errequal_test.go b/assert/errequal_test.go
index 4bb9080..b97342a 100644
--- a/assert/errequal_test.go
+++ b/assert/errequal_test.go
@@ -89,3 +89,27 @@ type structTypedError struct {
func (e structTypedError) Error() string {
return e.Message
}
+
+func TestErrsEqual(t *testing.T) {
+ // NOTE: ErrsEqual() uses the same basic machinery as ErrEqual(), so we're not comparing all types here.
+ // We just need to check the machinery of iterating over `actual` and `expected` and dealing with slice length mismatches.
+
+ errs := []error{
+ errors.New("first error"),
+ errors.New("second error"),
+ }
+
+ assert.ErrsEqual(t, errs, []string{"first error", "second error"})
+ expectErrors(t, func(t assert.TestingTB) {
+ assert.ErrsEqual(t, errs, []string{"second error", "first error"})
+ }, `
+ in actual[0]: expected "second error", but got "first error"
+ in actual[1]: expected "first error", but got "second error"
+ `)
+ expectErrors(t, func(t assert.TestingTB) {
+ assert.ErrsEqual(t, errs, []string{"first error"})
+ }, `in actual[1]: expected <missing>, but got "second error"`)
+ expectErrors(t, func(t assert.TestingTB) {
+ assert.ErrsEqual(t, errs, []string{"first error", "second error", "third error"})
+ }, `in actual[2]: expected "third error", but got <missing>`)
+}