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

Function TestReader

tempodb/backend/raw_test.go:97–153  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

95}
96
97func TestReader(t *testing.T) {
98 m := &MockRawReader{}
99 r := NewReader(m)
100 ctx := context.Background()
101
102 expected := []byte{0x01, 0x02, 0x03, 0x04}
103 m.R = expected
104 actual, err := r.Read(ctx, "test", uuid.New(), "test", nil)
105 assert.NoError(t, err)
106 assert.Equal(t, expected, actual)
107
108 m.Range = expected
109 err = r.ReadRange(ctx, "test", uuid.New(), "test", 10, actual, nil)
110 assert.NoError(t, err)
111 assert.Equal(t, expected, actual)
112
113 expectedTenants := []string{"a", "b", "c"}
114 m.L = expectedTenants
115 actualTenants, err := r.Tenants(ctx)
116 assert.NoError(t, err)
117 assert.Equal(t, expectedTenants, actualTenants)
118
119 uuid1, uuid2, uuid3 := uuid.New(), uuid.New(), uuid.New()
120 expectedBlocks := []uuid.UUID{uuid1, uuid2}
121 expectedCompactedBlocks := []uuid.UUID{uuid3}
122
123 m.BlockIDs = append(m.BlockIDs, uuid1)
124 m.BlockIDs = append(m.BlockIDs, uuid2)
125 m.CompactedBlockIDs = append(m.CompactedBlockIDs, uuid3)
126
127 actualBlocks, actualCompactedBlocks, err := r.Blocks(ctx, "test")
128 assert.NoError(t, err)
129 assert.Equal(t, expectedBlocks, actualBlocks)
130 assert.Equal(t, expectedCompactedBlocks, actualCompactedBlocks)
131
132 // should fail b/c meta is not valid
133 meta, err := r.BlockMeta(ctx, uuid.New(), "test")
134 assert.Error(t, err)
135 assert.Nil(t, meta)
136
137 expectedMeta := NewBlockMeta("test", uuid.New(), "blerg")
138 m.R, _ = json.Marshal(expectedMeta)
139 meta, err = r.BlockMeta(ctx, uuid.New(), "test")
140 assert.NoError(t, err)
141 assert.Equal(t, expectedMeta, meta)
142
143 // should fail b/c tenant index is not valid
144 idx, err := r.TenantIndex(ctx, "test")
145 assert.Error(t, err)
146 assert.Nil(t, idx)
147
148 expectedIdx := newTenantIndex([]*BlockMeta{expectedMeta}, nil)
149 m.R, _ = expectedIdx.marshalPb()
150 idx, err = r.TenantIndex(ctx, "test")
151 assert.NoError(t, err)
152 assert.True(t, cmp.Equal(expectedIdx, idx))
153}
154

Callers

nothing calls this directly

Calls 13

ReadMethod · 0.95
ReadRangeMethod · 0.95
TenantsMethod · 0.95
BlocksMethod · 0.95
BlockMetaMethod · 0.95
TenantIndexMethod · 0.95
NewReaderFunction · 0.85
NewBlockMetaFunction · 0.85
newTenantIndexFunction · 0.85
marshalPbMethod · 0.80
ErrorMethod · 0.65
MarshalMethod · 0.65

Tested by

no test coverage detected