| 1037 | } |
| 1038 | |
| 1039 | func TestSetrange(t *testing.T) { |
| 1040 | server.Clear() |
| 1041 | c, err := proto.Dial(server.Addr()) |
| 1042 | ok(t, err) |
| 1043 | defer c.Close() |
| 1044 | s := server.Direct() |
| 1045 | |
| 1046 | // Simple case |
| 1047 | { |
| 1048 | s.Set("foo", "abcdefg") |
| 1049 | mustDo(t, c, |
| 1050 | "SETRANGE", "foo", "1", "bar", |
| 1051 | proto.Int(7), |
| 1052 | ) |
| 1053 | s.CheckGet(t, "foo", "abarefg") |
| 1054 | } |
| 1055 | // Non existing key |
| 1056 | { |
| 1057 | mustDo(t, c, |
| 1058 | "SETRANGE", "nosuch", "3", "bar", |
| 1059 | proto.Int(6), |
| 1060 | ) |
| 1061 | s.CheckGet(t, "nosuch", "\x00\x00\x00bar") |
| 1062 | } |
| 1063 | |
| 1064 | // Wrong type of existing key |
| 1065 | { |
| 1066 | s.HSet("wrong", "aap", "noot") |
| 1067 | mustDo(t, c, |
| 1068 | "SETRANGE", "wrong", "0", "aap", |
| 1069 | proto.Error(msgWrongType), |
| 1070 | ) |
| 1071 | } |
| 1072 | |
| 1073 | // Wrong usage |
| 1074 | { |
| 1075 | mustDo(t, c, |
| 1076 | "SETRANGE", |
| 1077 | proto.Error(errWrongNumber("setrange")), |
| 1078 | ) |
| 1079 | mustDo(t, c, |
| 1080 | "SETRANGE", "missing", |
| 1081 | proto.Error(errWrongNumber("setrange")), |
| 1082 | ) |
| 1083 | mustDo(t, c, |
| 1084 | "SETRANGE", "missing", "1", |
| 1085 | proto.Error(errWrongNumber("setrange")), |
| 1086 | ) |
| 1087 | mustDo(t, c, |
| 1088 | "SETRANGE", "key", "noint", "", |
| 1089 | proto.Error(msgInvalidInt), |
| 1090 | ) |
| 1091 | mustDo(t, c, |
| 1092 | "SETRANGE", "key", "-1", "", |
| 1093 | proto.Error("ERR offset is out of range"), |
| 1094 | ) |
| 1095 | mustDo(t, c, |
| 1096 | "SETRANGE", "many", "12", "keys", "here", |