MCPcopy
hub / github.com/cli/cli / Test_apiRun

Function Test_apiRun

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

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected