-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_test.go
More file actions
45 lines (40 loc) · 1.31 KB
/
errors_test.go
File metadata and controls
45 lines (40 loc) · 1.31 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
package cleango
import (
"errors"
"fmt"
"testing"
)
func TestErrors(t *testing.T) {
e := ToDomainError("no wrap message", errors.New("not domain"))
var asDomain *DomainError
if !errors.As(e, &asDomain) {
t.Fatal("should have created new domain error")
}
if asDomain.UnderlyingCause == nil {
t.Fatal("underlying cause was not preserved")
}
if asDomain.UnderlyingCause.Error() != "not domain" {
t.Fatalf("unknown underlying cause %s", asDomain.UnderlyingCause)
}
if asDomain.Error() != "[system - converted error (not domain)]" {
t.Fatal("did not nest call stack properly", asDomain.Error())
}
de := ToDomainError(
"wrapping another domain",
&DomainError{
Kind: InvalidInput,
Message: "bad param {jimmy}",
})
if !errors.As(de, &asDomain) ||
!errors.Is(asDomain, errors.Unwrap(de)) {
t.Fatalf("unwrapped message did not match source")
}
}
func TestDeepIssues(t *testing.T) {
dbLikeErr := fmt.Errorf("failed to connect to data source")
wrapper1 := ToDomainError("converted to domain error", dbLikeErr)
useCaseErrWrapper := ToDomainError("wrapper at the use case level", wrapper1)
if useCaseErrWrapper.Error() != "wrapper at the use case level ([system - converted to domain error (failed to connect to data source)])" {
t.Fatal("message didn't wrap properly | ", useCaseErrWrapper.Error())
}
}