-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry_test.go
77 lines (62 loc) · 1.35 KB
/
registry_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
71
72
73
74
75
76
77
package sigmon
import (
"reflect"
"testing"
)
func TestRegistry(t *testing.T) {
t.Run("LoadBufferBuffer", tRegistryLoadBufferBuffer)
t.Run("SetGet", tRegistrySetGet)
}
func tRegistryLoadBufferBuffer(t *testing.T) {
r := newRegistry(nil)
f := func(*State) {}
r.loadBuffer(nil)
r.loadBuffer(f)
select {
case fn := <-r.buffer():
got := reflect.ValueOf(fn).Pointer()
want := reflect.ValueOf(f).Pointer()
if got != want {
t.Fatalf("got %v, want %v", got, want)
}
default:
t.Fatalf("should not block")
}
r.loadBuffer(nil)
select {
case fn := <-r.buffer():
got := reflect.ValueOf(fn).Pointer()
notWant := reflect.ValueOf(f).Pointer()
if got == notWant {
t.Fatalf("handlerfunc not replaced")
}
if got == 0x0 {
t.Fatalf("handlerfunc should not be nil")
}
default:
t.Fatalf("should not block")
}
}
func tRegistrySetGet(t *testing.T) {
r := newRegistry(nil)
f := func(*State) {}
if r.get() == nil {
t.Fatalf("got nil, want empty func")
}
r.set(nil)
r.set(f)
got := reflect.ValueOf(r.get()).Pointer()
want := reflect.ValueOf(f).Pointer()
if got != want {
t.Fatalf("got %v, want %v", got, want)
}
r.set(nil)
got = reflect.ValueOf(r.get()).Pointer()
notWant := reflect.ValueOf(f).Pointer()
if got == notWant {
t.Fatalf("handlerfunc not replaced")
}
if got == 0x0 {
t.Fatalf("handlerfunc should not be nil")
}
}