github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/storage/stores/indexshipper/uploads/table_test.go (about) 1 package uploads 2 3 import ( 4 "os" 5 "path/filepath" 6 "strconv" 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 11 "github.com/grafana/loki/pkg/storage/stores/indexshipper/index" 12 ) 13 14 const ( 15 testTableName = "test-table" 16 ) 17 18 func TestTable(t *testing.T) { 19 tempDir := t.TempDir() 20 storageClient := buildTestStorageClient(t, tempDir) 21 testTable := NewTable(testTableName, storageClient) 22 defer testTable.Stop() 23 24 for userIdx := 0; userIdx < 2; userIdx++ { 25 userID := "user-" + strconv.Itoa(userIdx) 26 t.Run(userID, func(t *testing.T) { 27 userIndexPath := filepath.Join(tempDir, testTableName, userID) 28 require.NoError(t, os.MkdirAll(userIndexPath, 0755)) 29 30 // build some test indexes and add them to the table. 31 testIndexes := buildTestIndexes(t, userIndexPath, 5) 32 for _, testIndex := range testIndexes { 33 require.NoError(t, testTable.AddIndex(userID, testIndex)) 34 } 35 36 // see if we can find all the added indexes in the table. 37 indexesFound := map[string]*mockIndex{} 38 err := testTable.ForEach(userID, func(_ bool, index index.Index) error { 39 indexesFound[index.Path()] = index.(*mockIndex) 40 return nil 41 }) 42 require.NoError(t, err) 43 44 require.Equal(t, testIndexes, indexesFound) 45 }) 46 } 47 }