-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin_test.go
More file actions
67 lines (54 loc) · 1.42 KB
/
join_test.go
File metadata and controls
67 lines (54 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package errors_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/frederik-jatzkowski/errors"
)
func TestJoin(t *testing.T) {
var (
Err1 = errors.Errorf("error 1")
Err2 = errors.New("error 2")
)
err := errors.Join(Err1, Err2)
result := fmt.Sprintf("%+v", err)
assert.Contains(t, result, "error 1")
assert.Contains(t, result, "error 2")
assert.ErrorIs(t, err, Err1)
assert.ErrorIs(t, err, Err2)
assert.ErrorIs(t, err, err)
assert.False(t, errors.Is(err, ErrSentinel))
}
func TestJoinError(t *testing.T) {
err1 := errors.New("first")
err2 := errors.New("second")
joined := errors.Join(err1, err2)
errorMsg := joined.Error()
assert.NotEmpty(t, errorMsg)
}
func TestJoinNilErrors(t *testing.T) {
err1 := errors.New("valid error")
joined := errors.Join(nil, err1, nil)
assert.ErrorIs(t, joined, err1)
assert.NotNil(t, joined)
}
func TestJoinAllNil(t *testing.T) {
result := errors.Join(nil, nil, nil)
assert.Nil(t, result)
}
func TestJoinSingle(t *testing.T) {
err := errors.New("single")
joined := errors.Join(err)
assert.ErrorIs(t, joined, err)
}
func TestJoinUnwrap(t *testing.T) {
err1 := errors.New("first")
err2 := errors.New("second")
joined := errors.Join(err1, err2)
if unwrapper, ok := joined.(interface{ Unwrap() []error }); ok {
unwrapped := unwrapper.Unwrap()
assert.Len(t, unwrapped, 2)
assert.Contains(t, unwrapped, err1)
assert.Contains(t, unwrapped, err2)
}
}