Merge pull request #71 from Gouthamve/tests

Fix #59
This commit is contained in:
Fabian Reinartz 2017-05-01 11:46:16 +02:00 committed by GitHub
commit 085991c9da
2 changed files with 62 additions and 2 deletions

View file

@ -413,13 +413,14 @@ func (s *populatedChunkSeries) Next() bool {
for s.set.Next() {
lset, chks := s.set.At()
from := -1
for i, c := range chks {
if c.MaxTime < s.mint {
chks = chks[1:]
from = i
continue
}
if c.MinTime > s.maxt {
chks = chks[:i]
chks = chks[from+1 : i]
break
}
c.Chunk, s.err = s.chunks.Chunk(c.Ref)

View file

@ -851,3 +851,62 @@ func TestSeriesIterator(t *testing.T) {
return
}
func TestPopulatedCSReturnsValidChunkSlice(t *testing.T) {
lbls := []labels.Labels{labels.New(labels.Label{"a", "b"})}
chunkMetas := [][]*ChunkMeta{
{
{MinTime: 1, MaxTime: 2, Ref: 1},
{MinTime: 3, MaxTime: 4, Ref: 2},
{MinTime: 10, MaxTime: 12, Ref: 3},
},
}
cr := mockChunkReader(
map[uint64]chunks.Chunk{
1: chunks.NewXORChunk(),
2: chunks.NewXORChunk(),
3: chunks.NewXORChunk(),
},
)
m := &mockChunkSeriesSet{l: lbls, cm: chunkMetas, i: -1}
p := &populatedChunkSeries{
set: m,
chunks: cr,
mint: 0,
maxt: 0,
}
require.False(t, p.Next())
p.mint = 6
p.maxt = 9
require.False(t, p.Next())
return
}
type mockChunkSeriesSet struct {
l []labels.Labels
cm [][]*ChunkMeta
i int
}
func (m *mockChunkSeriesSet) Next() bool {
if len(m.l) != len(m.cm) {
return false
}
m.i++
return m.i < len(m.l)
}
func (m *mockChunkSeriesSet) At() (labels.Labels, []*ChunkMeta) {
return m.l[m.i], m.cm[m.i]
}
func (m *mockChunkSeriesSet) Err() error {
return nil
}