String formats the unmatched request and generates a snippet to help stub the request, useful when reporting unmatched requests i.e. those that have been received but no stubbing was defined
()
| 139 | // stub the request, useful when reporting unmatched requests i.e. those |
| 140 | // that have been received but no stubbing was defined |
| 141 | func (u unmatchedRequest) String() string { |
| 142 | str := fmt.Sprintf("Found unmatched %s request to %s\n", u.Method, u.URL) |
| 143 | |
| 144 | if u.Body != "" { |
| 145 | str += "The request contained this HTTP body:\n" + u.Body |
| 146 | } |
| 147 | |
| 148 | str += fmt.Sprintf(`Stub it by adding: |
| 149 | wiremock.StubFor(ctx, wiremock.%s(wiremock.URLPathEqualTo("%s")). |
| 150 | WillReturnResponse(wiremock.NewResponse().WithBody("<body>").WithHeaders( |
| 151 | map[string]string{"Content-Type": "%s"}, |
| 152 | ).WithStatus(200) |
| 153 | ))`, strings.ToTitle(strings.ToLower(u.Method)), u.URL, contentTypeFrom(u)) |
| 154 | |
| 155 | return str |
| 156 | } |
| 157 | |
| 158 | // UnmatchedRequests queries the WireMock admin API for any unmatched requests |
| 159 | // i.e. those that have been received but no stubbing was defined and returns |
no test coverage detected