(t *testing.T)
| 423 | } |
| 424 | |
| 425 | func Test_apiRun(t *testing.T) { |
| 426 | tests := []struct { |
| 427 | name string |
| 428 | options ApiOptions |
| 429 | httpResponse *http.Response |
| 430 | err error |
| 431 | stdout string |
| 432 | stderr string |
| 433 | isatty bool |
| 434 | }{ |
| 435 | { |
| 436 | name: "success", |
| 437 | httpResponse: &http.Response{ |
| 438 | StatusCode: 200, |
| 439 | Body: io.NopCloser(bytes.NewBufferString(`bam!`)), |
| 440 | }, |
| 441 | err: nil, |
| 442 | stdout: `bam!`, |
| 443 | stderr: ``, |
| 444 | isatty: false, |
| 445 | }, |
| 446 | { |
| 447 | name: "show response headers", |
| 448 | options: ApiOptions{ |
| 449 | ShowResponseHeaders: true, |
| 450 | }, |
| 451 | httpResponse: &http.Response{ |
| 452 | Proto: "HTTP/1.1", |
| 453 | Status: "200 Okey-dokey", |
| 454 | StatusCode: 200, |
| 455 | Body: io.NopCloser(bytes.NewBufferString(`body`)), |
| 456 | Header: http.Header{"Content-Type": []string{"text/plain"}}, |
| 457 | }, |
| 458 | err: nil, |
| 459 | stdout: "HTTP/1.1 200 Okey-dokey\nContent-Type: text/plain\r\n\r\nbody", |
| 460 | stderr: ``, |
| 461 | isatty: false, |
| 462 | }, |
| 463 | { |
| 464 | name: "success 204", |
| 465 | httpResponse: &http.Response{ |
| 466 | StatusCode: 204, |
| 467 | Body: nil, |
| 468 | }, |
| 469 | err: nil, |
| 470 | stdout: ``, |
| 471 | stderr: ``, |
| 472 | isatty: false, |
| 473 | }, |
| 474 | { |
| 475 | name: "REST error", |
| 476 | httpResponse: &http.Response{ |
| 477 | StatusCode: 400, |
| 478 | Body: io.NopCloser(bytes.NewBufferString(`{"message": "THIS IS FINE"}`)), |
| 479 | Header: http.Header{"Content-Type": []string{"application/json; charset=utf-8"}}, |
| 480 | }, |
| 481 | err: cmdutil.SilentError, |
| 482 | stdout: `{"message": "THIS IS FINE"}`, |
nothing calls this directly
no test coverage detected