You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
gomock caller.SetArg recognizes variadic pointer parameter as a single param
Code example
func (p *pkg) VariadicInterface(data ...interface{}) {
for i := range data {
data[i] = i
}
}
func (p *pkg) VariadicInt(data ...*int) {
for i := range data {
*data[i] = i
}
}
// Usage
var a, b, c, d int
pkgReal.VariadicInterface(&a, &b)
pkgReal.VariadicInt(&c, &d)
The gomock's Call interface allows for setting a value to a specified
argument, making it convinient to work with functions that return data
through pointer arguments. However, this is not possible for variadic
functions, the error is:
SetArg(1, ...) called for a method with 1 args...
The root cause is that the variadic argument in a form of
...interface{} is threated as single value instead of being treated as
slice.
This commit changes this situation by making sure that the variadic
arguments that are a slice are treated as slices. As a consequence it is
now possible to set argument value for variadic functions.
See: golang#174
gomock caller.SetArg recognizes variadic pointer parameter as a single param
Code example
Expect function on Test
Output
SetArg(1, ...) called for a method with 1 args
Expected behaviour
Test passed with
a
,b
,c
, andd
match given valuePlease correct me if I use it wrong.
The text was updated successfully, but these errors were encountered: