-
-
Notifications
You must be signed in to change notification settings - Fork 511
/
testing_test.go
86 lines (79 loc) · 1.83 KB
/
testing_test.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package testcontainers
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func ExampleSkipIfProviderIsNotHealthy() {
SkipIfProviderIsNotHealthy(&testing.T{})
}
type notFoundError struct{}
func (notFoundError) NotFound() {}
func (notFoundError) Error() string {
return "not found"
}
func Test_isNotFound(t *testing.T) {
tests := map[string]struct {
err error
want bool
}{
"nil": {
err: nil,
want: true,
},
"join-nils": {
err: errors.Join(nil, nil),
want: true,
},
"join-nil-not-found": {
err: errors.Join(nil, notFoundError{}),
want: true,
},
"not-found": {
err: notFoundError{},
want: true,
},
"other": {
err: errors.New("other"),
want: false,
},
"join-other": {
err: errors.Join(nil, notFoundError{}, errors.New("other")),
want: false,
},
"warp": {
err: fmt.Errorf("wrap: %w", notFoundError{}),
want: true,
},
"multi-warp": {
err: fmt.Errorf("wrap: %w", fmt.Errorf("wrap: %w", notFoundError{})),
want: true,
},
"multi-warp-other": {
err: fmt.Errorf("wrap: %w", fmt.Errorf("wrap: %w", errors.New("other"))),
want: false,
},
"multi-warp-other-not-found": {
err: fmt.Errorf("wrap: %w", fmt.Errorf("wrap: %w %w", errors.New("other"), notFoundError{})),
want: false,
},
"multi-warp-not-found-nil": {
err: fmt.Errorf("wrap: %w", fmt.Errorf("wrap: %w %w", nil, notFoundError{})),
want: true,
},
"multi-join-not-found-other": {
err: errors.Join(nil, fmt.Errorf("wrap: %w", errors.Join(notFoundError{}, errors.New("other")))),
want: false,
},
"multi-join-not-found-nil": {
err: errors.Join(nil, fmt.Errorf("wrap: %w", errors.Join(notFoundError{}, nil))),
want: true,
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
require.Equal(t, tc.want, isCleanupSafe(tc.err))
})
}
}