Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util/testkit: make the msg of failed check more readable #7386

Merged
merged 7 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion executor/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ func (s *testSuite) TestUser(c *C) {
tk.MustExec(dropUserSQL)
tk.MustQuery("select * from mysql.db").Check(testkit.Rows(
"localhost test testDB Y Y Y Y Y Y Y N Y Y N N N N N N Y N N",
"localhost test testDB1 Y Y Y Y Y Y Y N Y Y N N N N N N Y N N] [% dddb_% dduser Y Y Y Y Y Y Y N Y Y N N N N N N Y N N",
"localhost test testDB1 Y Y Y Y Y Y Y N Y Y N N N N N N Y N N",
"% dddb_% dduser Y Y Y Y Y Y Y N Y Y N N N N N N Y N N",
"% test test Y N N N N N N N N N N N N N N N N N N",
"localhost test testDBRevoke N N N N N N N N N N N N N N N N N N N",
))
Expand Down
13 changes: 10 additions & 3 deletions util/testkit/testkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package testkit

import (
"bytes"
"fmt"
"sort"
"sync/atomic"
Expand Down Expand Up @@ -43,9 +44,15 @@ type Result struct {

// Check asserts the result equals the expected results.
func (res *Result) Check(expected [][]interface{}) {
got := fmt.Sprintf("%s", res.rows)
need := fmt.Sprintf("%s", expected)
res.c.Assert(got, check.Equals, need, res.comment)
resBuff := bytes.NewBufferString("")
for _, row := range res.rows {
fmt.Fprintf(resBuff, "%s\n", row)
}
needBuff := bytes.NewBufferString("")
for _, row := range expected {
fmt.Fprintf(needBuff, "%s\n", row)
}
res.c.Assert(resBuff.String(), check.Equals, needBuff.String(), res.comment)
}

// CheckAt asserts the result of selected columns equals the expected results.
Expand Down