2023-05-16 16:01:50 +00:00
|
|
|
package errs
|
|
|
|
|
|
|
|
import (
|
2025-01-07 10:49:23 +00:00
|
|
|
"errors"
|
2023-05-16 16:01:50 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFromManyErrors(t *testing.T) {
|
2025-01-07 10:49:23 +00:00
|
|
|
e1 := errors.New("Error 1")
|
|
|
|
e2 := errors.New("Error 2")
|
|
|
|
e3 := errors.New("Error 3")
|
2023-05-16 16:01:50 +00:00
|
|
|
err := FromMany(e1, e2, e3)
|
|
|
|
|
2025-01-02 11:03:41 +00:00
|
|
|
assert.ErrorIs(t, err, e1)
|
|
|
|
assert.ErrorIs(t, err, e2)
|
|
|
|
assert.ErrorIs(t, err, e3)
|
2023-05-16 16:01:50 +00:00
|
|
|
|
2025-01-02 11:03:41 +00:00
|
|
|
assert.Equal(t, `Error 1
|
2023-05-16 16:01:50 +00:00
|
|
|
Error 2
|
2025-01-02 11:03:41 +00:00
|
|
|
Error 3`, err.Error())
|
2023-05-16 16:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFromManyErrorsWihtNil(t *testing.T) {
|
2025-01-07 10:49:23 +00:00
|
|
|
e1 := errors.New("Error 1")
|
2023-05-16 16:01:50 +00:00
|
|
|
var e2 error = nil
|
2025-01-07 10:49:23 +00:00
|
|
|
e3 := errors.New("Error 3")
|
2023-05-16 16:01:50 +00:00
|
|
|
err := FromMany(e1, e2, e3)
|
|
|
|
|
2025-01-02 11:03:41 +00:00
|
|
|
assert.ErrorIs(t, err, e1)
|
|
|
|
assert.ErrorIs(t, err, e3)
|
2023-05-16 16:01:50 +00:00
|
|
|
|
2025-01-02 11:03:41 +00:00
|
|
|
assert.Equal(t, `Error 1
|
|
|
|
Error 3`, err.Error())
|
2023-05-16 16:01:50 +00:00
|
|
|
}
|