-
Notifications
You must be signed in to change notification settings - Fork 2
/
errors_test.go
70 lines (63 loc) · 1.23 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
68
69
70
package tcp_test
import (
"errors"
"strconv"
"testing"
"github.com/matryer/is"
"github.com/rvflash/tcp"
)
const (
hiWorld = "hello world"
prefix = "tcp: "
)
func TestNewError(t *testing.T) {
var (
dt = []struct {
in string
err error
out string
}{
{out: prefix},
{in: "hi!", out: prefix + "hi!"},
{in: "hello", err: errors.New("world"), out: prefix + "hello: world"},
}
are = is.New(t)
err error
)
for i, tt := range dt {
tt := tt
t.Run("#"+strconv.Itoa(i), func(t *testing.T) {
err = tcp.NewError(tt.in, tt.err)
are.Equal(err.Error(), tt.out)
})
}
}
func TestError_Recovered(t *testing.T) {
e := &tcp.Error{}
is.New(t).True(!e.Recovered())
}
func TestErrors_Error(t *testing.T) {
var err tcp.Errors
err = append(err, errors.New(hiWorld))
err = append(err, tcp.NewError(hiWorld))
are := is.New(t)
are.Equal(err.Error(), hiWorld+", "+prefix+hiWorld)
}
func TestErrors_Recovered(t *testing.T) {
var (
dt = []struct {
err tcp.Errors
ok bool
}{
{err: tcp.Errors{}},
{err: tcp.Errors{tcp.NewError(hiWorld)}, ok: true},
}
are = is.New(t)
)
for i, tt := range dt {
tt := tt
t.Run("#"+strconv.Itoa(i), func(t *testing.T) {
are.Equal(tt.err.Recovered(), tt.ok)
})
}
}