Skip to content

Commit 15bf95d

Browse files
committed
test:add test for SPop
1 parent 5b9717c commit 15bf95d

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

tests/integration/set_test.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,26 @@ var _ = Describe("Set Commands", func() {
270270
sAdd = client.SAdd(ctx, "set", "three")
271271
Expect(sAdd.Err()).NotTo(HaveOccurred())
272272

273-
// 报错:redis: can't parse reply="*1" reading string
274-
//sPop := client.SPop(ctx, "set")
275-
//Expect(sPop.Err()).NotTo(HaveOccurred())
276-
//Expect(sPop.Val()).NotTo(Equal(""))
273+
sPop := client.SPop(ctx, "set")
274+
Expect(sPop.Err()).NotTo(HaveOccurred())
275+
Expect(sPop.Val()).NotTo(Equal(""))
277276

278277
sMembers := client.SMembers(ctx, "set")
279278
Expect(sMembers.Err()).NotTo(HaveOccurred())
280-
Expect(sMembers.Val()).To(HaveLen(3))
279+
Expect(sMembers.Val()).To(HaveLen(2))
280+
281+
// 再添加一个元素进行批量弹出测试
282+
sAdd = client.SAdd(ctx, "set2", "one")
283+
Expect(sAdd.Err()).NotTo(HaveOccurred())
284+
sAdd = client.SAdd(ctx, "set2", "two")
285+
Expect(sAdd.Err()).NotTo(HaveOccurred())
286+
sAdd = client.SAdd(ctx, "set2", "three")
287+
Expect(sAdd.Err()).NotTo(HaveOccurred())
288+
289+
// 测试多个元素弹出,应该返回数组
290+
sPopN := client.SPopN(ctx, "set2", 2)
291+
Expect(sPopN.Err()).NotTo(HaveOccurred())
292+
Expect(sPopN.Val()).To(HaveLen(2))
281293

282294
err := client.Do(ctx, "SPOP", "set", 1, 2).Err()
283295
Expect(err).To(MatchError(ContainSubstring("ERR wrong number of arguments for 'spop' command")))

0 commit comments

Comments
 (0)