MatchedBy can be used to match a mock call based on only certain properties from a complex struct or some calculation. It takes a function that will be evaluated with the called argument and will return true when there's a match and false otherwise. Example: m.On("Do", MatchedBy(func(req *http.Re
(fn interface{})
| 915 | // which returns a bool. If fn doesn't match the required signature, |
| 916 | // MatchedBy() panics. |
| 917 | func MatchedBy(fn interface{}) argumentMatcher { |
| 918 | fnType := reflect.TypeOf(fn) |
| 919 | |
| 920 | if fnType.Kind() != reflect.Func { |
| 921 | panic(fmt.Sprintf("assert: arguments: %s is not a func", fn)) |
| 922 | } |
| 923 | if fnType.NumIn() != 1 { |
| 924 | panic(fmt.Sprintf("assert: arguments: %s does not take exactly one argument", fn)) |
| 925 | } |
| 926 | if fnType.NumOut() != 1 || fnType.Out(0).Kind() != reflect.Bool { |
| 927 | panic(fmt.Sprintf("assert: arguments: %s does not return a bool", fn)) |
| 928 | } |
| 929 | |
| 930 | return argumentMatcher{fn: reflect.ValueOf(fn)} |
| 931 | } |
| 932 | |
| 933 | // Get Returns the argument at the specified index. |
| 934 | func (args Arguments) Get(index int) interface{} { |
no outgoing calls