| 644 | } |
| 645 | |
| 646 | func TestDecrBy(t *testing.T) { |
| 647 | server.Clear() |
| 648 | c, err := proto.Dial(server.Addr()) |
| 649 | ok(t, err) |
| 650 | defer c.Close() |
| 651 | s := server.Direct() |
| 652 | |
| 653 | // Existing key |
| 654 | { |
| 655 | s.Set("foo", "12") |
| 656 | mustDo(t, c, |
| 657 | "DECRBY", "foo", "400", |
| 658 | proto.Int(-388), |
| 659 | ) |
| 660 | s.CheckGet(t, "foo", "-388") |
| 661 | } |
| 662 | |
| 663 | // Existing key, not an integer |
| 664 | { |
| 665 | s.Set("foo", "noint") |
| 666 | mustDo(t, c, |
| 667 | "DECRBY", "foo", "400", |
| 668 | proto.Error(msgInvalidInt), |
| 669 | ) |
| 670 | } |
| 671 | |
| 672 | // New key |
| 673 | { |
| 674 | mustDo(t, c, |
| 675 | "DECRBY", "bar", "4000", |
| 676 | proto.Int(-4000), |
| 677 | ) |
| 678 | s.CheckGet(t, "bar", "-4000") |
| 679 | } |
| 680 | |
| 681 | // Wrong type of existing key |
| 682 | { |
| 683 | s.HSet("wrong", "aap", "noot") |
| 684 | mustDo(t, c, |
| 685 | "DECRBY", "wrong", "400", |
| 686 | proto.Error(msgWrongType), |
| 687 | ) |
| 688 | } |
| 689 | |
| 690 | // Amount not an integer |
| 691 | mustDo(t, c, |
| 692 | "DECRBY", "key", "noint", |
| 693 | proto.Error(msgInvalidInt), |
| 694 | ) |
| 695 | |
| 696 | // Wrong usage |
| 697 | { |
| 698 | mustDo(t, c, |
| 699 | "DECRBY", |
| 700 | proto.Error(errWrongNumber("decrby")), |
| 701 | ) |
| 702 | mustDo(t, c, |
| 703 | "DECRBY", "another", "new", "key", |