use test utils in buffer_test

This commit is contained in:
Callum Styan 2017-12-06 17:15:02 -08:00
parent ef99a94ffe
commit 2ad78b3e51

View file

@ -5,7 +5,7 @@ import (
"sort" "sort"
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/prometheus/tsdb/testutil"
) )
func TestSampleRing(t *testing.T) { func TestSampleRing(t *testing.T) {
@ -79,12 +79,12 @@ func TestBufferedSeriesIterator(t *testing.T) {
t, v := bit.At() t, v := bit.At()
b = append(b, sample{t: t, v: v}) b = append(b, sample{t: t, v: v})
} }
require.Equal(t, exp, b, "buffer mismatch") testutil.Equals(t, exp, b)
} }
sampleEq := func(ets int64, ev float64) { sampleEq := func(ets int64, ev float64) {
ts, v := it.At() ts, v := it.At()
require.Equal(t, ets, ts, "timestamp mismatch") testutil.Equals(t, ets, ts)
require.Equal(t, ev, v, "value mismatch") testutil.Equals(t, ev, v)
} }
it = NewBuffer(newListSeriesIterator([]sample{ it = NewBuffer(newListSeriesIterator([]sample{
@ -98,29 +98,29 @@ func TestBufferedSeriesIterator(t *testing.T) {
{t: 101, v: 10}, {t: 101, v: 10},
}), 2) }), 2)
require.True(t, it.Seek(-123), "seek failed") testutil.Assert(t, it.Seek(-123) == true, "seek failed")
sampleEq(1, 2) sampleEq(1, 2)
bufferEq(nil) bufferEq(nil)
require.True(t, it.Next(), "next failed") testutil.Assert(t, it.Next() == true, "next failed")
sampleEq(2, 3) sampleEq(2, 3)
bufferEq([]sample{{t: 1, v: 2}}) bufferEq([]sample{{t: 1, v: 2}})
require.True(t, it.Next(), "next failed") testutil.Assert(t, it.Next() == true, "next failed")
require.True(t, it.Next(), "next failed") testutil.Assert(t, it.Next() == true, "next failed")
require.True(t, it.Next(), "next failed") testutil.Assert(t, it.Next() == true, "next failed")
sampleEq(5, 6) sampleEq(5, 6)
bufferEq([]sample{{t: 2, v: 3}, {t: 3, v: 4}, {t: 4, v: 5}}) bufferEq([]sample{{t: 2, v: 3}, {t: 3, v: 4}, {t: 4, v: 5}})
require.True(t, it.Seek(5), "seek failed") testutil.Assert(t, it.Seek(5) == true, "seek failed")
sampleEq(5, 6) sampleEq(5, 6)
bufferEq([]sample{{t: 2, v: 3}, {t: 3, v: 4}, {t: 4, v: 5}}) bufferEq([]sample{{t: 2, v: 3}, {t: 3, v: 4}, {t: 4, v: 5}})
require.True(t, it.Seek(101), "seek failed") testutil.Assert(t, it.Seek(101) == true, "seek failed")
sampleEq(101, 10) sampleEq(101, 10)
bufferEq([]sample{{t: 99, v: 8}, {t: 100, v: 9}}) bufferEq([]sample{{t: 99, v: 8}, {t: 100, v: 9}})
require.False(t, it.Next(), "next succeeded unexpectedly") testutil.Assert(t, it.Next() == false, "next succeeded unexpectedly")
} }
type listSeriesIterator struct { type listSeriesIterator struct {