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

sql/pgwire: tidy up tests for Exec with placeholders #3856

Merged
merged 1 commit into from
Feb 2, 2016
Merged

sql/pgwire: tidy up tests for Exec with placeholders #3856

merged 1 commit into from
Feb 2, 2016

Conversation

tamird
Copy link
Contributor

@tamird tamird commented Jan 14, 2016

Review on Reviewable

results = append(results, result{res: res, err: err})
}
{
res, err := stmt.Exec(test.params...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this about?

@petermattis
Copy link
Collaborator

LGTM

@tamird
Copy link
Contributor Author

tamird commented Jan 14, 2016

This is related to #3819.

@RaduBerinde
Copy link
Member

sql/pgwire_test.go, line 363 [r2] (raw file):
Wow.. This is kind of insane. Can't we do something more readable, e.g.

for i := 0; i < 2; i++) {
   if (i == 0) {
      res, err := db.Exec()
   } else {
      res, err := stmt.Exec()
   }
   .. check error ..

Actually, it seems that the errors are supposed to be the same (they both must match test.error right?). I would just run both statements and first compare the errors to check they are the same. And then do the error checking once.


Comments from the review on Reviewable.io

@tamird
Copy link
Contributor Author

tamird commented Jan 15, 2016

Review status: 0 of 1 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


sql/pgwire_test.go, line 363 [r2] (raw file):
I think this pattern is quite idiomatic in Go. checking if both errors are identical first can lead to some hard to debug error messages; this version produces a more self contained error in case this test fails. One problem is that it'll be hard to tell which variant failed (stmt.Exec or db.Exec) - I'll see about improving that.


Comments from the review on Reviewable.io

@bdarnell
Copy link
Contributor

Review status: 0 of 1 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


sql/pgwire_test.go, line 363 [r2] (raw file):
I'm not sure what you're referring to by "this pattern", but I wouldn't consider defining functions inline in a for statement to be idiomatic. I prefer Radu's version looping from 0..2. (the error checking is fine as-is)


Comments from the review on Reviewable.io

@RaduBerinde
Copy link
Member

sql/pgwire_test.go, line 363 [r2] (raw file):
You can also separate the three ifs into a function (which might be useful for other cases as well) and just call it twice (no loop).

res, err := db.Exec()
checkErrorMatches(err, test.error);
res, err = stmt.Exec()
checkErrorMatches(err, test.error)


Comments from the review on Reviewable.io

@tamird tamird changed the title sql/pgwire: add tests for Exec with placeholders sql/pgwire: tidy up tests for Exec with placeholders Jan 30, 2016
@nvanbenschoten
Copy link
Member

Review status: 0 of 1 files reviewed at latest revision, 3 unresolved discussions.


sql/pgwire_test.go, line 346 [r1] (raw file):
You might want to s/queryTests/execTests/g, and s/query/exec/g below.


sql/pgwire_test.go, line 383 [r1] (raw file):
You're not defering anything, so why is this needed?


sql/pgwire_test.go, line 363 [r2] (raw file):
Personally I'd be ok with this approach if the function slice wasn't defined inline, but instead assigned to a well-named variable. It seems like we're doing the same thing in TestPGPreparedQuery, so whatever we decide, I'd make sure to keep them consistent.


Comments from the review on Reviewable.io

@petermattis
Copy link
Collaborator

LGTM modulo some of the other comments below.


Review status: 0 of 1 files reviewed at latest revision, 4 unresolved discussions.


sql/pgwire_test.go, line 262 [r3] (raw file):
Not sure the extra indentation is worth being able to defer rows.Close(), but whatever.


Comments from the review on Reviewable.io

@tamird
Copy link
Contributor Author

tamird commented Feb 1, 2016

PTAL, this got a bit bigger.


Review status: 0 of 1 files reviewed at latest revision, 4 unresolved discussions.


sql/pgwire_test.go, line 346 [r1] (raw file):
changed queryTests, but query is still appropriate since it's a string.


sql/pgwire_test.go, line 383 [r1] (raw file):
Removed!


sql/pgwire_test.go, line 363 [r2] (raw file):
I don't really see the big problem here; this inline function is just currying db.Exec


Comments from the review on Reviewable.io

@maddyblue
Copy link
Contributor

LGTM


Review status: 0 of 1 files reviewed at latest revision, 3 unresolved discussions.


Comments from the review on Reviewable.io

tamird added a commit that referenced this pull request Feb 2, 2016
sql/pgwire: tidy up tests for `Exec` with placeholders
@tamird tamird merged commit 6d8b60e into cockroachdb:master Feb 2, 2016
@tamird tamird deleted the sql-pg-exec-boom branch February 2, 2016 19:51
pav-kv pushed a commit to pav-kv/cockroach that referenced this pull request Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants