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

Function Test_apiRun

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

Source from the content-addressed store, hash-verified

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