Run sets a handler to be called before returning. It can be used when mocking a method (such as an unmarshaler) that takes a pointer to a struct and sets properties in such struct Mock.On("Unmarshal", AnythingOfType("*map[string]interface{}")).Return().Run(func(args Arguments) { arg := args.Get(
(fn func(args Arguments))
| 181 | // arg["foo"] = "bar" |
| 182 | // }) |
| 183 | func (c *Call) Run(fn func(args Arguments)) *Call { |
| 184 | c.lock() |
| 185 | defer c.unlock() |
| 186 | c.RunFn = fn |
| 187 | return c |
| 188 | } |
| 189 | |
| 190 | // Maybe allows the method call to be optional. Not calling an optional method |
| 191 | // will not cause an error while asserting expectations |