(t *testing.T)
| 387 | } |
| 388 | |
| 389 | func TestLindex(t *testing.T) { |
| 390 | server.Clear() |
| 391 | c, err := proto.Dial(server.Addr()) |
| 392 | ok(t, err) |
| 393 | defer c.Close() |
| 394 | s := server.Direct() |
| 395 | s.Push("l", "aap", "noot", "mies", "vuur") |
| 396 | |
| 397 | mustDo(t, c, |
| 398 | "LINDEX", "l", "0", |
| 399 | proto.String("aap"), |
| 400 | ) |
| 401 | mustDo(t, c, |
| 402 | "LINDEX", "l", "1", |
| 403 | proto.String("noot"), |
| 404 | ) |
| 405 | mustDo(t, c, |
| 406 | "LINDEX", "l", "3", |
| 407 | proto.String("vuur"), |
| 408 | ) |
| 409 | |
| 410 | mustNil(t, c, "LINDEX", "l", "3000") // Too many |
| 411 | |
| 412 | mustDo(t, c, |
| 413 | "LINDEX", "l", "-1", |
| 414 | proto.String("vuur"), |
| 415 | ) |
| 416 | |
| 417 | mustDo(t, c, |
| 418 | "LINDEX", "l", "-2", |
| 419 | proto.String("mies"), |
| 420 | ) |
| 421 | |
| 422 | mustNil(t, c, "LINDEX", "l", "-400") // Too big |
| 423 | |
| 424 | // Non existing key |
| 425 | mustNil(t, c, "LINDEX", "nonexisting", "400") |
| 426 | |
| 427 | t.Run("errors", func(t *testing.T) { |
| 428 | // Wrong type of key |
| 429 | mustOK(t, c, "SET", "str", "value") |
| 430 | mustDo(t, c, |
| 431 | "LINDEX", "str", "1", |
| 432 | proto.Error(msgWrongType), |
| 433 | ) |
| 434 | |
| 435 | // Not an integer |
| 436 | mustDo(t, c, |
| 437 | "LINDEX", "l", "noint", |
| 438 | proto.Error("ERR value is not an integer or out of range"), |
| 439 | ) |
| 440 | // Too many arguments |
| 441 | mustDo(t, c, |
| 442 | "LINDEX", "str", "l", "foo", |
| 443 | proto.Error("ERR wrong number of arguments for 'lindex' command"), |
| 444 | ) |
| 445 | }) |
| 446 | } |
nothing calls this directly
no test coverage detected