* add check negative position to Read() and write tests * add tests for Write() method * add tests for Write() method * add checks of whence and negative position to Seek() and write tests * add tests for Rewind() * add tests for Close() * add tests for Reset() * add tests for Len() * add tests for Bytes() * tests polishing * tests polishing * tests polishing * tests polishing
38 lines
559 B
Go
38 lines
559 B
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"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)
|
|
}
|
|
|
|
err := s.Exists(context.TODO(), "test")
|
|
if !errors.Is(err, ErrNotFound) {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !h.f {
|
|
t.Fatal("hook not works")
|
|
}
|
|
}
|