2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-09 22:15:35 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-04-18 10:04:42 +01:00
|
|
|
package errs2_test
|
2018-10-18 17:55:00 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
2019-11-14 19:46:15 +00:00
|
|
|
"storj.io/storj/private/errs2"
|
2018-10-18 17:55:00 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCollectSingleError(t *testing.T) {
|
|
|
|
errchan := make(chan error)
|
|
|
|
defer close(errchan)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
errchan <- errs.New("error")
|
|
|
|
}()
|
|
|
|
|
2019-04-18 10:04:42 +01:00
|
|
|
err := errs2.Collect(errchan, 1*time.Second)
|
2018-10-18 17:55:00 +01:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Equal(t, err.Error(), "error")
|
|
|
|
}
|
|
|
|
|
2019-04-18 10:04:42 +01:00
|
|
|
func TestCollectMultipleError(t *testing.T) {
|
2018-10-18 17:55:00 +01:00
|
|
|
errchan := make(chan error)
|
|
|
|
defer close(errchan)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
errchan <- errs.New("error1")
|
|
|
|
errchan <- errs.New("error2")
|
|
|
|
errchan <- errs.New("error3")
|
|
|
|
}()
|
|
|
|
|
2019-04-18 10:04:42 +01:00
|
|
|
err := errs2.Collect(errchan, 1*time.Second)
|
2018-10-18 17:55:00 +01:00
|
|
|
assert.Error(t, err)
|
2019-02-06 16:40:55 +00:00
|
|
|
assert.Equal(t, err.Error(), "error1; error2; error3")
|
2018-10-18 17:55:00 +01:00
|
|
|
}
|