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

Function Test_apiRun

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

Source from the content-addressed store, hash-verified

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