-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patherror_test.go
70 lines (58 loc) · 1.33 KB
/
error_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
package presence
import (
"errors"
"fmt"
"testing"
)
func TestErrorLen(t *testing.T) {
e := Error{}
id1 := <-nextID
id2 := <-nextID
err1 := errors.New(id1)
err2 := errors.New(id2)
e.Append(id1, err1)
e.Append(id2, err2)
if e.Len() != 2 {
t.Fatalf("err len should be 2, but got: %d", e.Len())
}
}
func TestErrorEach(t *testing.T) {
e := Error{}
id := <-nextID
err := errors.New(id)
e.Append(id, err)
e.Each(func(idx string, errx error) {
if idx != id {
t.Fatalf("error id should be: %s, but got: %s", id, idx)
}
if err.Error() != errx.Error() {
t.Fatalf("error message should be: %s, but got: %s", err.Error(), errx.Error())
}
})
}
func TestErrorString(t *testing.T) {
e := Error{}
id1 := <-nextID
id2 := <-nextID
err1 := errors.New(id1)
err2 := errors.New(id2)
e.Append(id1, err1)
e.Append(id2, err2)
errMessage := fmt.Sprintf("Presence Error:{id: %[1]s, err:%[1]s}{id: %[2]s, err:%[2]s}", id1, id2)
if e.Error() != errMessage {
t.Fatalf("err message should be \"%s\", but got: \"%s\"", errMessage, e.Error())
}
}
func TestErrorHas(t *testing.T) {
e := Error{}
id1 := <-nextID
id2 := <-nextID
err1 := errors.New(id1)
e.Append(id1, err1)
if !e.Has(id1) {
t.Fatalf("multi err should have %s, but it doesnt", id1)
}
if e.Has(id2) {
t.Fatalf("multi err should not have %s, but it does", id2)
}
}