MCPcopy
hub / github.com/grafana/dskit / TestMockKV_Delete

Function TestMockKV_Delete

kv/etcd/mock_test.go:128–189  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

126}
127
128func TestMockKV_Delete(t *testing.T) {
129 t.Run("exact match", func(t *testing.T) {
130 kv := newMockKV()
131 kv.values["/foo"] = mvccpb.KeyValue{
132 Key: []byte("/foo"),
133 Value: []byte("1"),
134 }
135
136 res, err := kv.Delete(context.Background(), "/foo")
137
138 require.NoError(t, err)
139 assert.Equal(t, int64(1), res.Deleted)
140 assert.Empty(t, kv.values)
141 })
142
143 t.Run("prefix match", func(t *testing.T) {
144 kv := newMockKV()
145 kv.values["/foo"] = mvccpb.KeyValue{
146 Key: []byte("/foo"),
147 Value: []byte("1"),
148 }
149 kv.values["/baz"] = mvccpb.KeyValue{
150 Key: []byte("/baz"),
151 Value: []byte("2"),
152 }
153 kv.values["/first"] = mvccpb.KeyValue{
154 Key: []byte("/first"),
155 Value: []byte("3"),
156 }
157
158 res, err := kv.Delete(context.Background(), "/f", clientv3.WithPrefix())
159
160 require.NoError(t, err)
161 assert.Equal(t, int64(2), res.Deleted)
162 assert.NotContains(t, kv.values, "/foo")
163 assert.NotContains(t, kv.values, "/first")
164 })
165
166 t.Run("empty prefix", func(t *testing.T) {
167 kv := newMockKV()
168 kv.values["/foo"] = mvccpb.KeyValue{
169 Key: []byte("/foo"),
170 Value: []byte("1"),
171 }
172 kv.values["/baz"] = mvccpb.KeyValue{
173 Key: []byte("/baz"),
174 Value: []byte("2"),
175 }
176 kv.values["/first"] = mvccpb.KeyValue{
177 Key: []byte("/first"),
178 Value: []byte("3"),
179 }
180
181 res, err := kv.Delete(context.Background(), "", clientv3.WithPrefix())
182
183 require.NoError(t, err)
184 assert.Equal(t, int64(3), res.Deleted)
185 assert.NotContains(t, kv.values, "/foo")

Callers

nothing calls this directly

Calls 4

newMockKVFunction · 0.85
RunMethod · 0.80
DeleteMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected