2015-01-15 18:51:22 +03:00
|
|
|
package redis_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
2015-05-14 15:19:29 +03:00
|
|
|
|
2016-04-09 13:27:16 +03:00
|
|
|
"gopkg.in/redis.v4"
|
2015-01-15 18:51:22 +03:00
|
|
|
)
|
|
|
|
|
2016-04-12 19:41:56 +03:00
|
|
|
var _ = Describe("Cmd", func() {
|
2015-01-15 18:51:22 +03:00
|
|
|
var client *redis.Client
|
|
|
|
|
2016-03-14 13:36:18 +03:00
|
|
|
BeforeEach(func() {
|
2016-03-16 17:57:24 +03:00
|
|
|
client = redis.NewClient(redisOptions())
|
|
|
|
Expect(client.FlushDb().Err()).NotTo(HaveOccurred())
|
2015-01-15 18:51:22 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
AfterEach(func() {
|
|
|
|
Expect(client.Close()).NotTo(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
2016-04-12 19:41:56 +03:00
|
|
|
It("implements Stringer", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("foo", "bar", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.String()).To(Equal("SET foo bar: OK"))
|
|
|
|
|
|
|
|
get := client.Get("foo")
|
|
|
|
Expect(get.String()).To(Equal("GET foo: bar"))
|
|
|
|
})
|
|
|
|
|
2016-04-12 19:41:56 +03:00
|
|
|
It("has val/err", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "hello", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
|
|
|
|
get := client.Get("key")
|
|
|
|
Expect(get.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(get.Val()).To(Equal("hello"))
|
|
|
|
|
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
Expect(set.Val()).To(Equal("OK"))
|
|
|
|
})
|
|
|
|
|
2016-04-12 19:41:56 +03:00
|
|
|
It("has helpers", func() {
|
2015-01-31 12:08:56 +03:00
|
|
|
set := client.Set("key", "10", 0)
|
2015-01-15 18:51:22 +03:00
|
|
|
Expect(set.Err()).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
n, err := client.Get("key").Int64()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(n).To(Equal(int64(10)))
|
|
|
|
|
|
|
|
un, err := client.Get("key").Uint64()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(un).To(Equal(uint64(10)))
|
|
|
|
|
|
|
|
f, err := client.Get("key").Float64()
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
Expect(f).To(Equal(float64(10)))
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|