| 707 | } |
| 708 | |
| 709 | func TestDecr(t *testing.T) { |
| 710 | server.Clear() |
| 711 | c, err := proto.Dial(server.Addr()) |
| 712 | ok(t, err) |
| 713 | defer c.Close() |
| 714 | s := server.Direct() |
| 715 | |
| 716 | // Existing key |
| 717 | { |
| 718 | s.Set("foo", "12") |
| 719 | mustDo(t, c, |
| 720 | "DECR", "foo", |
| 721 | proto.Int(11), |
| 722 | ) |
| 723 | s.CheckGet(t, "foo", "11") |
| 724 | } |
| 725 | |
| 726 | // Existing key, not an integer |
| 727 | { |
| 728 | s.Set("foo", "noint") |
| 729 | mustDo(t, c, |
| 730 | "DECR", "foo", |
| 731 | proto.Error(msgInvalidInt), |
| 732 | ) |
| 733 | } |
| 734 | |
| 735 | // New key |
| 736 | { |
| 737 | mustDo(t, c, |
| 738 | "DECR", "bar", |
| 739 | proto.Int(-1), |
| 740 | ) |
| 741 | s.CheckGet(t, "bar", "-1") |
| 742 | } |
| 743 | |
| 744 | // Wrong type of existing key |
| 745 | { |
| 746 | s.HSet("wrong", "aap", "noot") |
| 747 | mustDo(t, c, |
| 748 | "DECR", "wrong", |
| 749 | proto.Error(msgWrongType), |
| 750 | ) |
| 751 | } |
| 752 | |
| 753 | // Wrong usage |
| 754 | { |
| 755 | mustDo(t, c, |
| 756 | "DECR", |
| 757 | proto.Error(errWrongNumber("decr")), |
| 758 | ) |
| 759 | mustDo(t, c, |
| 760 | "DECR", "new", "key", |
| 761 | proto.Error(errWrongNumber("decr")), |
| 762 | ) |
| 763 | } |
| 764 | |
| 765 | // Direct one works |
| 766 | { |