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"
"testing"
"github.com/stretchr/testify/require"
"github.com/prometheus/tsdb/testutil"
)
func TestSampleRing(t *testing.T) {
@ -79,12 +79,12 @@ func TestBufferedSeriesIterator(t *testing.T) {
t, v := bit.At()
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) {
ts, v := it.At()
require.Equal(t, ets, ts, "timestamp mismatch")
require.Equal(t, ev, v, "value mismatch")
testutil.Equals(t, ets, ts)
testutil.Equals(t, ev, v)
}
it = NewBuffer(newListSeriesIterator([]sample{
@ -98,29 +98,29 @@ func TestBufferedSeriesIterator(t *testing.T) {
{t: 101, v: 10},
}), 2)
require.True(t, it.Seek(-123), "seek failed")
testutil.Assert(t, it.Seek(-123) == true, "seek failed")
sampleEq(1, 2)
bufferEq(nil)
require.True(t, it.Next(), "next failed")
testutil.Assert(t, it.Next() == true, "next failed")
sampleEq(2, 3)
bufferEq([]sample{{t: 1, v: 2}})
require.True(t, it.Next(), "next failed")
require.True(t, it.Next(), "next failed")
require.True(t, it.Next(), "next failed")
testutil.Assert(t, it.Next() == true, "next failed")
testutil.Assert(t, it.Next() == true, "next failed")
testutil.Assert(t, it.Next() == true, "next failed")
sampleEq(5, 6)
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)
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)
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 {