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

[GH-358] Bug Fix sending "null" body in unnecessary requests #387

Merged
merged 11 commits into from
Apr 22, 2024

Conversation

developerkunal
Copy link
Contributor

@developerkunal developerkunal commented Apr 15, 2024

🔧 Changes

  • Fix NewRequest Function sending "null" body in unnecessary requests.
  • Add Unit Testcases for NewRequest Function.

📚 References

🔬 Testing

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

@developerkunal developerkunal changed the title [#358] Bug Fix sending "null" body in unnecessary requests. [GH-358] Bug Fix sending "null" body in unnecessary requests. Apr 15, 2024
@developerkunal developerkunal marked this pull request as ready for review April 15, 2024 12:46
@developerkunal developerkunal requested a review from a team as a code owner April 15, 2024 12:46
@developerkunal developerkunal changed the title [GH-358] Bug Fix sending "null" body in unnecessary requests. [GH-358] Bug Fix sending "null" body in unnecessary requests Apr 15, 2024
Comment on lines 76 to 77
assert.Error(t, err)
assert.Contains(t, err.Error(), testCase.expectedError.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance we can make the expectedError a string and then use assert.EqualError instead? This would reduce the assertions to just 1 line.

if testCase.expectedError != nil {
assert.Error(t, err)
assert.Contains(t, err.Error(), testCase.expectedError.Error())
assert.Nil(t, request)
Copy link
Contributor

Choose a reason for hiding this comment

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

We could return immediately after this assert and then remove the else block.

}{
{
name: "Valid GET request",
method: "GET",
Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance we could use the constants from the http package for the methods? http.MethodGet

Comment on lines 84 to 87
if testCase.method == "GET" || testCase.method == "DELETE" {
requestBody, _ := io.ReadAll(request.Body)
assert.Empty(t, string(requestBody))
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We could remove these conditional checks inside the assertions if we have an expectedBody on the testCases as well and then simply do an assert.Equal.

transfer_encoding: []
trailer: {}
host: go-auth0-dev.eu.auth0.com
remote_addr: ""
request_uri: ""
body: |
null
body: ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@developerkunal developerkunal merged commit 3b22216 into main Apr 22, 2024
7 checks passed
@developerkunal developerkunal deleted the fix-body-sent-in--unreqired-requests branch April 22, 2024 13:34
@sergiught sergiught mentioned this pull request Apr 23, 2024
2 tasks
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.

2 participants