// +build redis package redis import ( "os" "testing" "time" "github.com/gofiber/utils" ) var storeConfig = ConfigDefault func init() { if v := os.Getenv("REDIS_PORT"); v != "" { storeConfig.Addr = "localhost:" + v } } func Test_Redis_Set(t *testing.T) { store := New(storeConfig) id := "hello" value := []byte("Hi there!") store.Set(id, value, 0) var ( returnedValue []byte exp int64 ) store.db.QueryRow(store.sqlSelect, id).Scan(&returnedValue, &exp) utils.AssertEqual(t, returnedValue, value) utils.AssertEqual(t, exp, int64(0)) } func Test_Redis_SetExpiry(t *testing.T) { store := New(storeConfig) id := "hello" value := []byte("Hi there!") expiry := time.Second * 10 store.Set(id, value, expiry) now := time.Now().Unix() var ( returnedValue []byte exp int64 ) store.db.QueryRow(store.sqlSelect, id).Scan(&returnedValue, &exp) delta := exp - now upperBound := int64(expiry.Seconds()) lowerBound := upperBound - 2 if !(delta <= upperBound && delta > lowerBound) { t.Fatalf("Test_SetExpiry: expiry delta out of bounds (is %d, must be %d