| 1 |
package redis_test |
| 2 |
|
| 3 |
import ( |
| 4 |
. "github.com/onsi/ginkgo" |
| 5 |
. "github.com/onsi/gomega" |
| 6 |
|
| 7 |
"gopkg.in/redis.v5" |
| 8 |
) |
| 9 |
|
| 10 |
var _ = Describe("Cmd", func() { |
| 11 |
var client *redis.Client |
| 12 |
|
| 13 |
BeforeEach(func() { |
| 14 |
client = redis.NewClient(redisOptions()) |
| 15 |
Expect(client.FlushDb().Err()).NotTo(HaveOccurred()) |
| 16 |
}) |
| 17 |
|
| 18 |
AfterEach(func() { |
| 19 |
Expect(client.Close()).NotTo(HaveOccurred()) |
| 20 |
}) |
| 21 |
|
| 22 |
It("implements Stringer", func() { |
| 23 |
set := client.Set("foo", "bar", 0) |
| 24 |
Expect(set.String()).To(Equal("set foo bar: OK")) |
| 25 |
|
| 26 |
get := client.Get("foo") |
| 27 |
Expect(get.String()).To(Equal("get foo: bar")) |
| 28 |
}) |
| 29 |
|
| 30 |
It("has val/err", func() { |
| 31 |
set := client.Set("key", "hello", 0) |
| 32 |
Expect(set.Err()).NotTo(HaveOccurred()) |
| 33 |
Expect(set.Val()).To(Equal("OK")) |
| 34 |
|
| 35 |
get := client.Get("key") |
| 36 |
Expect(get.Err()).NotTo(HaveOccurred()) |
| 37 |
Expect(get.Val()).To(Equal("hello")) |
| 38 |
|
| 39 |
Expect(set.Err()).NotTo(HaveOccurred()) |
| 40 |
Expect(set.Val()).To(Equal("OK")) |
| 41 |
}) |
| 42 |
|
| 43 |
It("has helpers", func() { |
| 44 |
set := client.Set("key", "10", 0) |
| 45 |
Expect(set.Err()).NotTo(HaveOccurred()) |
| 46 |
|
| 47 |
n, err := client.Get("key").Int64() |
| 48 |
Expect(err).NotTo(HaveOccurred()) |
| 49 |
Expect(n).To(Equal(int64(10))) |
| 50 |
|
| 51 |
un, err := client.Get("key").Uint64() |
| 52 |
Expect(err).NotTo(HaveOccurred()) |
| 53 |
Expect(un).To(Equal(uint64(10))) |
| 54 |
|
| 55 |
f, err := client.Get("key").Float64() |
| 56 |
Expect(err).NotTo(HaveOccurred()) |
| 57 |
Expect(f).To(Equal(float64(10))) |
| 58 |
}) |
| 59 |
|
| 60 |
}) |