Esempio n. 1
0
func TestSaveString(t *testing.T) {
	var tmp = os.TempDir()
	cache, _ := NewCache(tmp)
	key := cache.CreateKey("foo")
	err := cache.Save(key, "bar")
	if err != nil {
		t.Errorf("It should not fail, but got %s", err)
	}
}
Esempio n. 2
0
func TestSaveStruct(t *testing.T) {
	var tmp = os.TempDir()
	cache, _ := NewCache(tmp)
	key := cache.CreateKey("example")
	example := Example{
		ID:         1,
		Key:        "key",
		AnotherKey: "This is another key",
	}
	err := cache.Save(key, example)
	if err != nil {
		t.Errorf("It should not fail, but got %s", err)
	}
}
Esempio n. 3
0
func TestIsCached(t *testing.T) {
	var tmp = os.TempDir()
	cache, _ := NewCache(tmp)
	if cache.IsCached("exists") == true {
		t.Errorf("It should not be cached, but it is")
	}
	err := cache.Save("exists", "bar")
	if err != nil {
		t.Errorf("It should not fail, but got an error: %s", err)
	}
	if cache.IsCached("exists") == false {
		t.Errorf("It should be cached, but it doesn't")
	}
}