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

feat: add nil check to SetResult (#503) #582

Merged
merged 1 commit into from
Mar 6, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ func (r *Request) SetBody(body interface{}) *Request {
// Accessing a result value from response instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this should be documented here? something like
passing a nil res paramaeter has no effect

Copy link
Member

Choose a reason for hiding this comment

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

@segevda I will add it later it. Thanks!

// response.Result().(*AuthToken)
func (r *Request) SetResult(res interface{}) *Request {
r.Result = getPointer(res)
if res != nil {
r.Result = getPointer(res)
}
return r
}

Expand Down
10 changes: 10 additions & 0 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1891,3 +1891,13 @@ func TestPostBodyError(t *testing.T) {
assertEqual(t, "read error", err.Error())
assertNil(t, resp)
}

func TestSetResultMustNotPanicOnNil(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Errorf("must not panic")
}
}()
dc().R().SetResult(nil)
}