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