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 TestCreateKey(t *testing.T) { var tmp = os.TempDir() cache, _ := NewCache(tmp) hash := cache.CreateKey("foo") if hash == "" { t.Errorf("Hash should not be null, but got %s", hash) } if hash != "2851307223" { t.Errorf("Hash should be '2851307223', but got %s", hash) } }
func TestLoadString(t *testing.T) { var tmp = os.TempDir() cache, _ := NewCache(tmp) key := cache.CreateKey("foo") var data string err := cache.Load(key, &data) if err != nil { t.Errorf("It should not fail, but got %s", err) } if data != "bar" { t.Errorf("Value should be equal to 'bar', but got: %s", data) } }
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 TestLoadStruct(t *testing.T) { var tmp = os.TempDir() cache, _ := NewCache(tmp) key := cache.CreateKey("example") var example Example err := cache.Load(key, &example) if err != nil { t.Errorf("It should not fail, but got %s", err) } if example.ID != 1 { t.Errorf("Payload ID should be 1, but got: %d", example.ID) } if example.Key != "key" { t.Errorf("Payload ID should be 'key', but got: %s", example.Key) } }