| 30 | } |
| 31 | |
| 32 | func (r *Registry) Exclude(t *testing.T, m Matcher) { |
| 33 | registrationStack := string(debug.Stack()) |
| 34 | |
| 35 | excludedStub := &Stub{ |
| 36 | Matcher: m, |
| 37 | Responder: func(req *http.Request) (*http.Response, error) { |
| 38 | callStack := string(debug.Stack()) |
| 39 | |
| 40 | var errMsg strings.Builder |
| 41 | errMsg.WriteString("HTTP call was made when it should have been excluded:\n") |
| 42 | errMsg.WriteString(fmt.Sprintf("Request URL: %s\n", req.URL)) |
| 43 | errMsg.WriteString(fmt.Sprintf("Was excluded by: %s\n", registrationStack)) |
| 44 | errMsg.WriteString(fmt.Sprintf("Was called from: %s\n", callStack)) |
| 45 | |
| 46 | t.Error(errMsg.String()) |
| 47 | t.FailNow() |
| 48 | return nil, nil |
| 49 | }, |
| 50 | exclude: true, |
| 51 | } |
| 52 | r.stubs = append(r.stubs, excludedStub) |
| 53 | } |
| 54 | |
| 55 | type Testing interface { |
| 56 | Errorf(string, ...interface{}) |