github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/lib/errcount/errcount_test.go (about)

     1  package errcount
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestErrCount(t *testing.T) {
    11  	ec := New()
    12  	assert.Equal(t, nil, ec.Err("none"))
    13  
    14  	e1 := errors.New("one")
    15  	ec.Add(e1)
    16  
    17  	err := ec.Err("stuff")
    18  	assert.True(t, errors.Is(err, e1), err)
    19  	assert.Equal(t, "stuff: one", err.Error())
    20  
    21  	e2 := errors.New("two")
    22  	ec.Add(e2)
    23  
    24  	err = ec.Err("stuff")
    25  	assert.True(t, errors.Is(err, e2), err)
    26  	assert.Equal(t, "stuff: 2 errors: last error: two", err.Error())
    27  }