MCPcopy
hub / github.com/cli/cli / Test_setupGitRun

Function Test_setupGitRun

pkg/cmd/auth/setupgit/setupgit_test.go:77–200  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

75 }
76}
77func Test_setupGitRun(t *testing.T) {
78 tests := []struct {
79 name string
80 opts *SetupGitOptions
81 setupErr error
82 cfgStubs func(*testing.T, gh.Config)
83 expectedHostsSetup []string
84 expectedErr error
85 expectedErrOut string
86 }{
87 {
88 name: "opts.Config returns an error",
89 opts: &SetupGitOptions{
90 Config: func() (gh.Config, error) {
91 return nil, fmt.Errorf("oops")
92 },
93 },
94 expectedErr: errors.New("oops"),
95 },
96 {
97 name: "when an unknown hostname is provided without forcing, return an error",
98 opts: &SetupGitOptions{
99 Hostname: "ghe.io",
100 },
101 cfgStubs: func(t *testing.T, cfg gh.Config) {
102 login(t, cfg, "github.com", "test-user", "gho_ABCDEFG", "https", false)
103 },
104 expectedErr: errors.New("You are not logged into the GitHub host \"ghe.io\". Run gh auth login -h ghe.io to authenticate or provide `--force`"),
105 },
106 {
107 name: "when an unknown hostname is provided with forcing, set it up",
108 opts: &SetupGitOptions{
109 Hostname: "ghe.io",
110 Force: true,
111 },
112 expectedHostsSetup: []string{"ghe.io"},
113 },
114 {
115 name: "when a known hostname is provided without forcing, set it up",
116 opts: &SetupGitOptions{
117 Hostname: "ghe.io",
118 },
119 cfgStubs: func(t *testing.T, cfg gh.Config) {
120 login(t, cfg, "ghe.io", "test-user", "gho_ABCDEFG", "https", false)
121 },
122 expectedHostsSetup: []string{"ghe.io"},
123 },
124 {
125 name: "when a hostname is provided but setting it up errors, that error is bubbled",
126 opts: &SetupGitOptions{
127 Hostname: "ghe.io",
128 },
129 setupErr: fmt.Errorf("broken"),
130 cfgStubs: func(t *testing.T, cfg gh.Config) {
131 login(t, cfg, "ghe.io", "test-user", "gho_ABCDEFG", "https", false)
132 },
133 expectedErr: errors.New("failed to set up git credential helper: broken"),
134 expectedErrOut: "",

Callers

nothing calls this directly

Calls 11

TestFunction · 0.92
NewIsolatedTestConfigFunction · 0.92
setupGitRunFunction · 0.85
SetStdinTTYMethod · 0.80
SetStderrTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
loginFunction · 0.70
ErrorfMethod · 0.65
RunMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected