(t *testing.T)
| 437 | } |
| 438 | |
| 439 | func TestIncr(t *testing.T) { |
| 440 | server.Clear() |
| 441 | c, err := proto.Dial(server.Addr()) |
| 442 | ok(t, err) |
| 443 | defer c.Close() |
| 444 | s := server.Direct() |
| 445 | |
| 446 | // Existing key |
| 447 | { |
| 448 | s.Set("foo", "12") |
| 449 | mustDo(t, c, |
| 450 | "INCR", "foo", |
| 451 | proto.Int(13), |
| 452 | ) |
| 453 | s.CheckGet(t, "foo", "13") |
| 454 | } |
| 455 | |
| 456 | // Existing key, not an integer |
| 457 | { |
| 458 | s.Set("foo", "noint") |
| 459 | mustDo(t, c, |
| 460 | "INCR", "foo", |
| 461 | proto.Error(msgInvalidInt), |
| 462 | ) |
| 463 | } |
| 464 | |
| 465 | // New key |
| 466 | { |
| 467 | must1(t, c, |
| 468 | "INCR", "bar", |
| 469 | ) |
| 470 | s.CheckGet(t, "bar", "1") |
| 471 | } |
| 472 | |
| 473 | // Wrong type of existing key |
| 474 | { |
| 475 | s.HSet("wrong", "aap", "noot") |
| 476 | mustDo(t, c, |
| 477 | "INCR", "wrong", |
| 478 | proto.Error(msgWrongType), |
| 479 | ) |
| 480 | } |
| 481 | |
| 482 | // Direct usage |
| 483 | { |
| 484 | i, err := s.Incr("count", 1) |
| 485 | ok(t, err) |
| 486 | equals(t, 1, i) |
| 487 | i, err = s.Incr("count", 1) |
| 488 | ok(t, err) |
| 489 | equals(t, 2, i) |
| 490 | _, err = s.Incr("wrong", 1) |
| 491 | assert(t, err != nil, "do s.Incr error") |
| 492 | } |
| 493 | |
| 494 | // Wrong usage |
| 495 | { |
| 496 | mustDo(t, c, |
nothing calls this directly
no test coverage detected