moby/internal/multierror/multierror_test.go
Albin Kerouanton 64de635626
Add a temporary drop-in replacement for errors.Join
As we have a hard time figuring out what moby/moby#46099 should look
like, this drop-in replacement will solve the initial formatting problem
we have. It's made internal such that we can remove it whenever we want
and unlike moby/moby#46099 doesn't require thoughtful API changes.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-08-16 16:18:41 +02:00

25 lines
585 B
Go

package multierror
import (
"errors"
"fmt"
"testing"
"gotest.tools/v3/assert"
)
func TestErrorJoin(t *testing.T) {
t.Run("single", func(t *testing.T) {
err := Join(fmt.Errorf("invalid config: %w", Join(errors.New("foo"))))
const expected = `invalid config: foo`
assert.Equal(t, err.Error(), expected)
})
t.Run("multiple", func(t *testing.T) {
err := Join(errors.New("foobar"), fmt.Errorf("invalid config: \n%w", Join(errors.New("foo"), errors.New("bar"))))
const expected = `* foobar
* invalid config:
* foo
* bar`
assert.Equal(t, err.Error(), expected)
})
}