(t *testing.T)
| 243 | } |
| 244 | |
| 245 | func TestTenantIndexFallback(t *testing.T) { |
| 246 | var ( |
| 247 | mr = &MockRawReader{} |
| 248 | r = NewReader(mr) |
| 249 | mw = &MockRawWriter{} |
| 250 | w = NewWriter(mw) |
| 251 | ctx = context.Background() |
| 252 | tenantID = "test" |
| 253 | |
| 254 | u = uuid.New() |
| 255 | meta = NewBlockMeta(tenantID, u, "blerg") |
| 256 | expectedIdx = newTenantIndex([]*BlockMeta{meta}, nil) |
| 257 | ) |
| 258 | |
| 259 | err := w.WriteTenantIndex(ctx, tenantID, []*BlockMeta{meta}, nil) |
| 260 | assert.NoError(t, err) |
| 261 | |
| 262 | mr.R, err = expectedIdx.marshal() |
| 263 | assert.NoError(t, err) |
| 264 | mr.ReadFn = func(_ context.Context, name string, _ KeyPath, _ *CacheInfo) (io.ReadCloser, int64, error) { |
| 265 | if name == TenantIndexNamePb { |
| 266 | return nil, 0, fmt.Errorf("meow: %w", ErrDoesNotExist) |
| 267 | } |
| 268 | |
| 269 | return io.NopCloser(bytes.NewReader(mr.R)), int64(len(mr.R)), nil |
| 270 | } |
| 271 | |
| 272 | idx, err := r.TenantIndex(ctx, tenantID) |
| 273 | assert.NoError(t, err) |
| 274 | assert.True(t, cmp.Equal(expectedIdx, idx)) |
| 275 | |
| 276 | // Corrupt the proto to ensure we don't fall back |
| 277 | mr.ReadFn = func(_ context.Context, name string, _ KeyPath, _ *CacheInfo) (io.ReadCloser, int64, error) { |
| 278 | if name == TenantIndexNamePb { |
| 279 | return io.NopCloser(bytes.NewReader([]byte{0x00})), int64(1), nil |
| 280 | } |
| 281 | |
| 282 | return io.NopCloser(bytes.NewReader(mr.R)), int64(len(mr.R)), nil |
| 283 | } |
| 284 | |
| 285 | idx, err = r.TenantIndex(ctx, tenantID) |
| 286 | assert.ErrorIs(t, err, io.ErrUnexpectedEOF) |
| 287 | assert.Nil(t, idx) |
| 288 | |
| 289 | // Remove all indexes and error check |
| 290 | mr.ReadFn = func(_ context.Context, _ string, _ KeyPath, _ *CacheInfo) (io.ReadCloser, int64, error) { |
| 291 | return nil, 0, fmt.Errorf("meow: %w", ErrDoesNotExist) |
| 292 | } |
| 293 | |
| 294 | idx, err = r.TenantIndex(ctx, tenantID) |
| 295 | assert.ErrorIs(t, err, ErrDoesNotExist) |
| 296 | assert.Nil(t, idx) |
| 297 | } |
| 298 | |
| 299 | func TestNoCompactFlag(t *testing.T) { |
| 300 | ctx := context.Background() |
nothing calls this directly
no test coverage detected