Tests: use replacement DeepEquals using go-cmp

Use DeepEqual replacement using go-cmp, which is more flexible.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
pull/13452/head
Bryan Boreham 2023-04-16 14:13:31 +02:00
parent d77c30102e
commit 39af788dbd
15 changed files with 65 additions and 44 deletions

View File

@ -26,6 +26,7 @@ import (
"github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb" "github.com/prometheus/prometheus/tsdb"
"github.com/prometheus/prometheus/tsdb/chunkenc" "github.com/prometheus/prometheus/tsdb/chunkenc"
"github.com/prometheus/prometheus/util/testutil"
) )
type backfillSample struct { type backfillSample struct {
@ -76,7 +77,7 @@ func testBlocks(t *testing.T, db *tsdb.DB, expectedMinTime, expectedMaxTime, exp
allSamples := queryAllSeries(t, q, expectedMinTime, expectedMaxTime) allSamples := queryAllSeries(t, q, expectedMinTime, expectedMaxTime)
sortSamples(allSamples) sortSamples(allSamples)
sortSamples(expectedSamples) sortSamples(expectedSamples)
require.Equal(t, expectedSamples, allSamples, "did not create correct samples") testutil.RequireEqual(t, expectedSamples, allSamples, "did not create correct samples")
if len(allSamples) > 0 { if len(allSamples) > 0 {
require.Equal(t, expectedMinTime, allSamples[0].Timestamp, "timestamp of first sample is not the expected minimum time") require.Equal(t, expectedMinTime, allSamples[0].Timestamp, "timestamp of first sample is not the expected minimum time")

View File

@ -23,6 +23,7 @@ import (
"github.com/prometheus/prometheus/discovery/targetgroup" "github.com/prometheus/prometheus/discovery/targetgroup"
"github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/relabel" "github.com/prometheus/prometheus/model/relabel"
"github.com/prometheus/prometheus/util/testutil"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -69,5 +70,5 @@ func TestSDCheckResult(t *testing.T) {
}, },
} }
require.Equal(t, expectedSDCheckResult, getSDCheckResult(targetGroups, scrapeConfig, true)) testutil.RequireEqual(t, expectedSDCheckResult, getSDCheckResult(targetGroups, scrapeConfig, true))
} }

View File

@ -58,6 +58,7 @@ import (
"github.com/prometheus/prometheus/discovery/zookeeper" "github.com/prometheus/prometheus/discovery/zookeeper"
"github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/relabel" "github.com/prometheus/prometheus/model/relabel"
"github.com/prometheus/prometheus/util/testutil"
) )
func mustParseURL(u string) *config.URL { func mustParseURL(u string) *config.URL {
@ -2037,16 +2038,16 @@ func TestExpandExternalLabels(t *testing.T) {
c, err := LoadFile("testdata/external_labels.good.yml", false, false, log.NewNopLogger()) c, err := LoadFile("testdata/external_labels.good.yml", false, false, log.NewNopLogger())
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, labels.FromStrings("bar", "foo", "baz", "foo${TEST}bar", "foo", "${TEST}", "qux", "foo$${TEST}", "xyz", "foo$$bar"), c.GlobalConfig.ExternalLabels) testutil.RequireEqual(t, labels.FromStrings("bar", "foo", "baz", "foo${TEST}bar", "foo", "${TEST}", "qux", "foo$${TEST}", "xyz", "foo$$bar"), c.GlobalConfig.ExternalLabels)
c, err = LoadFile("testdata/external_labels.good.yml", false, true, log.NewNopLogger()) c, err = LoadFile("testdata/external_labels.good.yml", false, true, log.NewNopLogger())
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, labels.FromStrings("bar", "foo", "baz", "foobar", "foo", "", "qux", "foo${TEST}", "xyz", "foo$bar"), c.GlobalConfig.ExternalLabels) testutil.RequireEqual(t, labels.FromStrings("bar", "foo", "baz", "foobar", "foo", "", "qux", "foo${TEST}", "xyz", "foo$bar"), c.GlobalConfig.ExternalLabels)
os.Setenv("TEST", "TestValue") os.Setenv("TEST", "TestValue")
c, err = LoadFile("testdata/external_labels.good.yml", false, true, log.NewNopLogger()) c, err = LoadFile("testdata/external_labels.good.yml", false, true, log.NewNopLogger())
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, labels.FromStrings("bar", "foo", "baz", "fooTestValuebar", "foo", "TestValue", "qux", "foo${TEST}", "xyz", "foo$bar"), c.GlobalConfig.ExternalLabels) testutil.RequireEqual(t, labels.FromStrings("bar", "foo", "baz", "fooTestValuebar", "foo", "TestValue", "qux", "foo${TEST}", "xyz", "foo$bar"), c.GlobalConfig.ExternalLabels)
} }
func TestAgentMode(t *testing.T) { func TestAgentMode(t *testing.T) {

View File

@ -38,6 +38,7 @@ import (
"github.com/prometheus/prometheus/util/annotations" "github.com/prometheus/prometheus/util/annotations"
"github.com/prometheus/prometheus/util/stats" "github.com/prometheus/prometheus/util/stats"
"github.com/prometheus/prometheus/util/teststorage" "github.com/prometheus/prometheus/util/teststorage"
"github.com/prometheus/prometheus/util/testutil"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
@ -1631,7 +1632,7 @@ load 1ms
sort.Sort(expMat) sort.Sort(expMat)
sort.Sort(res.Value.(Matrix)) sort.Sort(res.Value.(Matrix))
} }
require.Equal(t, c.result, res.Value, "query %q failed", c.query) testutil.RequireEqual(t, c.result, res.Value, "query %q failed", c.query)
}) })
} }
} }
@ -1956,7 +1957,7 @@ func TestSubquerySelector(t *testing.T) {
require.Equal(t, c.Result.Err, res.Err) require.Equal(t, c.Result.Err, res.Err)
mat := res.Value.(Matrix) mat := res.Value.(Matrix)
sort.Sort(mat) sort.Sort(mat)
require.Equal(t, c.Result.Value, mat) testutil.RequireEqual(t, c.Result.Value, mat)
}) })
} }
}) })
@ -2001,7 +2002,7 @@ load 1m
res := qry.Exec(context.Background()) res := qry.Exec(context.Background())
require.NoError(t, res.Err) require.NoError(t, res.Err)
require.Equal(t, expectedResult, res.Value) testutil.RequireEqual(t, expectedResult, res.Value)
} }
type FakeQueryLogger struct { type FakeQueryLogger struct {
@ -3147,7 +3148,7 @@ func TestRangeQuery(t *testing.T) {
res := qry.Exec(context.Background()) res := qry.Exec(context.Background())
require.NoError(t, res.Err) require.NoError(t, res.Err)
require.Equal(t, c.Result, res.Value) testutil.RequireEqual(t, c.Result, res.Value)
}) })
} }
} }
@ -4347,7 +4348,7 @@ func TestNativeHistogram_Sum_Count_Add_AvgOperator(t *testing.T) {
vector, err := res.Vector() vector, err := res.Vector()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, exp, vector) testutil.RequireEqual(t, exp, vector)
} }
// sum(). // sum().
@ -4605,7 +4606,7 @@ func TestNativeHistogram_SubOperator(t *testing.T) {
} }
} }
require.Equal(t, exp, vector) testutil.RequireEqual(t, exp, vector)
} }
// - operator. // - operator.
@ -4753,7 +4754,7 @@ func TestNativeHistogram_MulDivOperator(t *testing.T) {
vector, err := res.Vector() vector, err := res.Vector()
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, exp, vector) testutil.RequireEqual(t, exp, vector)
} }
// histogram * scalar. // histogram * scalar.

View File

@ -31,6 +31,7 @@ import (
"github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/promql/parser"
"github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/util/teststorage" "github.com/prometheus/prometheus/util/teststorage"
"github.com/prometheus/prometheus/util/testutil"
) )
var testEngine = promql.NewEngine(promql.EngineOpts{ var testEngine = promql.NewEngine(promql.EngineOpts{
@ -180,7 +181,7 @@ func TestAlertingRuleLabelsUpdate(t *testing.T) {
} }
} }
require.Equal(t, result, filteredRes) testutil.RequireEqual(t, result, filteredRes)
} }
evalTime := baseTime.Add(time.Duration(len(results)) * time.Minute) evalTime := baseTime.Add(time.Duration(len(results)) * time.Minute)
res, err := rule.Eval(context.TODO(), evalTime, EngineQueryFunc(testEngine, storage), nil, 0) res, err := rule.Eval(context.TODO(), evalTime, EngineQueryFunc(testEngine, storage), nil, 0)
@ -278,7 +279,7 @@ func TestAlertingRuleExternalLabelsInTemplate(t *testing.T) {
} }
} }
require.Equal(t, result, filteredRes) testutil.RequireEqual(t, result, filteredRes)
} }
func TestAlertingRuleExternalURLInTemplate(t *testing.T) { func TestAlertingRuleExternalURLInTemplate(t *testing.T) {
@ -371,7 +372,7 @@ func TestAlertingRuleExternalURLInTemplate(t *testing.T) {
} }
} }
require.Equal(t, result, filteredRes) testutil.RequireEqual(t, result, filteredRes)
} }
func TestAlertingRuleEmptyLabelFromTemplate(t *testing.T) { func TestAlertingRuleEmptyLabelFromTemplate(t *testing.T) {
@ -425,7 +426,7 @@ func TestAlertingRuleEmptyLabelFromTemplate(t *testing.T) {
require.Equal(t, "ALERTS_FOR_STATE", smplName) require.Equal(t, "ALERTS_FOR_STATE", smplName)
} }
} }
require.Equal(t, result, filteredRes) testutil.RequireEqual(t, result, filteredRes)
} }
func TestAlertingRuleQueryInTemplate(t *testing.T) { func TestAlertingRuleQueryInTemplate(t *testing.T) {
@ -823,7 +824,7 @@ func TestKeepFiringFor(t *testing.T) {
} }
} }
require.Equal(t, result, filteredRes) testutil.RequireEqual(t, result, filteredRes)
} }
evalTime := baseTime.Add(time.Duration(len(results)) * time.Minute) evalTime := baseTime.Add(time.Duration(len(results)) * time.Minute)
res, err := rule.Eval(context.TODO(), evalTime, EngineQueryFunc(testEngine, storage), nil, 0) res, err := rule.Eval(context.TODO(), evalTime, EngineQueryFunc(testEngine, storage), nil, 0)
@ -870,7 +871,7 @@ func TestPendingAndKeepFiringFor(t *testing.T) {
for _, smpl := range res { for _, smpl := range res {
smplName := smpl.Metric.Get("__name__") smplName := smpl.Metric.Get("__name__")
if smplName == "ALERTS" { if smplName == "ALERTS" {
require.Equal(t, result, smpl) testutil.RequireEqual(t, result, smpl)
} else { } else {
// If not 'ALERTS', it has to be 'ALERTS_FOR_STATE'. // If not 'ALERTS', it has to be 'ALERTS_FOR_STATE'.
require.Equal(t, "ALERTS_FOR_STATE", smplName) require.Equal(t, "ALERTS_FOR_STATE", smplName)

View File

@ -42,6 +42,7 @@ import (
"github.com/prometheus/prometheus/tsdb/chunkenc" "github.com/prometheus/prometheus/tsdb/chunkenc"
"github.com/prometheus/prometheus/tsdb/tsdbutil" "github.com/prometheus/prometheus/tsdb/tsdbutil"
"github.com/prometheus/prometheus/util/teststorage" "github.com/prometheus/prometheus/util/teststorage"
prom_testutil "github.com/prometheus/prometheus/util/testutil"
) )
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
@ -180,7 +181,7 @@ func TestAlertingRule(t *testing.T) {
sort.Slice(filteredRes, func(i, j int) bool { sort.Slice(filteredRes, func(i, j int) bool {
return labels.Compare(filteredRes[i].Metric, filteredRes[j].Metric) < 0 return labels.Compare(filteredRes[i].Metric, filteredRes[j].Metric) < 0
}) })
require.Equal(t, test.result, filteredRes) prom_testutil.RequireEqual(t, test.result, filteredRes)
for _, aa := range rule.ActiveAlerts() { for _, aa := range rule.ActiveAlerts() {
require.Zero(t, aa.Labels.Get(model.MetricNameLabel), "%s label set on active alert: %s", model.MetricNameLabel, aa.Labels) require.Zero(t, aa.Labels.Get(model.MetricNameLabel), "%s label set on active alert: %s", model.MetricNameLabel, aa.Labels)
@ -330,7 +331,7 @@ func TestForStateAddSamples(t *testing.T) {
sort.Slice(filteredRes, func(i, j int) bool { sort.Slice(filteredRes, func(i, j int) bool {
return labels.Compare(filteredRes[i].Metric, filteredRes[j].Metric) < 0 return labels.Compare(filteredRes[i].Metric, filteredRes[j].Metric) < 0
}) })
require.Equal(t, test.result, filteredRes) prom_testutil.RequireEqual(t, test.result, filteredRes)
for _, aa := range rule.ActiveAlerts() { for _, aa := range rule.ActiveAlerts() {
require.Zero(t, aa.Labels.Get(model.MetricNameLabel), "%s label set on active alert: %s", model.MetricNameLabel, aa.Labels) require.Zero(t, aa.Labels.Get(model.MetricNameLabel), "%s label set on active alert: %s", model.MetricNameLabel, aa.Labels)

View File

@ -25,6 +25,7 @@ import (
"github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/promql/parser" "github.com/prometheus/prometheus/promql/parser"
"github.com/prometheus/prometheus/util/teststorage" "github.com/prometheus/prometheus/util/teststorage"
"github.com/prometheus/prometheus/util/testutil"
) )
var ( var (
@ -126,7 +127,7 @@ func TestRuleEval(t *testing.T) {
rule := NewRecordingRule("test_rule", scenario.expr, scenario.ruleLabels) rule := NewRecordingRule("test_rule", scenario.expr, scenario.ruleLabels)
result, err := rule.Eval(context.TODO(), ruleEvaluationTime, EngineQueryFunc(testEngine, storage), nil, 0) result, err := rule.Eval(context.TODO(), ruleEvaluationTime, EngineQueryFunc(testEngine, storage), nil, 0)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, scenario.expected, result) testutil.RequireEqual(t, scenario.expected, result)
}) })
} }
} }

View File

@ -32,6 +32,7 @@ import (
"github.com/go-kit/log" "github.com/go-kit/log"
"github.com/gogo/protobuf/proto" "github.com/gogo/protobuf/proto"
"github.com/google/go-cmp/cmp"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
config_util "github.com/prometheus/common/config" config_util "github.com/prometheus/common/config"
@ -1383,10 +1384,16 @@ func TestScrapeLoopAppend(t *testing.T) {
} }
t.Logf("Test:%s", test.title) t.Logf("Test:%s", test.title)
require.Equal(t, expected, app.resultFloats) requireEqual(t, expected, app.resultFloats)
} }
} }
func requireEqual(t *testing.T, expected, actual interface{}, msgAndArgs ...interface{}) {
testutil.RequireEqualWithOptions(t, expected, actual,
[]cmp.Option{cmp.AllowUnexported(floatSample{}), cmp.AllowUnexported(histogramSample{})},
msgAndArgs...)
}
func TestScrapeLoopAppendForConflictingPrefixedLabels(t *testing.T) { func TestScrapeLoopAppendForConflictingPrefixedLabels(t *testing.T) {
testcases := map[string]struct { testcases := map[string]struct {
targetLabels []string targetLabels []string
@ -1450,7 +1457,7 @@ func TestScrapeLoopAppendForConflictingPrefixedLabels(t *testing.T) {
require.NoError(t, slApp.Commit()) require.NoError(t, slApp.Commit())
require.Equal(t, []floatSample{ requireEqual(t, []floatSample{
{ {
metric: labels.FromStrings(tc.expected...), metric: labels.FromStrings(tc.expected...),
t: timestamp.FromTime(time.Date(2000, 1, 1, 1, 0, 0, 0, time.UTC)), t: timestamp.FromTime(time.Date(2000, 1, 1, 1, 0, 0, 0, time.UTC)),
@ -1544,7 +1551,7 @@ func TestScrapeLoopAppendSampleLimit(t *testing.T) {
f: 1, f: 1,
}, },
} }
require.Equal(t, want, resApp.rolledbackFloats, "Appended samples not as expected:\n%s", appender) requireEqual(t, want, resApp.rolledbackFloats, "Appended samples not as expected:\n%s", appender)
now = time.Now() now = time.Now()
slApp = sl.appender(context.Background()) slApp = sl.appender(context.Background())
@ -2158,9 +2165,9 @@ metric: <
_, _, _, err := sl.append(app, buf.Bytes(), test.contentType, now) _, _, _, err := sl.append(app, buf.Bytes(), test.contentType, now)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, app.Commit()) require.NoError(t, app.Commit())
require.Equal(t, test.floats, app.resultFloats) requireEqual(t, test.floats, app.resultFloats)
require.Equal(t, test.histograms, app.resultHistograms) requireEqual(t, test.histograms, app.resultHistograms)
require.Equal(t, test.exemplars, app.resultExemplars) requireEqual(t, test.exemplars, app.resultExemplars)
}) })
} }
} }
@ -2215,8 +2222,8 @@ func TestScrapeLoopAppendExemplarSeries(t *testing.T) {
require.NoError(t, app.Commit()) require.NoError(t, app.Commit())
} }
require.Equal(t, samples, app.resultFloats) requireEqual(t, samples, app.resultFloats)
require.Equal(t, exemplars, app.resultExemplars) requireEqual(t, exemplars, app.resultExemplars)
} }
func TestScrapeLoopRunReportsTargetDownOnScrapeError(t *testing.T) { func TestScrapeLoopRunReportsTargetDownOnScrapeError(t *testing.T) {
@ -2292,7 +2299,7 @@ func TestScrapeLoopAppendGracefullyIfAmendOrOutOfOrderOrOutOfBounds(t *testing.T
f: 1, f: 1,
}, },
} }
require.Equal(t, want, app.resultFloats, "Appended samples not as expected:\n%s", appender) requireEqual(t, want, app.resultFloats, "Appended samples not as expected:\n%s", appender)
require.Equal(t, 4, total) require.Equal(t, 4, total)
require.Equal(t, 4, added) require.Equal(t, 4, added)
require.Equal(t, 1, seriesAdded) require.Equal(t, 1, seriesAdded)

View File

@ -4058,11 +4058,11 @@ func TestOOOWALWrite(t *testing.T) {
// The normal WAL. // The normal WAL.
actRecs := getRecords(path.Join(dir, "wal")) actRecs := getRecords(path.Join(dir, "wal"))
require.Equal(t, inOrderRecords, actRecs) testutil.RequireEqual(t, inOrderRecords, actRecs)
// The WBL. // The WBL.
actRecs = getRecords(path.Join(dir, wlog.WblDirName)) actRecs = getRecords(path.Join(dir, wlog.WblDirName))
require.Equal(t, oooRecords, actRecs) testutil.RequireEqual(t, oooRecords, actRecs)
} }
// Tests https://github.com/prometheus/prometheus/issues/10291#issuecomment-1044373110. // Tests https://github.com/prometheus/prometheus/issues/10291#issuecomment-1044373110.

View File

@ -30,6 +30,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/google/go-cmp/cmp"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
prom_testutil "github.com/prometheus/client_golang/prometheus/testutil" prom_testutil "github.com/prometheus/client_golang/prometheus/testutil"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
@ -50,6 +51,7 @@ import (
"github.com/prometheus/prometheus/tsdb/tombstones" "github.com/prometheus/prometheus/tsdb/tombstones"
"github.com/prometheus/prometheus/tsdb/tsdbutil" "github.com/prometheus/prometheus/tsdb/tsdbutil"
"github.com/prometheus/prometheus/tsdb/wlog" "github.com/prometheus/prometheus/tsdb/wlog"
"github.com/prometheus/prometheus/util/testutil"
) )
// newTestHeadDefaultOptions returns the HeadOptions that should be used by default in unit tests. // newTestHeadDefaultOptions returns the HeadOptions that should be used by default in unit tests.
@ -3743,7 +3745,7 @@ func TestChunkSnapshot(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
// Verifies both existence of right exemplars and order of exemplars in the buffer. // Verifies both existence of right exemplars and order of exemplars in the buffer.
require.Equal(t, expExemplars, actExemplars) testutil.RequireEqualWithOptions(t, expExemplars, actExemplars, []cmp.Option{cmp.AllowUnexported(ex{})})
} }
var ( var (

View File

@ -24,6 +24,7 @@ import (
"github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/tsdb/encoding" "github.com/prometheus/prometheus/tsdb/encoding"
"github.com/prometheus/prometheus/tsdb/tombstones" "github.com/prometheus/prometheus/tsdb/tombstones"
"github.com/prometheus/prometheus/util/testutil"
) )
func TestRecord_EncodeDecode(t *testing.T) { func TestRecord_EncodeDecode(t *testing.T) {
@ -44,7 +45,7 @@ func TestRecord_EncodeDecode(t *testing.T) {
} }
decSeries, err := dec.Series(enc.Series(series, nil), nil) decSeries, err := dec.Series(enc.Series(series, nil), nil)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, series, decSeries) testutil.RequireEqual(t, series, decSeries)
metadata := []RefMetadata{ metadata := []RefMetadata{
{ {
@ -107,7 +108,7 @@ func TestRecord_EncodeDecode(t *testing.T) {
} }
decExemplars, err := dec.Exemplars(enc.Exemplars(exemplars, nil), nil) decExemplars, err := dec.Exemplars(enc.Exemplars(exemplars, nil), nil)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, exemplars, decExemplars) testutil.RequireEqual(t, exemplars, decExemplars)
histograms := []RefHistogramSample{ histograms := []RefHistogramSample{
{ {

View File

@ -34,6 +34,7 @@ import (
"github.com/prometheus/prometheus/tsdb/record" "github.com/prometheus/prometheus/tsdb/record"
"github.com/prometheus/prometheus/tsdb/tombstones" "github.com/prometheus/prometheus/tsdb/tombstones"
"github.com/prometheus/prometheus/tsdb/wlog" "github.com/prometheus/prometheus/tsdb/wlog"
"github.com/prometheus/prometheus/util/testutil"
) )
func TestSegmentWAL_cut(t *testing.T) { func TestSegmentWAL_cut(t *testing.T) {
@ -147,7 +148,7 @@ func TestSegmentWAL_Truncate(t *testing.T) {
readSeries = append(readSeries, s...) readSeries = append(readSeries, s...)
}, nil, nil)) }, nil, nil))
require.Equal(t, expected, readSeries) testutil.RequireEqual(t, expected, readSeries)
} }
// Symmetrical test of reading and writing to the WAL via its main interface. // Symmetrical test of reading and writing to the WAL via its main interface.
@ -213,9 +214,9 @@ func TestSegmentWAL_Log_Restore(t *testing.T) {
require.NoError(t, r.Read(serf, smplf, delf)) require.NoError(t, r.Read(serf, smplf, delf))
require.Equal(t, recordedSamples, resultSamples) testutil.RequireEqual(t, recordedSamples, resultSamples)
require.Equal(t, recordedSeries, resultSeries) testutil.RequireEqual(t, recordedSeries, resultSeries)
require.Equal(t, recordedDeletes, resultDeletes) testutil.RequireEqual(t, recordedDeletes, resultDeletes)
series := series[k : k+(numMetrics/iterations)] series := series[k : k+(numMetrics/iterations)]
@ -533,7 +534,7 @@ func TestMigrateWAL_Fuzz(t *testing.T) {
} }
require.NoError(t, r.Err()) require.NoError(t, r.Err())
require.Equal(t, []interface{}{ testutil.RequireEqual(t, []interface{}{
[]record.RefSeries{ []record.RefSeries{
{Ref: 100, Labels: labels.FromStrings("abc", "def", "123", "456")}, {Ref: 100, Labels: labels.FromStrings("abc", "def", "123", "456")},
{Ref: 1, Labels: labels.FromStrings("abc", "def2", "1234", "4567")}, {Ref: 1, Labels: labels.FromStrings("abc", "def2", "1234", "4567")},

View File

@ -29,6 +29,7 @@ import (
"github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/tsdb/chunks" "github.com/prometheus/prometheus/tsdb/chunks"
"github.com/prometheus/prometheus/tsdb/record" "github.com/prometheus/prometheus/tsdb/record"
"github.com/prometheus/prometheus/util/testutil"
) )
func TestLastCheckpoint(t *testing.T) { func TestLastCheckpoint(t *testing.T) {
@ -286,7 +287,7 @@ func TestCheckpoint(t *testing.T) {
{Ref: 2, Labels: labels.FromStrings("a", "b", "c", "2")}, {Ref: 2, Labels: labels.FromStrings("a", "b", "c", "2")},
{Ref: 4, Labels: labels.FromStrings("a", "b", "c", "4")}, {Ref: 4, Labels: labels.FromStrings("a", "b", "c", "4")},
} }
require.Equal(t, expectedRefSeries, series) testutil.RequireEqual(t, expectedRefSeries, series)
expectedRefMetadata := []record.RefMetadata{ expectedRefMetadata := []record.RefMetadata{
{Ref: 0, Unit: fmt.Sprintf("%d", last-100), Help: fmt.Sprintf("%d", last-100)}, {Ref: 0, Unit: fmt.Sprintf("%d", last-100), Help: fmt.Sprintf("%d", last-100)},

View File

@ -32,6 +32,7 @@ import (
"github.com/prometheus/prometheus/prompb" "github.com/prometheus/prometheus/prompb"
"github.com/prometheus/prometheus/util/stats" "github.com/prometheus/prometheus/util/stats"
"github.com/prometheus/prometheus/util/testutil"
"github.com/go-kit/log" "github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
@ -597,7 +598,7 @@ func TestGetSeries(t *testing.T) {
r := res.data.([]labels.Labels) r := res.data.([]labels.Labels)
sort.Sort(byLabels(tc.expected)) sort.Sort(byLabels(tc.expected))
sort.Sort(byLabels(r)) sort.Sort(byLabels(r))
require.Equal(t, tc.expected, r) testutil.RequireEqual(t, tc.expected, r)
} }
}) })
} }
@ -2878,7 +2879,7 @@ func assertAPIError(t *testing.T, got *apiError, exp errorType) {
func assertAPIResponse(t *testing.T, got, exp interface{}) { func assertAPIResponse(t *testing.T, got, exp interface{}) {
t.Helper() t.Helper()
require.Equal(t, exp, got) testutil.RequireEqual(t, exp, got)
} }
func assertAPIResponseLength(t *testing.T, got interface{}, expLen int) { func assertAPIResponseLength(t *testing.T, got interface{}, expLen int) {

View File

@ -37,6 +37,7 @@ import (
"github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb" "github.com/prometheus/prometheus/tsdb"
"github.com/prometheus/prometheus/util/teststorage" "github.com/prometheus/prometheus/util/teststorage"
"github.com/prometheus/prometheus/util/testutil"
) )
var scenarios = map[string]struct { var scenarios = map[string]struct {
@ -427,5 +428,5 @@ func TestFederationWithNativeHistograms(t *testing.T) {
// TODO(codesome): Once PromQL is able to set the CounterResetHint on histograms, // TODO(codesome): Once PromQL is able to set the CounterResetHint on histograms,
// test it with switching histogram types for metric families. // test it with switching histogram types for metric families.
require.Equal(t, 4, metricFamilies) require.Equal(t, 4, metricFamilies)
require.Equal(t, expVec, actVec) testutil.RequireEqual(t, expVec, actVec)
} }