1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-18 08:26:45 +02:00
woodpecker/vendor/github.com/koding/cache/helper_test.go

84 lines
1.7 KiB
Go

package cache
import "testing"
func testCacheGetSet(t *testing.T, cache Cache) {
err := cache.Set("test_key", "test_data")
if err != nil {
t.Fatal("should not give err while setting item")
}
err = cache.Set("test_key2", "test_data2")
if err != nil {
t.Fatal("should not give err while setting item")
}
data, err := cache.Get("test_key")
if err != nil {
t.Fatal("test_key should be in the cache")
}
if data != "test_data" {
t.Fatal("data is not \"test_data\"")
}
data, err = cache.Get("test_key2")
if err != nil {
t.Fatal("test_key2 should be in the cache")
}
if data != "test_data2" {
t.Fatal("data is not \"test_data2\"")
}
}
func testCacheNilValue(t *testing.T, cache Cache) {
err := cache.Set("test_key", nil)
if err != nil {
t.Fatal("should not give err while setting item")
}
data, err := cache.Get("test_key")
if err != nil {
t.Fatal("test_key should be in the cache")
}
if data != nil {
t.Fatal("data is not nil")
}
err = cache.Delete("test_key")
if err != nil {
t.Fatal("should not give err while setting item")
}
data, err = cache.Get("test_key")
if err == nil {
t.Fatal("test_key should not be in the cache")
}
}
func testCacheDelete(t *testing.T, cache Cache) {
cache.Set("test_key", "test_data")
cache.Set("test_key2", "test_data2")
err := cache.Delete("test_key3")
if err != nil {
t.Fatal("non-exiting item should not give error")
}
err = cache.Delete("test_key")
if err != nil {
t.Fatal("exiting item should not give error")
}
data, err := cache.Get("test_key")
if err != ErrNotFound {
t.Fatal("test_key should not be in the cache")
}
if data != nil {
t.Fatal("data should be nil")
}
}