MCPcopy
hub / github.com/cli/cli / Test_getVariablesFromOptions

Function Test_getVariablesFromOptions

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

Source from the content-addressed store, hash-verified

476}
477
478func Test_getVariablesFromOptions(t *testing.T) {
479 genFile := func(s string) string {
480 f, err := os.CreateTemp("", "gh-env.*")
481 if err != nil {
482 t.Fatal(err)
483 return ""
484 }
485 defer f.Close()
486 t.Cleanup(func() {
487 _ = os.Remove(f.Name())
488 })
489 _, err = f.WriteString(s)
490 if err != nil {
491 t.Fatal(err)
492 }
493 return f.Name()
494 }
495
496 tests := []struct {
497 name string
498 opts SetOptions
499 isTTY bool
500 stdin string
501 want map[string]string
502 wantErr bool
503 }{
504 {
505 name: "variable from arg",
506 opts: SetOptions{
507 VariableName: "FOO",
508 Body: "bar",
509 },
510 want: map[string]string{"FOO": "bar"},
511 },
512 {
513 name: "variable from stdin",
514 opts: SetOptions{
515 Body: "",
516 EnvFile: "-",
517 },
518 stdin: `FOO=bar`,
519 want: map[string]string{"FOO": "bar"},
520 },
521 {
522 name: "variables from file",
523 opts: SetOptions{
524 Body: "",
525 EnvFile: genFile(heredoc.Doc(`
526 FOO=bar
527 QUOTED="my value"
528 #IGNORED=true
529 export SHELL=bash
530 `)),
531 },
532 stdin: `FOO=bar`,
533 want: map[string]string{
534 "FOO": "bar",
535 "SHELL": "bash",

Callers

nothing calls this directly

Calls 10

TestFunction · 0.92
getVariablesFromOptionsFunction · 0.85
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
CloseMethod · 0.65
RemoveMethod · 0.65
NameMethod · 0.65
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected