MCPcopy
hub / github.com/cli/cli / TestSwitchRun

Function TestSwitchRun

pkg/cmd/auth/switch/switch_test.go:86–440  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestSwitchRun(t *testing.T) {
87 type user struct {
88 name string
89 token string
90 }
91
92 type hostUsers struct {
93 host string
94 users []user
95 }
96
97 type successfulExpectation struct {
98 switchedHost string
99 activeUser string
100 activeToken string
101 hostsCfg string
102 stderr string
103 }
104
105 type failedExpectation struct {
106 err error
107 stderr string
108 }
109
110 userWithMissingToken := "user-that-is-broken-by-the-test"
111
112 tests := []struct {
113 name string
114 opts SwitchOptions
115 cfgHosts []hostUsers
116 env map[string]string
117
118 expectedSuccess successfulExpectation
119 expectedFailure failedExpectation
120
121 prompterStubs func(*prompter.PrompterMock)
122 }{
123 {
124 name: "given one host with two users, switches to the other user",
125 opts: SwitchOptions{},
126 cfgHosts: []hostUsers{
127 {"github.com", []user{
128 {"inactive-user", "inactive-user-token"},
129 {"active-user", "active-user-token"},
130 }},
131 },
132 expectedSuccess: successfulExpectation{
133 switchedHost: "github.com",
134 activeUser: "inactive-user",
135 activeToken: "inactive-user-token",
136 hostsCfg: "github.com:\n git_protocol: ssh\n users:\n inactive-user:\n active-user:\n user: inactive-user\n",
137 stderr: "✓ Switched active account for github.com to inactive-user",
138 },
139 },
140 {
141 name: "given one host, with three users, switches to the specified user",
142 opts: SwitchOptions{
143 Username: "inactive-user-2",

Callers

nothing calls this directly

Calls 15

SelectCallsMethod · 0.95
IndexForFunction · 0.92
NewIsolatedTestConfigFunction · 0.92
DeleteFunction · 0.92
TestFunction · 0.92
switchRunFunction · 0.85
EqualMethod · 0.80
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
ContainsMethod · 0.80
ErrorfMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected