mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 05:04:05 -08:00
Tests: use replacement DeepEquals in more places
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
d0dee51aac
commit
17f48f2b3b
|
@ -22,6 +22,7 @@ import (
|
|||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
)
|
||||
|
||||
func TestRelabel(t *testing.T) {
|
||||
|
@ -591,7 +592,7 @@ func TestRelabel(t *testing.T) {
|
|||
res, keep := Process(test.input, test.relabel...)
|
||||
require.Equal(t, !test.drop, keep)
|
||||
if keep {
|
||||
require.Equal(t, test.output, res)
|
||||
testutil.RequireEqual(t, test.output, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
|
||||
"github.com/prometheus/prometheus/model/exemplar"
|
||||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
)
|
||||
|
||||
func TestOpenMetricsParse(t *testing.T) {
|
||||
|
@ -268,12 +269,12 @@ foo_total 17.0 1520879607.789 # {id="counter-test"} 5`
|
|||
require.Equal(t, exp[i].m, string(m))
|
||||
require.Equal(t, exp[i].t, ts)
|
||||
require.Equal(t, exp[i].v, v)
|
||||
require.Equal(t, exp[i].lset, res)
|
||||
testutil.RequireEqual(t, exp[i].lset, res)
|
||||
if exp[i].e == nil {
|
||||
require.False(t, found)
|
||||
} else {
|
||||
require.True(t, found)
|
||||
require.Equal(t, *exp[i].e, e)
|
||||
testutil.RequireEqual(t, *exp[i].e, e)
|
||||
}
|
||||
|
||||
case EntryType:
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
)
|
||||
|
||||
func TestPromParse(t *testing.T) {
|
||||
|
@ -191,7 +192,7 @@ testmetric{label="\"bar\""} 1`
|
|||
require.Equal(t, exp[i].m, string(m))
|
||||
require.Equal(t, exp[i].t, ts)
|
||||
require.Equal(t, exp[i].v, v)
|
||||
require.Equal(t, exp[i].lset, res)
|
||||
testutil.RequireEqual(t, exp[i].lset, res)
|
||||
|
||||
case EntryType:
|
||||
m, typ := p.Type()
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/prometheus/prometheus/model/exemplar"
|
||||
"github.com/prometheus/prometheus/model/histogram"
|
||||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
|
||||
dto "github.com/prometheus/prometheus/prompb/io/prometheus/client"
|
||||
)
|
||||
|
@ -1993,12 +1994,12 @@ func TestProtobufParse(t *testing.T) {
|
|||
require.Equal(t, int64(0), exp[i].t, "i: %d", i)
|
||||
}
|
||||
require.Equal(t, exp[i].v, v, "i: %d", i)
|
||||
require.Equal(t, exp[i].lset, res, "i: %d", i)
|
||||
testutil.RequireEqual(t, exp[i].lset, res, "i: %d", i)
|
||||
if len(exp[i].e) == 0 {
|
||||
require.False(t, eFound, "i: %d", i)
|
||||
} else {
|
||||
require.True(t, eFound, "i: %d", i)
|
||||
require.Equal(t, exp[i].e[0], e, "i: %d", i)
|
||||
testutil.RequireEqual(t, exp[i].e[0], e, "i: %d", i)
|
||||
require.False(t, p.Exemplar(&e), "too many exemplars returned, i: %d", i)
|
||||
}
|
||||
if exp[i].ct != 0 {
|
||||
|
@ -2017,7 +2018,7 @@ func TestProtobufParse(t *testing.T) {
|
|||
} else {
|
||||
require.Equal(t, int64(0), exp[i].t, "i: %d", i)
|
||||
}
|
||||
require.Equal(t, exp[i].lset, res, "i: %d", i)
|
||||
testutil.RequireEqual(t, exp[i].lset, res, "i: %d", i)
|
||||
require.Equal(t, exp[i].m, string(m), "i: %d", i)
|
||||
if shs != nil {
|
||||
require.Equal(t, exp[i].shs, shs, "i: %d", i)
|
||||
|
@ -2026,7 +2027,7 @@ func TestProtobufParse(t *testing.T) {
|
|||
}
|
||||
j := 0
|
||||
for e := (exemplar.Exemplar{}); p.Exemplar(&e); j++ {
|
||||
require.Equal(t, exp[i].e[j], e, "i: %d", i)
|
||||
testutil.RequireEqual(t, exp[i].e[j], e, "i: %d", i)
|
||||
e = exemplar.Exemplar{}
|
||||
}
|
||||
require.Len(t, exp[i].e, j, "not enough exemplars found, i: %d", i)
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
"github.com/prometheus/prometheus/model/histogram"
|
||||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
|
||||
"github.com/prometheus/prometheus/promql/parser/posrange"
|
||||
)
|
||||
|
@ -4018,7 +4019,7 @@ func TestParseSeries(t *testing.T) {
|
|||
|
||||
if !test.fail {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, test.expectedMetric, metric, "error on input '%s'", test.input)
|
||||
testutil.RequireEqual(t, test.expectedMetric, metric, "error on input '%s'", test.input)
|
||||
require.Equal(t, test.expectedValues, vals, "error in input '%s'", test.input)
|
||||
} else {
|
||||
require.Error(t, err)
|
||||
|
|
|
@ -719,7 +719,7 @@ func TestSendAlertsDontAffectActiveAlerts(t *testing.T) {
|
|||
|
||||
// The relabel rule changes a1=1 to a1=bug.
|
||||
// But the labels with the AlertingRule should not be changed.
|
||||
require.Equal(t, labels.FromStrings("a1", "1"), rule.active[h].Labels)
|
||||
testutil.RequireEqual(t, labels.FromStrings("a1", "1"), rule.active[h].Labels)
|
||||
}
|
||||
|
||||
func TestKeepFiringFor(t *testing.T) {
|
||||
|
|
|
@ -40,6 +40,7 @@ import (
|
|||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/model/relabel"
|
||||
"github.com/prometheus/prometheus/util/runutil"
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
)
|
||||
|
||||
func TestPopulateLabels(t *testing.T) {
|
||||
|
@ -449,8 +450,8 @@ func TestPopulateLabels(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
}
|
||||
require.Equal(t, c.in, in)
|
||||
require.Equal(t, c.res, res)
|
||||
require.Equal(t, c.resOrig, orig)
|
||||
testutil.RequireEqual(t, c.res, res)
|
||||
testutil.RequireEqual(t, c.resOrig, orig)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ import (
|
|||
"github.com/prometheus/prometheus/scrape"
|
||||
"github.com/prometheus/prometheus/tsdb/chunks"
|
||||
"github.com/prometheus/prometheus/tsdb/record"
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
)
|
||||
|
||||
const defaultFlushDeadline = 1 * time.Minute
|
||||
|
@ -1077,7 +1078,7 @@ func TestProcessExternalLabels(t *testing.T) {
|
|||
} {
|
||||
b.Reset(tc.labels)
|
||||
processExternalLabels(b, tc.externalLabels)
|
||||
require.Equal(t, tc.expected, b.Labels(), "test %d", i)
|
||||
testutil.RequireEqual(t, tc.expected, b.Labels(), "test %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/prompb"
|
||||
"github.com/prometheus/prometheus/util/annotations"
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
)
|
||||
|
||||
func TestNoDuplicateReadConfigs(t *testing.T) {
|
||||
|
@ -484,7 +485,7 @@ func TestSampleAndChunkQueryableClient(t *testing.T) {
|
|||
got = append(got, ss.At().Labels())
|
||||
}
|
||||
require.NoError(t, ss.Err())
|
||||
require.Equal(t, tc.expectedSeries, got)
|
||||
testutil.RequireEqual(t, tc.expectedSeries, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/prometheus/prometheus/model/exemplar"
|
||||
|
@ -35,6 +36,7 @@ import (
|
|||
"github.com/prometheus/prometheus/prompb"
|
||||
"github.com/prometheus/prometheus/storage"
|
||||
"github.com/prometheus/prometheus/tsdb"
|
||||
"github.com/prometheus/prometheus/util/testutil"
|
||||
)
|
||||
|
||||
func TestRemoteWriteHandler(t *testing.T) {
|
||||
|
@ -59,23 +61,23 @@ func TestRemoteWriteHandler(t *testing.T) {
|
|||
for _, ts := range writeRequestFixture.Timeseries {
|
||||
labels := labelProtosToLabels(ts.Labels)
|
||||
for _, s := range ts.Samples {
|
||||
require.Equal(t, mockSample{labels, s.Timestamp, s.Value}, appendable.samples[i])
|
||||
requireEqual(t, mockSample{labels, s.Timestamp, s.Value}, appendable.samples[i])
|
||||
i++
|
||||
}
|
||||
|
||||
for _, e := range ts.Exemplars {
|
||||
exemplarLabels := labelProtosToLabels(e.Labels)
|
||||
require.Equal(t, mockExemplar{labels, exemplarLabels, e.Timestamp, e.Value}, appendable.exemplars[j])
|
||||
requireEqual(t, mockExemplar{labels, exemplarLabels, e.Timestamp, e.Value}, appendable.exemplars[j])
|
||||
j++
|
||||
}
|
||||
|
||||
for _, hp := range ts.Histograms {
|
||||
if hp.IsFloatHistogram() {
|
||||
fh := FloatHistogramProtoToFloatHistogram(hp)
|
||||
require.Equal(t, mockHistogram{labels, hp.Timestamp, nil, fh}, appendable.histograms[k])
|
||||
requireEqual(t, mockHistogram{labels, hp.Timestamp, nil, fh}, appendable.histograms[k])
|
||||
} else {
|
||||
h := HistogramProtoToHistogram(hp)
|
||||
require.Equal(t, mockHistogram{labels, hp.Timestamp, h, nil}, appendable.histograms[k])
|
||||
requireEqual(t, mockHistogram{labels, hp.Timestamp, h, nil}, appendable.histograms[k])
|
||||
}
|
||||
|
||||
k++
|
||||
|
@ -293,6 +295,13 @@ type mockHistogram struct {
|
|||
fh *histogram.FloatHistogram
|
||||
}
|
||||
|
||||
// Wrapper to instruct go-cmp package to compare a list of structs with unexported fields.
|
||||
func requireEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) {
|
||||
testutil.RequireEqualWithOptions(t, expected, actual,
|
||||
[]cmp.Option{cmp.AllowUnexported(mockSample{}), cmp.AllowUnexported(mockExemplar{}), cmp.AllowUnexported(mockHistogram{})},
|
||||
msgAndArgs...)
|
||||
}
|
||||
|
||||
func (m *mockAppendable) Appender(_ context.Context) storage.Appender {
|
||||
return m
|
||||
}
|
||||
|
|
|
@ -205,7 +205,7 @@ func TestIndexRW_Postings(t *testing.T) {
|
|||
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, c)
|
||||
require.Equal(t, series[i], builder.Labels())
|
||||
testutil.RequireEqual(t, series[i], builder.Labels())
|
||||
}
|
||||
require.NoError(t, p.Err())
|
||||
|
||||
|
@ -488,7 +488,7 @@ func TestPersistence_index_e2e(t *testing.T) {
|
|||
|
||||
err = mi.Series(expp.At(), &eBuilder, &expchks)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, eBuilder.Labels(), builder.Labels())
|
||||
testutil.RequireEqual(t, eBuilder.Labels(), builder.Labels())
|
||||
require.Equal(t, expchks, chks)
|
||||
}
|
||||
require.False(t, expp.Next(), "Expected no more postings for %q=%q", p.Name, p.Value)
|
||||
|
|
Loading…
Reference in a new issue