-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherrors_test.go
More file actions
48 lines (44 loc) · 870 Bytes
/
errors_test.go
File metadata and controls
48 lines (44 loc) · 870 Bytes
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
package authenticator
import (
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestErrors_RetrieveDomainErrorCode(t *testing.T) {
tt := []struct {
name string
code ErrCode
err error
}{
{
name: "Typed error",
code: EInvalidCode,
err: ErrInvalidCode("invalid code"),
},
{
name: "stdlib error",
code: EInternal,
err: fmt.Errorf("whoops"),
},
{
name: "Wrapped error",
code: EBadRequest,
err: fmt.Errorf("whoops: %w", ErrBadRequest("bad request")),
},
{
name: "Multi layered error",
code: EInvalidToken,
err: fmt.Errorf("whoops: %w",
fmt.Errorf("wrapped: %w", ErrInvalidToken("bad token")),
),
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
code := ErrorCode(tc.err)
if code != tc.code {
t.Error("code does not match", cmp.Diff(code, tc.code))
}
})
}
}