(t *testing.T)
| 771 | } |
| 772 | |
| 773 | func TestGetSet(t *testing.T) { |
| 774 | server.Clear() |
| 775 | c, err := proto.Dial(server.Addr()) |
| 776 | ok(t, err) |
| 777 | defer c.Close() |
| 778 | s := server.Direct() |
| 779 | |
| 780 | // Existing key |
| 781 | { |
| 782 | s.Set("foo", "bar") |
| 783 | mustDo(t, c, |
| 784 | "GETSET", "foo", "baz", |
| 785 | proto.String("bar"), |
| 786 | ) |
| 787 | s.CheckGet(t, "foo", "baz") |
| 788 | } |
| 789 | |
| 790 | // New key |
| 791 | { |
| 792 | mustNil(t, c, |
| 793 | "GETSET", "bar", "bak", |
| 794 | ) |
| 795 | s.CheckGet(t, "bar", "bak") |
| 796 | } |
| 797 | |
| 798 | // TTL needs to be cleared |
| 799 | { |
| 800 | s.Set("one", "two") |
| 801 | s.SetTTL("one", time.Second*1234) |
| 802 | mustDo(t, c, |
| 803 | "GETSET", "one", "three", |
| 804 | proto.String("two"), |
| 805 | ) |
| 806 | s.CheckGet(t, "bar", "bak") |
| 807 | equals(t, time.Duration(0), s.TTL("one")) |
| 808 | } |
| 809 | |
| 810 | // Wrong type of existing key |
| 811 | { |
| 812 | s.HSet("wrong", "aap", "noot") |
| 813 | mustDo(t, c, |
| 814 | "GETSET", "wrong", "key", |
| 815 | proto.Error(msgWrongType), |
| 816 | ) |
| 817 | } |
| 818 | |
| 819 | // Wrong usage |
| 820 | { |
| 821 | mustDo(t, c, |
| 822 | "GETSET", |
| 823 | proto.Error(errWrongNumber("getset")), |
| 824 | ) |
| 825 | mustDo(t, c, |
| 826 | "GETSET", "spurious", "arguments", "here", |
| 827 | proto.Error(errWrongNumber("getset")), |
| 828 | ) |
| 829 | } |
| 830 | } |
nothing calls this directly
no test coverage detected