Repository navigation
Set accept header for function Apps.ListUserRepos - #798
Conversation
Or GitHub may return something contains: Message: "If you would like to help us test the Integrations API during its preview period, you must specify a custom media type in the 'Accept' header. Please see the docs for full details.",
Set accept header in function ListUserRepos
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
|
I signed it! |
|
CLAs look good, thanks! |
sahildua2305
left a comment
There was a problem hiding this comment.
@lingsamuel while your changes look ok, I have reservations about why we need to have custom media type for this endpoint.
Especially, we have test for Apps.ListUserRepos here which isn't failing.
@shurcooL what do you think?
|
Just tested, I'm fine with the changes. @lingsamuel thanks for proactively submitting a PR to fix the issue. LGTM. @shurcooL however, this actually exposes the weakness of our tests when it comes to header restrictions on some endpoints. For example - test for |
There was a problem hiding this comment.
@lingsamuel Can you also modify the test for this endpoint, specifically in file apps_installation_test.go , after line 47, add:
testHeader(t, r, "Accept", mediaTypeIntegrationPreview)Similar to:
That will ensure the test fails should the method fail to set the header in the future.
@sahildua2305 I'm not sure what you mean. The current Apps.ListUserRepos test passes because it doesn't have restrictions on the headers, which is normal for a method we didn't think needed any custom headers. Perhaps you can clarify on what you expected to happen instead?
|
|
||
| // TODO: remove custom Accept header when this API fully launches. | ||
| req.Header.Set("Accept", mediaTypeIntegrationPreview) | ||
|
|
|
@shurcooL if I remove this line in test for However, on my local setup, the tests still pass. Are you able to reproduce this? |
|
The The way you can check that |
|
Ah okay! Thanks for explaining, @shurcooL. My understanding of the |
Add header test for Apps.ListUserRepos
|
@shurcooL All done. By the way, I think @sahildua2305 means the test should be failed if we can't get right data. Maybe he thought that the test is passed so the function will work correctly. |
|
@lingsamuel yes, that’s what I was thinking. Moreover, I assumed that testHeader was confirming that the request is successful only with the header mentioned. |
It does do that. It's just many tests don't call that helper. Specifically, func testHeader(t *testing.T, r *http.Request, header string, want string) {
if got := r.Header.Get(header); got != want {
t.Errorf("Header.Get(%q) returned %q, want %q", header, got, want)
}
}So, if you want, you can use it like this in a test to ensure that the default testHeader(t, r, "Accept", mediaTypeV3)I'm not sure if there are benefits to doing that, but I haven't thought about it too much. If you think there are worthwhile improvements possible, feel free to open a new issue about it. (P.S. This is a good example of where helpers make code less readable. I'm sure you wouldn't misunderstand what |
|
@shurcooL Oh no, I think @sahildua2305 means, |
|
Sorry, I don’t understand. If you think there’s a worthwhile opportunity to improve tests, feel free to open a new issue and describe it in more detail. I am satisfied with the current tests as they are, and don’t see any ways to make them significantly better. |
Without this custom media type in the Accept header, GitHub API responds
with:
{
"message": "If you would like to help us test the Integrations API during its preview period, you must specify a custom media type in the 'Accept' header. Please see the docs for full details.",
"documentation_url": "https://developer.github.com/v3"
}
The custom media type requirement is documented at
https://developer.github.com/changes/2016-09-14-Integrations-Early-Access/.
Fixes google#797.
Without this custom media type in the Accept header, GitHub API responds
with:
{
"message": "If you would like to help us test the Integrations API during its preview period, you must specify a custom media type in the 'Accept' header. Please see the docs for full details.",
"documentation_url": "https://developer.github.com/v3"
}
The custom media type requirement is documented at
https://developer.github.com/changes/2016-09-14-Integrations-Early-Access/.
Fixes google#797.
Fixes #797