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) } }
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) } }
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") } }