mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
errcount: factor errcount abstraction from operations
This commit is contained in:
27
lib/errcount/errcount_test.go
Normal file
27
lib/errcount/errcount_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package errcount
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestErrCount(t *testing.T) {
|
||||
ec := New()
|
||||
assert.Equal(t, nil, ec.Err("none"))
|
||||
|
||||
e1 := errors.New("one")
|
||||
ec.Add(e1)
|
||||
|
||||
err := ec.Err("stuff")
|
||||
assert.True(t, errors.Is(err, e1), err)
|
||||
assert.Equal(t, "stuff: one", err.Error())
|
||||
|
||||
e2 := errors.New("two")
|
||||
ec.Add(e2)
|
||||
|
||||
err = ec.Err("stuff")
|
||||
assert.True(t, errors.Is(err, e2), err)
|
||||
assert.Equal(t, "stuff: 2 errors: last error: two", err.Error())
|
||||
}
|
||||
Reference in New Issue
Block a user