Created
October 6, 2020 09:04
-
-
Save sanan-fataliyev/278c6e78cb642664af8f8c76aeabea82 to your computer and use it in GitHub Desktop.
testify helper method to set input argument
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func argSetter(index int, newVal interface{}) func(args mock.Arguments) { | |
| return func(args mock.Arguments) { | |
| // get dest arg | |
| dest := args.Get(index) | |
| // inspect | |
| ptr := reflect.ValueOf(dest) | |
| // dereference | |
| val := ptr.Elem() | |
| // set value | |
| val.Set(reflect.ValueOf(newVal)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment