MCPcopy Index your code
hub / github.com/cli/cli / Test_getBody

Function Test_getBody

pkg/cmd/variable/set/set_test.go:437–476  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

435}
436
437func Test_getBody(t *testing.T) {
438 tests := []struct {
439 name string
440 bodyArg string
441 want string
442 stdin string
443 }{
444 {
445 name: "literal value",
446 bodyArg: "a variable",
447 want: "a variable",
448 },
449 {
450 name: "from stdin",
451 want: "a variable",
452 stdin: "a variable",
453 },
454 {
455 name: "from stdin with trailing newline character",
456 want: "a variable",
457 stdin: "a variable\n",
458 },
459 }
460
461 for _, tt := range tests {
462 t.Run(tt.name, func(t *testing.T) {
463 ios, stdin, _, _ := iostreams.Test()
464 ios.SetStdinTTY(false)
465 _, err := stdin.WriteString(tt.stdin)
466 assert.NoError(t, err)
467 opts := &SetOptions{
468 IO: ios,
469 Body: tt.bodyArg,
470 }
471 body, err := getBody(opts)
472 assert.NoError(t, err)
473 assert.Equal(t, tt.want, body)
474 })
475 }
476}
477
478func Test_getVariablesFromOptions(t *testing.T) {
479 genFile := func(s string) string {

Callers

nothing calls this directly

Calls 5

TestFunction · 0.92
SetStdinTTYMethod · 0.80
EqualMethod · 0.80
getBodyFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected