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

Function TestLpush

IceFireDB-PubSub/test/cmd_list_test.go:52–140  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func TestLpush(t *testing.T) {
53 server.Clear()
54 c, err := proto.Dial(server.Addr())
55 ok(t, err)
56 defer c.Close()
57 s := server.Direct()
58
59 t.Run("basic", func(t *testing.T) {
60 mustDo(t, c,
61 "LPUSH", "l", "aap", "noot", "mies",
62 proto.Int(3), // new length.
63 )
64
65 mustDo(t, c,
66 "LRANGE", "l", "0", "0",
67 proto.Strings("mies"),
68 )
69
70 mustDo(t, c,
71 "LRANGE", "l", "-1", "-1",
72 proto.Strings("aap"),
73 )
74
75 mustDo(t, c,
76 "LPUSH", "l", "aap2", "noot2", "mies2",
77 proto.Int(6),
78 )
79
80 mustDo(t, c,
81 "LRANGE", "l", "0", "0",
82 proto.Strings("mies2"),
83 )
84
85 mustDo(t, c,
86 "LRANGE", "l", "-1", "-1",
87 proto.Strings("aap"),
88 )
89 })
90
91 t.Run("direct", func(t *testing.T) {
92 l, err := s.Lpush("l2", "a")
93 ok(t, err)
94 equals(t, 1, l)
95 l, err = s.Lpush("l2", "b")
96 ok(t, err)
97 equals(t, 2, l)
98 list, err := s.List("l2")
99 ok(t, err)
100 equals(t, []string{"b", "a"}, list)
101 el, err := s.Lpop("l2")
102 ok(t, err)
103 equals(t, "b", el)
104 el, err = s.Lpop("l2")
105 ok(t, err)
106 equals(t, "a", el)
107 // Key is removed on pop-empty.
108 equals(t, false, s.Exists("l2"))
109 })

Callers

nothing calls this directly

Calls 13

ClearFunction · 0.92
DialFunction · 0.92
AddrFunction · 0.92
DirectFunction · 0.92
IntFunction · 0.92
StringsFunction · 0.92
ErrorFunction · 0.92
okFunction · 0.70
mustDoFunction · 0.70
equalsFunction · 0.70
mustOKFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected