MCPcopy
hub / github.com/cli/cli / Test_getSecretsFromOptions

Function Test_getSecretsFromOptions

pkg/cmd/secret/set/set_test.go:867–956  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

865}
866
867func Test_getSecretsFromOptions(t *testing.T) {
868 genFile := func(s string) string {
869 f, err := os.CreateTemp("", "gh-env.*")
870 if err != nil {
871 t.Fatal(err)
872 return ""
873 }
874 defer f.Close()
875 t.Cleanup(func() {
876 _ = os.Remove(f.Name())
877 })
878 _, err = f.WriteString(s)
879 if err != nil {
880 t.Fatal(err)
881 }
882 return f.Name()
883 }
884
885 tests := []struct {
886 name string
887 opts SetOptions
888 isTTY bool
889 stdin string
890 want map[string]string
891 wantErr bool
892 }{
893 {
894 name: "secret from arg",
895 opts: SetOptions{
896 SecretName: "FOO",
897 Body: "bar",
898 EnvFile: "",
899 },
900 want: map[string]string{"FOO": "bar"},
901 },
902 {
903 name: "secrets from stdin",
904 opts: SetOptions{
905 Body: "",
906 EnvFile: "-",
907 },
908 stdin: `FOO=bar`,
909 want: map[string]string{"FOO": "bar"},
910 },
911 {
912 name: "secrets from file",
913 opts: SetOptions{
914 Body: "",
915 EnvFile: genFile(heredoc.Doc(`
916 FOO=bar
917 QUOTED="my value"
918 #IGNORED=true
919 export SHELL=bash
920 `)),
921 },
922 stdin: `FOO=bar`,
923 want: map[string]string{
924 "FOO": "bar",

Callers

nothing calls this directly

Calls 9

TestFunction · 0.92
getSecretsFromOptionsFunction · 0.85
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
CloseMethod · 0.65
RemoveMethod · 0.65
NameMethod · 0.65
RunMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected