mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 09:41:44 +08:00
28 lines
494 B
Go
28 lines
494 B
Go
|
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())
|
||
|
}
|