-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Test for marshalling Organizations and make JSON comparison non sensitive to key order #1303
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1303 +/- ##
=======================================
Coverage 73.42% 73.42%
=======================================
Files 86 86
Lines 6047 6047
=======================================
Hits 4440 4440
Misses 837 837
Partials 770 770 Continue to review full report at Codecov.
|
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.
Thank you, @sgarciac.
Can you please add to your PR description what problem you are attempting to solve here since this PR is not associated with any issue?
github/github_test.go
Outdated
@@ -135,32 +134,26 @@ func testBody(t *testing.T, r *http.Request, want string) { | |||
} | |||
} | |||
|
|||
// Helper function to test that a value is marshalled to JSON as expected. | |||
// Test whether the marshalling of v produces a JSON that corresponds |
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.
Let's please spell "marshal" and "unmarshal" consistently throughout the PR with a single "l".
Please also terminate the comment sentence with a period.
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.
done
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.
(also, added the issue I'm helping with to the description of the PR and the commit message)
9850785
to
c5c562f
Compare
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.
Just a couple more tweaks, please, and then I think we will be ready for a second LGTM.
Thank you, @sgarciac!
github/github_test.go
Outdated
@@ -135,32 +134,26 @@ func testBody(t *testing.T, r *http.Request, want string) { | |||
} | |||
} | |||
|
|||
// Helper function to test that a value is marshalled to JSON as expected. | |||
// Test whether the marshaling of v produces a JSON that corresponds |
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.
Let's please say "produces JSON" instead of "produces a JSON".
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.
done!
github/github_test.go
Outdated
} | ||
w, _ := json.Marshal(u) |
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.
Please test the returned err
here instead of ignoring it.
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.
done! (however, I wonder if it's ever possible for the marshal here to fail, if the immediate unmarshal had no errors)
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.
Probably not... but we would like to promote good Go programming practices for all developers who take a look at this code, whether they are new to Go or not... and if developers start ignoring error codes when they think there is no possible way that it could error, that opens up a potential world of pain further down the line.
Let's say, for example, we left it as-is, but then someone in the future decided to change the code above this that generated the value of u
, but left this line the same. Suddenly, it might be possible that u
was malformed, but this line would not catch that problem.
In summary, it is always safest to check returned error values in Go to minimize future negative surprises. Thanks.
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.
Just one more tiny change, please, and then I think we will be ready for a second LGTM.
Thank you, @sgarciac!
github/github_test.go
Outdated
if err != nil { | ||
t.Errorf("Unable to marshal JSON for %v", v) | ||
t.Errorf("Unable to marshal JSON for %v", u) |
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: please change this from %v
to %#v
in order to better see the contents of u
.
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.
done!
👌 |
Thank you, @wesleimp ! |
…tive to key order (google#1303) Helps google#55.
This pull request contains two items: