Skip to content

Commit b2e700e

Browse files
committed
Add more test cases calling FindAtOrAfter()
Check it works after slice and unmarshal, and check it fails when you seek off the end of the chunk. Signed-off-by: Bryan Boreham <bryan@weave.works> fix test
1 parent 87face4 commit b2e700e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pkg/chunk/encoding/bigchunk_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ func TestSliceBiggerChunk(t *testing.T) {
5555
require.Equal(t, sample.Value, model.SampleValue(j))
5656
require.True(t, iter.Scan())
5757
}
58+
59+
// Now try via seek
60+
iter = s.NewIterator(iter)
61+
require.True(t, iter.FindAtOrAfter(model.Time(i*step)))
62+
sample := iter.Value()
63+
require.Equal(t, sample.Timestamp, model.Time(i*step))
64+
require.Equal(t, sample.Value, model.SampleValue(i))
5865
}
5966
}
6067

pkg/chunk/encoding/chunk_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ func testChunkEncoding(t *testing.T, encoding Encoding, samples int) {
131131
require.False(t, iter.Scan())
132132
require.NoError(t, iter.Err())
133133

134+
// Check seek works after unmarshal
135+
iter = chunk.NewIterator(iter)
136+
for i := 0; i < samples; i += samples / 10 {
137+
require.True(t, iter.FindAtOrAfter(model.Time(i*step)))
138+
}
139+
134140
// Check the byte representation after another Marshall is the same.
135141
buf = bytes.Buffer{}
136142
err = chunk.Marshal(&buf)
@@ -170,6 +176,8 @@ func testChunkSeek(t *testing.T, encoding Encoding, samples int) {
170176
require.False(t, iter.Scan())
171177
require.NoError(t, iter.Err())
172178
}
179+
// Check seek past the end of the chunk returns failure
180+
require.False(t, iter.FindAtOrAfter(model.Time(samples*step+1)))
173181
}
174182

175183
func testChunkSeekForward(t *testing.T, encoding Encoding, samples int) {

0 commit comments

Comments
 (0)