Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Add msg parameter to Equals function in testutil #398

Merged
merged 2 commits into from
Oct 3, 2018

Conversation

janickic
Copy link
Contributor

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]

@krasi-georgiev
Copy link
Contributor

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.
Thanks!

Copy link
Contributor

@codesome codesome left a 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{}, "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

Copy link
Contributor Author

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}}}, "")
Copy link
Contributor

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{}, "")
Copy link
Contributor

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, "")
Copy link
Contributor

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, "")
Copy link
Contributor

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"}, "")
Copy link
Contributor

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")}}, "")
Copy link
Contributor

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), "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

@csmarchbanks
Copy link
Contributor

csmarchbanks commented Sep 27, 2018

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.

@krasi-georgiev
Copy link
Contributor

Had a quick look and looks good. I would say let's take your approach

@janickic
Copy link
Contributor Author

@csmarchbanks Added you as a co-author because I used your code.

@krasi-georgiev
Copy link
Contributor

ping me when it is ready for another review.

@codesome codesome mentioned this pull request Sep 30, 2018
Co-authored-by: Chris Marchbanks <[email protected]>
Signed-off-by: Camille Janicki <[email protected]>
@janickic
Copy link
Contributor Author

janickic commented Oct 2, 2018

@krasi-georgiev It looks like the checks are passing now. Thanks @krasi-georgiev and @codesome for suggesting to rebase.

@krasi-georgiev
Copy link
Contributor

@codesome can you have another look and will merge.

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))
Copy link
Contributor

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?

Copy link
Contributor

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)

if _, ok := msgAndArgs[0].(string); !ok {
return ""
}
return fmt.Sprintf(fmt.Sprintf("\n\nmsg: %s", msgAndArgs[0]), msgAndArgs[1:]...)
Copy link
Contributor

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 ""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@janickic
Copy link
Contributor Author

janickic commented Oct 3, 2018

Thanks @codesome for the review!

@krasi-georgiev krasi-georgiev merged commit 0ce4111 into prometheus-junkyard:master Oct 3, 2018
@krasi-georgiev
Copy link
Contributor

Thanks! appreciated.

@krasi-georgiev
Copy link
Contributor

@janickic here is another good issue if you are looking for more :) #237

@janickic
Copy link
Contributor Author

janickic commented Oct 8, 2018

I'll look into it! Thanks! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants