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

Method List

kv/consul/mock.go:203–230  ·  view source on GitHub ↗
(prefix string, q *consul.QueryOptions)

Source from the content-addressed store, hash-verified

201}
202
203func (m *mockKV) List(prefix string, q *consul.QueryOptions) (consul.KVPairs, *consul.QueryMeta, error) {
204 m.mtx.Lock()
205 defer m.mtx.Unlock()
206
207 if q.WaitTime > 0 {
208 deadline := time.Now().Add(mockedMaxWaitTime(q.WaitTime))
209 if ctxDeadline, ok := q.Context().Deadline(); ok && ctxDeadline.Before(deadline) {
210 // respect deadline from context, if set.
211 deadline = ctxDeadline
212 }
213
214 for q.WaitIndex >= m.current && time.Now().Before(deadline) {
215 m.cond.Wait()
216 }
217 if time.Now().After(deadline) {
218 return nil, &consul.QueryMeta{LastIndex: q.WaitIndex}, nil
219 }
220 }
221
222 result := consul.KVPairs{}
223 for _, kvp := range m.kvps {
224 if strings.HasPrefix(kvp.Key, prefix) && kvp.ModifyIndex >= q.WaitIndex {
225 // unfortunately real consul doesn't do index check and returns everything with given prefix.
226 result = append(result, copyKVPair(kvp))
227 }
228 }
229 return result, &consul.QueryMeta{LastIndex: m.current}, nil
230}
231
232func (m *mockKV) Delete(key string, _ *consul.WriteOptions) (*consul.WriteMeta, error) {
233 m.mtx.Lock()

Callers

nothing calls this directly

Calls 7

mockedMaxWaitTimeFunction · 0.85
copyKVPairFunction · 0.85
AddMethod · 0.65
BeforeMethod · 0.65
AfterMethod · 0.65
ContextMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected