-
Notifications
You must be signed in to change notification settings - Fork 0
/
destructor_test.go
58 lines (52 loc) · 1003 Bytes
/
destructor_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
package kdone
import (
"testing"
"github.com/go-kata/kerror"
)
func TestDestructorFunc(t *testing.T) {
var c int
if err := DestructorFunc(func() error {
c--
return nil
}).Destroy(); err != nil {
t.Logf("%+v", err)
t.Fail()
return
}
if c != -1 {
t.Fail()
return
}
}
func TestDestructorFunc_Destroy__Error(t *testing.T) {
err := DestructorFunc(func() error {
return kerror.New(nil, "test error")
}).Destroy()
t.Logf("%+v", err)
if err == nil {
t.Fail()
return
}
}
func TestDestructorFunc_MustDestroy__Error(t *testing.T) {
const class = kerror.Label("test.Error")
const message = "test error"
err := kerror.Try(func() error {
DestructorFunc(func() error {
return kerror.New(class, message)
}).MustDestroy()
return nil
})
t.Logf("%+v", err)
if kerror.ClassOf(err) != class || kerror.MessageOf(err) != message {
t.Fail()
return
}
}
func TestNoop(t *testing.T) {
if err := Noop.Destroy(); err != nil {
t.Logf("%+v", err)
t.Fail()
return
}
}