-
Notifications
You must be signed in to change notification settings - Fork 1
/
wredis_sets_test.go
133 lines (109 loc) · 3.83 KB
/
wredis_sets_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package wredis_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Sets", func() {
var (
testKey = "wredis::test::sets::one"
otherKey = "wredis::test::sets::two"
testSet = []string{"a", "b", "c"}
otherSet = []string{"a", "b", "d", "e"}
)
BeforeEach(func() {
Ω(unsafe.SAdd(testKey, testSet)).Should(BeEquivalentTo(3))
Ω(unsafe.SAdd(otherKey, otherSet)).Should(BeEquivalentTo(4))
})
AfterEach(func() {
Ω(unsafe.FlushAll()).Should(Succeed())
})
Context("SADD", func() {
It("should Add members to an existing set successfully", func() {
Ω(safe.SAdd(testKey, otherSet)).Should(BeEquivalentTo(2))
})
It("should fail if an empty slice is passed to SAdd", func() {
_, err := safe.SAdd(testKey, []string{})
Ω(err).ShouldNot(BeNil())
})
})
Context("SCARD", func() {
It("should return the correct count of members in a set", func() {
Ω(safe.SCard(testKey)).Should(BeEquivalentTo(3))
Ω(safe.SCard(otherKey)).Should(BeEquivalentTo(4))
})
It("should fail given an empty key", func() {
_, err := safe.SCard("")
Ω(err).Should(HaveOccurred())
Ω(err.Error()).Should(Equal("key cannot be empty"))
})
})
Context("SDIFFSTORE", func() {
var diffKey = "wredis::test::sets::diff"
It("should successfully store the difference of two sets correctly", func() {
diff, err := safe.SDiffStore(diffKey, otherKey, testKey)
Ω(err).Should(BeNil())
Ω(diff).Should(BeEquivalentTo(2))
})
It("should successfully store the difference of two sets correctly", func() {
diff, err := safe.SDiffStore(diffKey, testKey, otherKey)
Ω(err).Should(BeNil())
Ω(diff).Should(BeEquivalentTo(1))
})
It("should fail if empty dest is passed", func() {
_, err := safe.SDiffStore("")
Ω(err).Should(HaveOccurred())
Ω(err.Error()).Should(Equal("dest cannot be an empty string"))
})
It("should fail if no set keys are passed", func() {
_, err := safe.SDiffStore(diffKey)
Ω(err).Should(HaveOccurred())
Ω(err.Error()).Should(Equal("SDiffStore requires at least 1 input set"))
})
It("should fail if not set keys are passed", func() {
_, err := safe.SDiffStore(diffKey, "key", "", "otherKey")
Ω(err).Should(HaveOccurred())
Ω(err.Error()).Should(Equal("set keys cannot be empty strings"))
})
})
Context("SMEMBERS", func() {
It("should returns the members of a set successfully", func() {
members, err := safe.SMembers(testKey)
Ω(err).Should(BeNil())
Ω(members).Should(HaveLen(3))
Ω(members).Should(ConsistOf(testSet))
})
It("should return an error if key passed is empty", func() {
_, err := safe.SMembers("")
Ω(err).ShouldNot(BeNil())
Ω(err.Error()).Should(Equal("key cannot be an empty string"))
})
})
Context("SUNIONSTORE", func() {
var unionKey = "wredis::test::sets::union"
It("should successfully store the union of two sets correctly", func() {
union, err := safe.SUnionStore(unionKey, otherKey, testKey)
Ω(err).Should(BeNil())
Ω(union).Should(BeEquivalentTo(5))
})
It("should successfully store the union of two sets correctly", func() {
union, err := safe.SUnionStore(unionKey, testKey, otherKey)
Ω(err).Should(BeNil())
Ω(union).Should(BeEquivalentTo(5))
})
It("should fail if empty dest is passed", func() {
_, err := safe.SUnionStore("")
Ω(err).Should(HaveOccurred())
Ω(err.Error()).Should(Equal("dest cannot be an empty string"))
})
It("should fail if no set keys are passed", func() {
_, err := safe.SUnionStore(unionKey)
Ω(err).Should(HaveOccurred())
Ω(err.Error()).Should(Equal("SUnionStore requires at least 1 input set"))
})
It("should fail if not set keys are passed", func() {
_, err := safe.SUnionStore(unionKey, "key", "", "otherKey")
Ω(err).Should(HaveOccurred())
Ω(err.Error()).Should(Equal("set keys cannot be empty strings"))
})
})
})