(t *testing.T)
| 28 | ) |
| 29 | |
| 30 | func TestHash(t *testing.T) { |
| 31 | server.Clear() |
| 32 | |
| 33 | c, err := proto.Dial(server.Addr()) |
| 34 | ok(t, err) |
| 35 | defer c.Close() |
| 36 | |
| 37 | must1(t, c, "HSET", "aap", "noot", "mies") |
| 38 | t.Run("basic", func(t *testing.T) { |
| 39 | mustDo(t, c, |
| 40 | "HGET", "aap", "noot", |
| 41 | proto.String("mies"), |
| 42 | ) |
| 43 | equals(t, "mies", directDoString(t, c, "HGET", "aap", "noot")) |
| 44 | |
| 45 | // Existing field. |
| 46 | must0(t, c, "HSET", "aap", "noot", "mies") |
| 47 | |
| 48 | // Multiple fields. |
| 49 | mustDo(t, c, |
| 50 | "HSET", "aaa", "bbb", "cc", "ddd", "ee", |
| 51 | proto.Int(2), |
| 52 | ) |
| 53 | |
| 54 | mustDo(t, c, |
| 55 | "HGET", "aaa", "bbb", |
| 56 | proto.String("cc"), |
| 57 | ) |
| 58 | equals(t, "cc", directDoString(t, c, "HGET", "aaa", "bbb")) |
| 59 | mustDo(t, c, |
| 60 | "HGET", "aaa", "ddd", |
| 61 | proto.String("ee"), |
| 62 | ) |
| 63 | equals(t, "ee", directDoString(t, c, "HGET", "aaa", "ddd")) |
| 64 | }) |
| 65 | |
| 66 | t.Run("wrong key type", func(t *testing.T) { |
| 67 | mustOK(t, c, "SET", "foo", "bar") |
| 68 | mustDo(t, c, |
| 69 | "HSET", "foo", "noot", "mies", |
| 70 | proto.Error("WRONGTYPE Operation against a key holding the wrong kind of value"), |
| 71 | ) |
| 72 | }) |
| 73 | |
| 74 | t.Run("unmatched pairs", func(t *testing.T) { |
| 75 | mustDo(t, c, |
| 76 | "HSET", "a", "b", "c", "d", |
| 77 | proto.Error(errWrongNumber("hset")), |
| 78 | ) |
| 79 | }) |
| 80 | |
| 81 | t.Run("no such key", func(t *testing.T) { |
| 82 | mustNil(t, c, "HGET", "aap", "nosuch") |
| 83 | }) |
| 84 | |
| 85 | t.Run("no such hash", func(t *testing.T) { |
| 86 | mustNil(t, c, "HGET", "nosuch", "nosuch") |
| 87 | equals(t, "", directDoString(t, c, "HGET", "nosuch", "nosuch")) |
nothing calls this directly
no test coverage detected