generated from origadmin/.github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
56 lines (45 loc) · 1.25 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
package dl
import (
"errors"
"testing"
)
func TestInvalidTypeError(t *testing.T) {
err := InvalidTypeError("string")
if err == nil {
t.Error("InvalidTypeError should not return nil")
}
var e *invalidTypeErr
if !errors.As(err, &e) {
t.Error("InvalidTypeError should return an *invalidTypeErr")
}
if e.typeString != "string" {
t.Errorf("InvalidTypeError should set typeString to the correct value, got %s", e.typeString)
}
}
func TestInvalidErr_Error(t *testing.T) {
err := &invalidTypeErr{typeString: "string"}
if err.Error() != "invalid type string" {
t.Errorf("invalidTypeErr.Error should return the correct string, got %s", err.Error())
}
}
func TestInvalidErr_Is(t *testing.T) {
err1 := &invalidTypeErr{typeString: "string"}
err2 := &invalidTypeErr{typeString: "int"}
if !err1.Is(err2) {
t.Error("err1.Is(err2) should return true")
}
err3 := &invalidTypeErr{typeString: "string"}
if !err1.Is(err3) {
t.Error("err1.Is(err3) should return true")
}
if err1.Is(nil) {
t.Error("err1.Is(nil) should return false")
}
}
func TestError_Is(t *testing.T) {
err1 := &invalidTypeErr{typeString: "string"}
err2 := &invalidTypeErr{typeString: "int"}
if !errors.Is(err1, err2) {
t.Error("errors.Is(err1, err2) should return true")
}
}