-
Notifications
You must be signed in to change notification settings - Fork 179
Add msg parameter to Equals function in testutil #398
Add msg parameter to Equals function in testutil #398
Conversation
yeah I would say lets add some messages so I can test it locally and see how it would look like with passing and failing tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected values should be 2nd argument (after t
). I might have missed some below.
db_test.go
Outdated
@@ -110,7 +110,7 @@ func TestDataAvailableOnlyAfterCommit(t *testing.T) { | |||
testutil.Ok(t, err) | |||
seriesSet := query(t, querier, labels.NewEqualMatcher("foo", "bar")) | |||
|
|||
testutil.Equals(t, map[string][]sample{}, seriesSet) | |||
testutil.Equals(t, seriesSet, map[string][]sample{}, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix these. It looks like my code editor swapped the values
db_test.go
Outdated
@@ -122,7 +122,7 @@ func TestDataAvailableOnlyAfterCommit(t *testing.T) { | |||
|
|||
seriesSet = query(t, querier, labels.NewEqualMatcher("foo", "bar")) | |||
|
|||
testutil.Equals(t, map[string][]sample{`{foo="bar"}`: {{t: 0, v: 0}}}, seriesSet) | |||
testutil.Equals(t, seriesSet, map[string][]sample{`{foo="bar"}`: {{t: 0, v: 0}}}, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
db_test.go
Outdated
@@ -143,7 +143,7 @@ func TestDataNotAvailableAfterRollback(t *testing.T) { | |||
|
|||
seriesSet := query(t, querier, labels.NewEqualMatcher("foo", "bar")) | |||
|
|||
testutil.Equals(t, map[string][]sample{}, seriesSet) | |||
testutil.Equals(t, seriesSet, map[string][]sample{}, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
db_test.go
Outdated
@@ -179,7 +179,7 @@ func TestDBAppenderAddRef(t *testing.T) { | |||
testutil.Ok(t, err) | |||
|
|||
err = app2.AddFast(9999999, 1, 1) | |||
testutil.Equals(t, ErrNotFound, errors.Cause(err)) | |||
testutil.Equals(t, errors.Cause(err), ErrNotFound, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
db_test.go
Outdated
@@ -412,7 +412,7 @@ func TestDB_Snapshot(t *testing.T) { | |||
testutil.Ok(t, series.Err()) | |||
} | |||
testutil.Ok(t, seriesSet.Err()) | |||
testutil.Equals(t, 1000.0, sum) | |||
testutil.Equals(t, sum, 1000.0, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
db_test.go
Outdated
@@ -689,7 +689,7 @@ func TestWALFlushedOnDBClose(t *testing.T) { | |||
|
|||
values, err := q.LabelValues("labelname") | |||
testutil.Ok(t, err) | |||
testutil.Equals(t, []string{"labelvalue"}, values) | |||
testutil.Equals(t, values, []string{"labelvalue"}, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
head_test.go
Outdated
|
||
series, ok := recs[0].([]RefSeries) | ||
testutil.Assert(t, ok, "expected series record but got %+v", recs[0]) | ||
testutil.Equals(t, []RefSeries{{Ref: 1, Labels: labels.FromStrings("a", "b")}}, series) | ||
testutil.Equals(t, series, []RefSeries{{Ref: 1, Labels: labels.FromStrings("a", "b")}}, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
wal_test.go
Outdated
testutil.Equals(t, byte(walSeriesSimple), flag) | ||
testutil.Equals(t, []byte("Hello World!!"), b) | ||
testutil.Equals(t, WALEntrySeries, et, "") | ||
testutil.Equals(t, flag, byte(walSeriesSimple), "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
I took a slightly different approach (message is optional, can use variables) in a prometheus/prometheus PR (prometheus/prometheus#4639). It might be worthwhile to choose one or the other for people working in both repos. |
Had a quick look and looks good. I would say let's take your approach |
68a23d3
to
79a19c9
Compare
@csmarchbanks Added you as a co-author because I used your code. |
ping me when it is ready for another review. |
Co-authored-by: Chris Marchbanks <[email protected]> Signed-off-by: Camille Janicki <[email protected]>
@krasi-georgiev It looks like the checks are passing now. Thanks @krasi-georgiev and @codesome for suggesting to rebase. |
@codesome can you have another look and will merge. |
testutil/testutil.go
Outdated
if !reflect.DeepEqual(exp, act) { | ||
_, 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:\n\n\texp: %#v\n\n\tgot: %#v%s\033[39m\n\n", filepath.Base(file), line, exp, act, formatMessage(msgAndArgs)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to print the message before exp
and got
. Else it might get tedious trying to get to the end and find the message. @krasi-georgiev what do you say?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes tested it locally and you are right.
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)
testutil/testutil.go
Outdated
if _, ok := msgAndArgs[0].(string); !ok { | ||
return "" | ||
} | ||
return fmt.Sprintf(fmt.Sprintf("\n\nmsg: %s", msgAndArgs[0]), msgAndArgs[1:]...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit)
As we are already checking for msgAndArgs[0]
to be string
, we can reuse the value from that and avoid additional fmt.Sprintf
.
Maybe something like
if msg, ok := msgAndArgs[0].(string); ok {
return fmt.Sprintf("\n\nmsg: "+msg, msgAndArgs[1:]...)
}
return ""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Signed-off-by: Camille Janicki <[email protected]>
Thanks @codesome for the review! |
Thanks! appreciated. |
I'll look into it! Thanks! :) |
Fixes #390
I can go through and attempt to add more meaningful messages as opposed to an empty string.
Signed-off-by: Camille Janicki [email protected]