scaffoldREST adds a response for a REST request from GitHub's description. A request that already has a response is left alone: ghmock set checks REST responses in full, so a stored one has everything GitHub requires.
(chk *checker, name string, responses responseSet, explicit bool)
| 333 | // A request that already has a response is left alone: ghmock set checks REST |
| 334 | // responses in full, so a stored one has everything GitHub requires. |
| 335 | func scaffoldREST(chk *checker, name string, responses responseSet, explicit bool) ([]string, error) { |
| 336 | method, target, _ := strings.Cut(name, " ") |
| 337 | if !strings.HasPrefix(target, "/") { |
| 338 | return nil, fmt.Errorf("%s isn't on the REST API host, so GitHub's REST description doesn't cover it", target) |
| 339 | } |
| 340 | if len(responses[name]) > 0 { |
| 341 | if explicit { |
| 342 | return []string{fmt.Sprintf("%s: already has a response, so nothing was added", name)}, nil |
| 343 | } |
| 344 | return nil, nil |
| 345 | } |
| 346 | idx, err := chk.rest() |
| 347 | if err != nil { |
| 348 | return nil, err |
| 349 | } |
| 350 | resp, detail, err := idx.scaffold(method, target) |
| 351 | if err != nil { |
| 352 | return nil, err |
| 353 | } |
| 354 | responses[name] = []response{resp} |
| 355 | return []string{fmt.Sprintf("%s: added response 1 of 1%s", name, detail)}, nil |
| 356 | } |
no test coverage detected