2018-11-09 22:15:35 +00:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-10-18 17:55:00 +01:00
|
|
|
package utils_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCollectSingleError(t *testing.T) {
|
|
|
|
errchan := make(chan error)
|
|
|
|
defer close(errchan)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
errchan <- errs.New("error")
|
|
|
|
}()
|
|
|
|
|
|
|
|
err := utils.CollectErrors(errchan, 1*time.Second)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Equal(t, err.Error(), "error")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollecMultipleError(t *testing.T) {
|
|
|
|
errchan := make(chan error)
|
|
|
|
defer close(errchan)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
errchan <- errs.New("error1")
|
|
|
|
errchan <- errs.New("error2")
|
|
|
|
errchan <- errs.New("error3")
|
|
|
|
}()
|
|
|
|
|
|
|
|
err := utils.CollectErrors(errchan, 1*time.Second)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Equal(t, err.Error(), "error1\nerror2\nerror3")
|
|
|
|
}
|