open-vault/physical/cache_test.go
Sean Chittenden aeea7628d6 Add a *log.Logger argument to physical.Factory
Logging in the backend is a good thing.  This is a noisy interface change but should be a functional noop.
2016-04-25 20:10:32 -07:00

55 lines
895 B
Go

package physical
import (
"log"
"os"
"testing"
)
func TestCache(t *testing.T) {
logger := log.New(os.Stderr, "", log.LstdFlags)
inm := NewInmem(logger)
cache := NewCache(inm, 0)
testBackend(t, cache)
testBackend_ListPrefix(t, cache)
}
func TestCache_Purge(t *testing.T) {
logger := log.New(os.Stderr, "", log.LstdFlags)
inm := NewInmem(logger)
cache := NewCache(inm, 0)
ent := &Entry{
Key: "foo",
Value: []byte("bar"),
}
err := cache.Put(ent)
if err != nil {
t.Fatalf("err: %v", err)
}
// Delete from under
inm.Delete("foo")
// Read should work
out, err := cache.Get("foo")
if err != nil {
t.Fatalf("err: %v", err)
}
if out == nil {
t.Fatalf("should have key")
}
// Clear the cache
cache.Purge()
// Read should fail
out, err = cache.Get("foo")
if err != nil {
t.Fatalf("err: %v", err)
}
if out != nil {
t.Fatalf("should not have key")
}
}