setupTest creates a test instance with all required dependencies
(t *testing.T)
| 34 | |
| 35 | // setupTest creates a test instance with all required dependencies |
| 36 | func setupTest(t *testing.T) *testSetup { |
| 37 | t.Helper() |
| 38 | tmpDir := t.TempDir() |
| 39 | |
| 40 | // Create overrides with a separate registry to avoid conflicts |
| 41 | registry := prometheus.NewRegistry() |
| 42 | o, err := overrides.NewOverrides(overrides.Config{}, nil, registry) |
| 43 | require.NoError(t, err) |
| 44 | |
| 45 | // Create instance |
| 46 | cfg := &Config{} |
| 47 | cfg.RegisterFlagsAndApplyDefaults("", &flag.FlagSet{}) |
| 48 | |
| 49 | // Use the default encoding for tests |
| 50 | blockEnc := encoding.DefaultEncoding() |
| 51 | |
| 52 | // Populate block config with defaults, simulating what modules.go does by injecting storage.trace.block. |
| 53 | cfg.BlockConfig.RegisterFlagsAndApplyDefaults("", &flag.FlagSet{}) |
| 54 | cfg.BlockConfig.Version = blockEnc.Version() |
| 55 | cfg.WAL.Version = blockEnc.Version() |
| 56 | |
| 57 | // Setup WAL config |
| 58 | w, err := wal.New(&wal.Config{ |
| 59 | Filepath: tmpDir, |
| 60 | Version: blockEnc.Version(), |
| 61 | }) |
| 62 | require.NoError(t, err) |
| 63 | |
| 64 | lifecycle, err := newCompleteBlockLifecycle(*cfg, noopCompleteBlockFlusher{}, log.NewNopLogger()) |
| 65 | require.NoError(t, err) |
| 66 | instance, err := newInstance(testTenant, *cfg, w, blockEnc, lifecycle, o, log.NewNopLogger()) |
| 67 | require.NoError(t, err) |
| 68 | |
| 69 | return &testSetup{ |
| 70 | tmpDir: tmpDir, |
| 71 | wal: w, |
| 72 | overrides: o, |
| 73 | instance: instance, |
| 74 | cleanup: func() {}, |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | func TestMetrics_InitialValues(t *testing.T) { |
| 79 | // Record baseline values before creating the instance. |
no test coverage detected