Hi gophers, I have a problem and I have no clue of getting around it, are there any smart advisors that could help ?
Lets say I have a service a function being called something like this:
someData := ""
s.something.foo(arg1, callback(arg2) err{
someData = "xxx"
return true
})
now, this function returns some value, but inside of it assigns some values to data declared above it. How do I mock this action ?
I tried something like this but it did not work out
MockSomeData := ""
mycallback := func(arg1, innercallback func(arg2) error){
MockSomeData = "xxx"
}
s.MockSomething.EXPECT().foo(arg1, gomock.Any()).Do(mycallback)
Do you have any tips on how to go around it ? I cant really specify .RETURN(&MockSomeData) as the function does not really return the desired value but only assigns value to outer scope variable.
I tried this as suggested but does not work.
MockSomeData := ""
mycallback := func(arg1, innercallback func(arg2) error){
*(&MockSomeData) = "xxx"
}
s.MockSomething.EXPECT().foo(arg1, gomock.Any()).Do(mycallback)
When I debug the code and the inner callback function runs the MockSomeData gets overwritten but as soon as it steps outside the scope MockSomeData is nil again.