mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-10 08:20:23 +00:00
43 lines
704 B
Go
43 lines
704 B
Go
package diskcache
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestDiskCache(t *testing.T) {
|
|
tempDir, err := ioutil.TempDir("", "httpcache")
|
|
if err != nil {
|
|
t.Fatalf("TempDir: %v", err)
|
|
}
|
|
defer os.RemoveAll(tempDir)
|
|
|
|
cache := New(tempDir)
|
|
|
|
key := "testKey"
|
|
_, ok := cache.Get(key)
|
|
if ok {
|
|
t.Fatal("retrieved key before adding it")
|
|
}
|
|
|
|
val := []byte("some bytes")
|
|
cache.Set(key, val)
|
|
|
|
retVal, ok := cache.Get(key)
|
|
if !ok {
|
|
t.Fatal("could not retrieve an element we just added")
|
|
}
|
|
if !bytes.Equal(retVal, val) {
|
|
t.Fatal("retrieved a different value than what we put in")
|
|
}
|
|
|
|
cache.Delete(key)
|
|
|
|
_, ok = cache.Get(key)
|
|
if ok {
|
|
t.Fatal("deleted key still present")
|
|
}
|
|
}
|