Test SRANDMEMBER
(t *testing.T)
| 361 | |
| 362 | // Test SRANDMEMBER |
| 363 | func 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), |
nothing calls this directly
no test coverage detected