MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / TestHash

Function TestHash

IceFireDB-Redis-Proxy/test/cmd_hash_test.go:30–114  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func 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"))

Callers

nothing calls this directly

Calls 15

ClearFunction · 0.92
DialFunction · 0.92
AddrFunction · 0.92
StringFunction · 0.92
IntFunction · 0.92
ErrorFunction · 0.92
okFunction · 0.70
must1Function · 0.70
mustDoFunction · 0.70
equalsFunction · 0.70
directDoStringFunction · 0.70
must0Function · 0.70

Tested by

no test coverage detected