github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/storage/stores/indexshipper/uploads/testutil.go (about) 1 package uploads 2 3 import ( 4 "fmt" 5 "io" 6 "os" 7 "path/filepath" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 type mockIndex struct { 14 *os.File 15 } 16 17 func newMockIndex(t *testing.T, path string) *mockIndex { 18 fl, err := os.Create(path) 19 require.NoError(t, err) 20 return &mockIndex{fl} 21 } 22 23 func (m *mockIndex) Name() string { 24 return filepath.Base(m.File.Name()) 25 } 26 27 func (m *mockIndex) Path() string { 28 return m.File.Name() 29 } 30 31 func (m *mockIndex) Reader() (io.ReadSeeker, error) { 32 return m.File, nil 33 } 34 35 func buildTestIndexes(t *testing.T, path string, numIndexes int) map[string]*mockIndex { 36 testIndexes := make(map[string]*mockIndex) 37 for i := 0; i < numIndexes; i++ { 38 fileName := fmt.Sprintf("index-%d", i) 39 indexPath := filepath.Join(path, fileName) 40 41 index := newMockIndex(t, indexPath) 42 _, err := index.WriteString(fileName) 43 require.NoError(t, err) 44 45 testIndexes[indexPath] = index 46 } 47 48 return testIndexes 49 }