-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
67 lines (48 loc) · 1.51 KB
/
errors_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
package csv
import (
"testing"
)
func TestError_Error(t *testing.T) {
t.Parallel()
t.Run("should return the localized error message", func(t *testing.T) {
t.Parallel()
err := NewError(helperLocalizer(t), ErrStructSlicePointerID, "subMessage")
got := err.Error()
want := "value is not a pointer to a struct slice: subMessage"
if got != want {
t.Errorf("Error() = %v, want %v", got, want)
}
})
t.Run("should return the localized error message without subMessage", func(t *testing.T) {
t.Parallel()
err := NewError(helperLocalizer(t), ErrStructSlicePointerID, "")
got := err.Error()
want := "value is not a pointer to a struct slice"
if got != want {
t.Errorf("Error() = %v, want %v", got, want)
}
})
}
func TestError_Is(t *testing.T) {
t.Parallel()
t.Run("should return true if the target error is the same as the error", func(t *testing.T) {
t.Parallel()
err := NewError(helperLocalizer(t), ErrStructSlicePointerID, "subMessage")
target := NewError(helperLocalizer(t), ErrStructSlicePointerID, "subMessage")
got := err.Is(target)
want := true
if got != want {
t.Errorf("Is() = %v, want %v", got, want)
}
})
t.Run("should return false if the target error is not the same as the error", func(t *testing.T) {
t.Parallel()
err := NewError(helperLocalizer(t), ErrStructSlicePointerID, "subMessage")
target := NewError(helperLocalizer(t), ErrEqualID, "")
got := err.Is(target)
want := false
if got != want {
t.Errorf("Is() = %v, want %v", got, want)
}
})
}