2015-04-14 18:00:51 +00:00
|
|
|
package physical
|
|
|
|
|
2016-04-26 03:10:32 +00:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
2015-04-14 18:00:51 +00:00
|
|
|
|
|
|
|
func TestCache(t *testing.T) {
|
2016-04-26 03:10:32 +00:00
|
|
|
logger := log.New(os.Stderr, "", log.LstdFlags)
|
|
|
|
inm := NewInmem(logger)
|
2015-04-14 18:03:18 +00:00
|
|
|
cache := NewCache(inm, 0)
|
2015-04-14 18:00:51 +00:00
|
|
|
testBackend(t, cache)
|
|
|
|
testBackend_ListPrefix(t, cache)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCache_Purge(t *testing.T) {
|
2016-04-26 03:10:32 +00:00
|
|
|
logger := log.New(os.Stderr, "", log.LstdFlags)
|
|
|
|
inm := NewInmem(logger)
|
2015-04-14 18:03:18 +00:00
|
|
|
cache := NewCache(inm, 0)
|
2015-04-14 18:00:51 +00:00
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|