(t *testing.T)
| 455 | } |
| 456 | |
| 457 | func Test_apiRun(t *testing.T) { |
| 458 | tests := []struct { |
| 459 | name string |
| 460 | options ApiOptions |
| 461 | httpResponse *http.Response |
| 462 | err error |
| 463 | errMsg string |
| 464 | stdout string |
| 465 | stderr string |
| 466 | isatty bool |
| 467 | }{ |
| 468 | { |
| 469 | name: "success", |
| 470 | httpResponse: &http.Response{ |
| 471 | StatusCode: 200, |
| 472 | Body: io.NopCloser(bytes.NewBufferString(`bam!`)), |
| 473 | }, |
| 474 | err: nil, |
| 475 | stdout: `bam!`, |
| 476 | stderr: ``, |
| 477 | isatty: false, |
| 478 | }, |
| 479 | { |
| 480 | name: "show response headers", |
| 481 | options: ApiOptions{ |
| 482 | ShowResponseHeaders: true, |
| 483 | }, |
| 484 | httpResponse: &http.Response{ |
| 485 | Proto: "HTTP/1.1", |
| 486 | Status: "200 Okey-dokey", |
| 487 | StatusCode: 200, |
| 488 | Body: io.NopCloser(bytes.NewBufferString(`body`)), |
| 489 | Header: http.Header{"Content-Type": []string{"text/plain"}}, |
| 490 | }, |
| 491 | err: nil, |
| 492 | stdout: "HTTP/1.1 200 Okey-dokey\nContent-Type: text/plain\r\n\r\nbody", |
| 493 | stderr: ``, |
| 494 | isatty: false, |
| 495 | }, |
| 496 | { |
| 497 | name: "success 204", |
| 498 | httpResponse: &http.Response{ |
| 499 | StatusCode: 204, |
| 500 | Body: nil, |
| 501 | }, |
| 502 | err: nil, |
| 503 | stdout: ``, |
| 504 | stderr: ``, |
| 505 | isatty: false, |
| 506 | }, |
| 507 | { |
| 508 | name: "REST error", |
| 509 | httpResponse: &http.Response{ |
| 510 | StatusCode: 400, |
| 511 | Body: io.NopCloser(bytes.NewBufferString(`{"message": "THIS IS FINE"}`)), |
| 512 | Header: http.Header{"Content-Type": []string{"application/json; charset=utf-8"}}, |
| 513 | }, |
| 514 | err: cmdutil.SilentError, |
nothing calls this directly
no test coverage detected