Пример #1
0
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)
	}
}
Пример #2
0
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)
	}
}