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

Function Test_apiRun

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

Source from the content-addressed store, hash-verified

455}
456
457func 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,

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