@@ -12,8 +12,8 @@ import (
12
12
"github.com/casbin/casbin/v2"
13
13
)
14
14
15
- func initWatcher (t * testing.T ) (* casbin.Enforcer , * Watcher ) {
16
- w , err := NewWatcher ("127.0.0.1:6379" , WatcherOptions {} )
15
+ func initWatcherWithOptions (t * testing.T , wo WatcherOptions ) (* casbin.Enforcer , * Watcher ) {
16
+ w , err := NewWatcher ("127.0.0.1:6379" , wo )
17
17
if err != nil {
18
18
t .Fatalf ("Failed to connect to Redis: %v" , err )
19
19
}
@@ -25,6 +25,11 @@ func initWatcher(t *testing.T) (*casbin.Enforcer, *Watcher) {
25
25
_ = e .SetWatcher (w )
26
26
return e , w .(* Watcher )
27
27
}
28
+
29
+ func initWatcher (t * testing.T ) (* casbin.Enforcer , * Watcher ) {
30
+ return initWatcherWithOptions (t , WatcherOptions {})
31
+ }
32
+
28
33
func TestWatcher (t * testing.T ) {
29
34
_ , w := initWatcher (t )
30
35
_ = w .SetUpdateCallback (func (s string ) {
@@ -35,6 +40,19 @@ func TestWatcher(t *testing.T) {
35
40
time .Sleep (time .Millisecond * 500 )
36
41
}
37
42
43
+ func TestWatcherWithIgnoreSelfTrue (t * testing.T ) {
44
+ wo := WatcherOptions {
45
+ IgnoreSelf : true ,
46
+ OptionalUpdateCallback : func (s string ) {
47
+ t .Fatalf ("This callback should not be called when IgnoreSelf is set true." )
48
+ },
49
+ }
50
+ _ , w := initWatcherWithOptions (t , wo )
51
+ _ = w .Update ()
52
+ w .Close ()
53
+ time .Sleep (time .Millisecond * 500 )
54
+ }
55
+
38
56
func TestUpdate (t * testing.T ) {
39
57
_ , w := initWatcher (t )
40
58
_ = w .SetUpdateCallback (func (s string ) {
0 commit comments