From 5876a3303c354ead92cb27306668eb0b16eab3cd Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Thu, 9 Mar 2017 09:39:30 +0100 Subject: [PATCH] Add test for Index postings querying --- index_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/index_test.go b/index_test.go index 7a617f899..48026b5c8 100644 --- a/index_test.go +++ b/index_test.go @@ -62,6 +62,51 @@ func TestIndexRW_Create_Open(t *testing.T) { require.Error(t, err) } +func TestIndexRW_Postings(t *testing.T) { + dir, err := ioutil.TempDir("", "test_index_postings") + require.NoError(t, err) + defer os.RemoveAll(dir) + + iw, err := newIndexWriter(dir) + require.NoError(t, err, "create index writer") + + series := []labels.Labels{ + labels.FromStrings("a", "1", "b", "1"), + labels.FromStrings("a", "1", "b", "2"), + labels.FromStrings("a", "1", "b", "3"), + labels.FromStrings("a", "1", "b", "4"), + } + + // Postings lists are only written if a series with the respective + // reference was added before. + require.NoError(t, iw.AddSeries(1, series[0])) + require.NoError(t, iw.AddSeries(3, series[2])) + require.NoError(t, iw.AddSeries(2, series[1])) + require.NoError(t, iw.AddSeries(4, series[3])) + + err = iw.WritePostings("a", "1", newListPostings([]uint32{1, 2, 3, 4})) + require.NoError(t, err) + + require.NoError(t, iw.Close()) + + ir, err := newIndexReader(dir) + require.NoError(t, err, "open index reader") + + p, err := ir.Postings("a", "1") + require.NoError(t, err) + + for i := 0; p.Next(); i++ { + l, c, err := ir.Series(p.At()) + + require.NoError(t, err) + require.Equal(t, 0, len(c)) + require.Equal(t, l, series[i]) + } + require.NoError(t, p.Err()) + + require.NoError(t, ir.Close()) +} + // func TestPersistence_index_e2e(t *testing.T) { // dir, err := ioutil.TempDir("", "test_persistence_e2e") // require.NoError(t, err)