Better test coverage for memory cache
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
4131c431ef
commit
5306bdbb7e
@ -5,7 +5,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func Test_MemoryURI(t *testing.T) {
|
||||
func TestNew_MemoryURI(t *testing.T) {
|
||||
cache, err := New("memory://")
|
||||
|
||||
if err != nil {
|
||||
@ -17,7 +17,7 @@ func Test_MemoryURI(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_MemoryStoreGet(t *testing.T) {
|
||||
func TestMemoryCache_Get(t *testing.T) {
|
||||
cache, err := New("memory://")
|
||||
|
||||
if err != nil {
|
||||
@ -36,3 +36,61 @@ func Test_MemoryStoreGet(t *testing.T) {
|
||||
t.Fatal("Expected", obj, "got", new)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMemoryCache_GetRaw(t *testing.T) {
|
||||
cache, err := New("memory://")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("Error creating cache:", err)
|
||||
}
|
||||
|
||||
obj := "test"
|
||||
|
||||
cache.Set("test", obj, time.Minute)
|
||||
|
||||
v, err := cache.Get("test")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("Unable to get value:", err)
|
||||
}
|
||||
|
||||
new := string(v)
|
||||
|
||||
if obj != new {
|
||||
t.Fatal("Expected", obj, "got", new)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMemoryCache_Has(t *testing.T) {
|
||||
cache, err := New("memory://")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("Error creating cache:", err)
|
||||
}
|
||||
|
||||
cache.Set("test", "test", time.Minute)
|
||||
|
||||
if !cache.Has("test") {
|
||||
t.Fatal("Expected cache to have object 'test'")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMemoryCache_Del(t *testing.T) {
|
||||
cache, err := New("memory://")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal("Error creating cache:", err)
|
||||
}
|
||||
|
||||
cache.Set("test", "test", time.Minute)
|
||||
|
||||
if !cache.Has("test") {
|
||||
t.Fatal("Expected cache to have object 'test'")
|
||||
}
|
||||
|
||||
cache.Del("test")
|
||||
|
||||
if cache.Has("test") {
|
||||
t.Fatal("Cache did not properly delete item")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user