replace wrappers with hooks
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
35
store/noop_test.go
Normal file
35
store/noop_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type testHook struct {
|
||||
f bool
|
||||
}
|
||||
|
||||
func (t *testHook) Exists(fn FuncExists) FuncExists {
|
||||
return func(ctx context.Context, key string, opts ...ExistsOption) error {
|
||||
t.f = true
|
||||
return fn(ctx, key, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHook(t *testing.T) {
|
||||
h := &testHook{}
|
||||
|
||||
s := NewStore(Hooks(HookExists(h.Exists)))
|
||||
|
||||
if err := s.Init(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := s.Exists(context.TODO(), "test"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !h.f {
|
||||
t.Fatal("hook not works")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user