mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Add msg parameter to Equals function in testutil (#398)
* Add msg parameter to Equals function in testutil Co-authored-by: Chris Marchbanks <csmarchbanks@gmail.com> Signed-off-by: Camille Janicki <camille.janicki@gmail.com>
This commit is contained in:
parent
3fd6d2f920
commit
0ce41118ed
|
@ -58,10 +58,21 @@ func NotOk(tb testing.TB, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equals fails the test if exp is not equal to act.
|
// Equals fails the test if exp is not equal to act.
|
||||||
func Equals(tb testing.TB, exp, act interface{}) {
|
func Equals(tb testing.TB, exp, act interface{}, msgAndArgs ...interface{}) {
|
||||||
if !reflect.DeepEqual(exp, act) {
|
if !reflect.DeepEqual(exp, act) {
|
||||||
_, file, line, _ := runtime.Caller(1)
|
_, file, line, _ := runtime.Caller(1)
|
||||||
fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act)
|
fmt.Printf("\033[31m%s:%d:%s\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, formatMessage(msgAndArgs), exp, act)
|
||||||
tb.FailNow()
|
tb.FailNow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func formatMessage(msgAndArgs []interface{}) string {
|
||||||
|
if len(msgAndArgs) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if msg, ok := msgAndArgs[0].(string); ok {
|
||||||
|
return fmt.Sprintf("\n\nmsg: "+msg, msgAndArgs[1:]...)
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ func TestReader(t *testing.T) {
|
||||||
if j >= len(c.exp) {
|
if j >= len(c.exp) {
|
||||||
t.Fatal("received more records than inserted")
|
t.Fatal("received more records than inserted")
|
||||||
}
|
}
|
||||||
testutil.Equals(t, c.exp[j], rec)
|
testutil.Equals(t, c.exp[j], rec, "Bytes within record did not match expected Bytes")
|
||||||
}
|
}
|
||||||
if !c.fail && r.Err() != nil {
|
if !c.fail && r.Err() != nil {
|
||||||
t.Fatalf("unexpected error: %s", r.Err())
|
t.Fatalf("unexpected error: %s", r.Err())
|
||||||
|
@ -256,6 +256,7 @@ func TestWAL_Repair(t *testing.T) {
|
||||||
// We create 3 segments with 3 records each and then corrupt the 2nd record
|
// We create 3 segments with 3 records each and then corrupt the 2nd record
|
||||||
// of the 2nd segment.
|
// of the 2nd segment.
|
||||||
// As a result we want a repaired WAL with the first 4 records intact.
|
// As a result we want a repaired WAL with the first 4 records intact.
|
||||||
|
intactRecords := 4
|
||||||
w, err := NewSize(nil, nil, dir, 3*pageSize)
|
w, err := NewSize(nil, nil, dir, 3*pageSize)
|
||||||
testutil.Ok(t, err)
|
testutil.Ok(t, err)
|
||||||
|
|
||||||
|
@ -306,7 +307,7 @@ func TestWAL_Repair(t *testing.T) {
|
||||||
result = append(result, append(b, r.Record()...))
|
result = append(result, append(b, r.Record()...))
|
||||||
}
|
}
|
||||||
testutil.Ok(t, r.Err())
|
testutil.Ok(t, r.Err())
|
||||||
testutil.Equals(t, 4, len(result))
|
testutil.Equals(t, intactRecords, len(result), "Wrong number of intact records")
|
||||||
|
|
||||||
for i, r := range result {
|
for i, r := range result {
|
||||||
if !bytes.Equal(records[i], r) {
|
if !bytes.Equal(records[i], r) {
|
||||||
|
|
Loading…
Reference in a new issue