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

Function TestSrandmember

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

Test SRANDMEMBER

(t *testing.T)

Source from the content-addressed store, hash-verified

361
362// Test SRANDMEMBER
363func TestSrandmember(t *testing.T) {
364 server.Clear()
365 c, err := proto.Dial(server.Addr())
366 ok(t, err)
367 defer c.Close()
368 s := server.Direct()
369
370 s.SetAdd("s", "aap", "noot", "mies")
371
372 s.Seed(42)
373 // No count
374 {
375 res, err := c.Do("SRANDMEMBER", "s")
376 ok(t, err)
377 assert(t, res == proto.String("aap") ||
378 res == proto.String("noot") ||
379 res == proto.String("mies"),
380 "srandmember got something",
381 )
382 }
383
384 // Positive count
385 mustDo(t, c,
386 "SRANDMEMBER", "s", "2",
387 proto.Strings("noot", "mies"),
388 )
389
390 // Negative count
391 mustDo(t, c,
392 "SRANDMEMBER", "s", "-2",
393 proto.Strings("aap", "mies"),
394 )
395
396 // a nonexisting key
397 mustNil(t, c,
398 "SRANDMEMBER", "nosuch",
399 )
400
401 t.Run("errors", func(t *testing.T) {
402 s.SetAdd("chk", "aap", "noot")
403 s.Set("str", "value")
404
405 mustDo(t, c,
406 "SRANDMEMBER",
407 proto.Error(errWrongNumber("srandmember")),
408 )
409 mustDo(t, c,
410 "SRANDMEMBER", "chk", "noint",
411 proto.Error("ERR value is not an integer or out of range"),
412 )
413 mustDo(t, c,
414 "SRANDMEMBER", "chk", "1", "toomanu",
415 proto.Error("ERR syntax error"),
416 )
417
418 mustDo(t, c,
419 "SRANDMEMBER", "str",
420 proto.Error(msgWrongType),

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected