good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
172f7778
Unverified
Commit
172f7778
authored
5 years ago
by
Adam Schmideg
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
rpc: add error when call result parameter is not addressable (#20638)
parent
34bb132b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
rpc/client.go
+3
-0
3 additions, 0 deletions
rpc/client.go
rpc/client_test.go
+17
-0
17 additions, 0 deletions
rpc/client_test.go
with
20 additions
and
0 deletions
rpc/client.go
+
3
−
0
View file @
172f7778
...
...
@@ -276,6 +276,9 @@ func (c *Client) Call(result interface{}, method string, args ...interface{}) er
// The result must be a pointer so that package json can unmarshal into it. You
// can also pass nil, in which case the result is ignored.
func
(
c
*
Client
)
CallContext
(
ctx
context
.
Context
,
result
interface
{},
method
string
,
args
...
interface
{})
error
{
if
result
!=
nil
&&
reflect
.
TypeOf
(
result
)
.
Kind
()
!=
reflect
.
Ptr
{
return
fmt
.
Errorf
(
"call result parameter must be pointer or nil interface: %v"
,
result
)
}
msg
,
err
:=
c
.
newMessage
(
method
,
args
...
)
if
err
!=
nil
{
return
err
...
...
This diff is collapsed.
Click to expand it.
rpc/client_test.go
+
17
−
0
View file @
172f7778
...
...
@@ -49,6 +49,23 @@ func TestClientRequest(t *testing.T) {
}
}
func
TestClientResponseType
(
t
*
testing
.
T
)
{
server
:=
newTestServer
()
defer
server
.
Stop
()
client
:=
DialInProc
(
server
)
defer
client
.
Close
()
if
err
:=
client
.
Call
(
nil
,
"test_echo"
,
"hello"
,
10
,
&
echoArgs
{
"world"
});
err
!=
nil
{
t
.
Errorf
(
"Passing nil as result should be fine, but got an error: %v"
,
err
)
}
var
resultVar
echoResult
// Note: passing the var, not a ref
err
:=
client
.
Call
(
resultVar
,
"test_echo"
,
"hello"
,
10
,
&
echoArgs
{
"world"
})
if
err
==
nil
{
t
.
Error
(
"Passing a var as result should be an error"
)
}
}
func
TestClientBatchRequest
(
t
*
testing
.
T
)
{
server
:=
newTestServer
()
defer
server
.
Stop
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment