MCPcopy
hub / github.com/grafana/tempo / newMockReader

Function newMockReader

tempodb/blocklist/poller_test.go:1388–1442  ·  view source on GitHub ↗
(list PerTenant, compactedList PerTenantCompacted, expectsError bool)

Source from the content-addressed store, hash-verified

1386}
1387
1388func newMockReader(list PerTenant, compactedList PerTenantCompacted, expectsError bool) backend.Reader {
1389 tenants := []string{}
1390 ttt := make(map[string]bool)
1391
1392 for t := range list {
1393 ttt[t] = true
1394 }
1395 for t := range compactedList {
1396 ttt[t] = true
1397 }
1398
1399 for k := range ttt {
1400 tenants = append(tenants, k)
1401 }
1402
1403 return &backend.MockReader{
1404 T: tenants,
1405 BlocksFn: func(_ context.Context, tenantID string) ([]uuid.UUID, []uuid.UUID, error) {
1406 if expectsError {
1407 return nil, nil, errors.New("err")
1408 }
1409 blocks := list[tenantID]
1410 uuids := []uuid.UUID{}
1411 compactedUUIDs := []uuid.UUID{}
1412 for _, b := range blocks {
1413 uuids = append(uuids, (uuid.UUID)(b.BlockID))
1414 }
1415 compactedBlocks := compactedList[tenantID]
1416 for _, b := range compactedBlocks {
1417 compactedUUIDs = append(compactedUUIDs, (uuid.UUID)(b.BlockID))
1418 }
1419
1420 return uuids, compactedUUIDs, nil
1421 },
1422 BlockMetaCalls: make(map[string]map[uuid.UUID]int),
1423 BlockMetaFn: func(_ context.Context, blockID uuid.UUID, tenantID string) (*backend.BlockMeta, error) {
1424 if expectsError {
1425 return nil, errors.New("err")
1426 }
1427
1428 l, ok := list[tenantID]
1429 if !ok {
1430 return nil, backend.ErrDoesNotExist
1431 }
1432
1433 for _, m := range l {
1434 if (uuid.UUID)(m.BlockID) == blockID {
1435 return m, nil
1436 }
1437 }
1438
1439 return nil, backend.ErrDoesNotExist
1440 },
1441 }
1442}
1443
1444func newBlocklist(metas PerTenant, compactedMetas PerTenantCompacted) *List {
1445 l := New()

Callers 5

TestTenantIndexBuilderFunction · 0.85
TestTenantIndexFallbackFunction · 0.85
TestPollBlockFunction · 0.85
BenchmarkPoller10kFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected