MCPcopy Create free account
hub / github.com/cli/cli / Test_apiRun

Function Test_apiRun

pkg/cmd/api/api_test.go:459–804  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

TestFunction · 0.92
NewMockConfigFunction · 0.92
apiRunFunction · 0.85
SetStdoutTTYMethod · 0.80
RunMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected