MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / TestSadd

Function TestSadd

IceFireDB-Redis-Proxy/test/cmd_set_test.go:30–120  ·  view source on GitHub ↗

Test SADD / SMEMBERS.

(t *testing.T)

Source from the content-addressed store, hash-verified

28
29// Test SADD / SMEMBERS.
30func TestSadd(t *testing.T) {
31 server.Clear()
32 c, err := proto.Dial(server.Addr())
33 ok(t, err)
34 defer c.Close()
35 s := server.Direct()
36
37 {
38 mustDo(t, c,
39 "SADD", "s", "aap", "noot", "mies",
40 proto.Int(3),
41 )
42
43 members, err := s.Members("s")
44 ok(t, err)
45 equals(t, []string{"aap", "mies", "noot"}, members)
46
47 mustDo(t, c,
48 "SMEMBERS", "s",
49 proto.Strings("aap", "mies", "noot"),
50 )
51 }
52
53 mustDo(t, c,
54 "TYPE", "s",
55 proto.Inline("set"),
56 )
57
58 // SMEMBERS on an nonexisting key
59 mustDo(t, c,
60 "SMEMBERS", "nosuch",
61 proto.Strings(),
62 )
63
64 {
65 mustDo(t, c,
66 "SADD", "s", "new", "noot", "mies",
67 proto.Int(1), // Only one new field.
68 )
69
70 members, err := s.Members("s")
71 ok(t, err)
72 equals(t, []string{"aap", "mies", "new", "noot"}, members)
73 }
74
75 t.Run("direct usage", func(t *testing.T) {
76 added, err := s.SetAdd("s1", "aap")
77 ok(t, err)
78 equals(t, 1, added)
79
80 members, err := s.Members("s1")
81 ok(t, err)
82 equals(t, []string{"aap"}, members)
83 })
84
85 t.Run("errors", func(t *testing.T) {
86 mustOK(t, c, "SET", "str", "value")
87 mustDo(t, c,

Callers

nothing calls this directly

Calls 15

ClearFunction · 0.92
DialFunction · 0.92
AddrFunction · 0.92
DirectFunction · 0.92
IntFunction · 0.92
StringsFunction · 0.92
InlineFunction · 0.92
ErrorFunction · 0.92
okFunction · 0.70
mustDoFunction · 0.70
equalsFunction · 0.70
mustOKFunction · 0.70

Tested by

no test coverage detected