-
Notifications
You must be signed in to change notification settings - Fork 18
/
err_panic_test.go
54 lines (42 loc) · 1.21 KB
/
err_panic_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
package floc
import (
"fmt"
"testing"
)
type Str string
func (s Str) String() string {
return string(s)
}
func TestErrPanic_DataError(t *testing.T) {
tpl := "ERROR"
msg := fmt.Sprintf("%s%s", errorPrefix, tpl)
err := NewErrPanic(fmt.Errorf(tpl))
if err.Error() != msg {
t.Fatalf("%s expects error to be %s but has %s", t.Name(), msg, err.Error())
}
if data, ok := err.Data().(error); !ok {
t.Fatalf("%s expects data to be of type error but has %T", t.Name(), data)
}
}
func TestErrPanic_DataStringer(t *testing.T) {
tpl := "STRING"
msg := fmt.Sprintf("%s%s", errorPrefix, tpl)
err := NewErrPanic(Str(tpl))
if err.Error() != msg {
t.Fatalf("%s expects error to be %s but has %s", t.Name(), msg, err.Error())
}
if data, ok := err.Data().(fmt.Stringer); !ok {
t.Fatalf("%s expects data to be of type error but has %T", t.Name(), data)
}
}
func TestErrPanic_DataOther(t *testing.T) {
var tpl int = 42
msg := fmt.Sprintf("%s%d", errorPrefix, tpl)
err := NewErrPanic(tpl)
if err.Error() != msg {
t.Fatalf("%s expects error to be %s but has %s", t.Name(), msg, err.Error())
}
if data, ok := err.Data().(int); !ok {
t.Fatalf("%s expects data to be of type error but has %T", t.Name(), data)
}
}