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

Function TestSpop

IceFireDB-PubSub/test/cmd_set_test.go:300–360  ·  view source on GitHub ↗

Test SMOVE *func TestSmove(t *testing.T) { server.Clear() c, err := proto.Dial(server.Addr()) ok(t, err) defer c.Close() s := server.Direct() s.SetAdd("s", "aap", "noot") { must1(t, c, "SMOVE", "s", "s2", "aap", ) m, err := s.IsMember("s", "aap") ok(t, err) equals(t, false, m)

(t *testing.T)

Source from the content-addressed store, hash-verified

298
299// Test SPOP
300func TestSpop(t *testing.T) {
301 server.Clear()
302 c, err := proto.Dial(server.Addr())
303 ok(t, err)
304 defer c.Close()
305 s := server.Direct()
306
307 t.Run("basics", func(t *testing.T) {
308 s.SetAdd("s", "aap", "noot")
309
310 res, err := c.Do("SPOP", "s")
311 ok(t, err)
312 assert(t, res == proto.String("aap") || res == proto.String("noot"), "spop got something")
313
314 res, err = c.Do("SPOP", "s")
315 ok(t, err)
316 assert(t, res == proto.String("aap") || res == proto.String("noot"), "spop got something")
317
318 assert(t, !s.Exists("s"), "all spopped away")
319 })
320
321 t.Run("nonexisting key", func(t *testing.T) {
322 mustNil(t, c, "SPOP", "nosuch")
323 })
324
325 t.Run("various errors", func(t *testing.T) {
326 s.SetAdd("chk", "aap", "noot")
327 s.Set("str", "value")
328
329 /*mustDo(t, c,
330 "SMOVE",
331 proto.Error(errWrongNumber("smove")),
332 )
333 mustDo(t, c,
334 "SMOVE", "chk", "set2",
335 proto.Error(errWrongNumber("smove")),
336 )*/
337
338 mustDo(t, c,
339 "SPOP", "str",
340 proto.Error(msgWrongType),
341 )
342 })
343
344 t.Run("count argument", func(t *testing.T) {
345 s.SetAdd("s", "aap", "noot", "mies", "vuur")
346 directDo(t, c, "SPOP", "s", "2")
347 /*mustDo(t, c,
348 "SPOP", "s", "2",
349 proto.Strings("aap", "noot"),
350 )*/
351 members, err := s.Members("s")
352 ok(t, err)
353 assert(t, len(members) == 2, "SPOP s 2")
354
355 mustDo(t, c,
356 "SPOP", "str", "-12",
357 proto.Error(msgOutOfRange),

Callers

nothing calls this directly

Calls 15

ClearFunction · 0.92
DialFunction · 0.92
AddrFunction · 0.92
DirectFunction · 0.92
StringFunction · 0.92
ErrorFunction · 0.92
SetMethod · 0.80
okFunction · 0.70
assertFunction · 0.70
mustNilFunction · 0.70
mustDoFunction · 0.70
directDoFunction · 0.70

Tested by

no test coverage detected