MCPcopy Create free account
hub / github.com/cli/cli / Test_statusRun

Function Test_statusRun

pkg/cmd/auth/status/status_test.go:106–1049  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

104}
105
106func Test_statusRun(t *testing.T) {
107 tests := []struct {
108 name string
109 opts StatusOptions
110 jsonFields []string
111 env map[string]string
112 now time.Time
113 httpStubs func(*httpmock.Registry)
114 cfgStubs func(*testing.T, gh.Config)
115 wantErr error
116 wantOut string
117 wantErrOut string
118 }{
119 {
120 name: "timeout error",
121 opts: StatusOptions{
122 Hostname: "github.com",
123 },
124 cfgStubs: func(t *testing.T, c gh.Config) {
125 login(t, c, "github.com", "monalisa", "abc123", "https")
126 },
127 httpStubs: func(reg *httpmock.Registry) {
128 reg.Register(httpmock.REST("GET", ""), func(req *http.Request) (*http.Response, error) {
129 // timeout error
130 return nil, context.DeadlineExceeded
131 })
132 },
133 wantErr: cmdutil.SilentError,
134 wantErrOut: heredoc.Doc(`
135 github.com
136 X Timeout trying to log in to github.com account monalisa (GH_CONFIG_DIR/hosts.yml)
137 - Active account: true
138 - Error: Get "https://api.github.com/": context deadline exceeded
139 `),
140 },
141 {
142 name: "hostname set",
143 opts: StatusOptions{
144 Hostname: "ghe.io",
145 },
146 cfgStubs: func(t *testing.T, c gh.Config) {
147 login(t, c, "github.com", "monalisa", "gho_abc123", "https")
148 login(t, c, "ghe.io", "monalisa-ghe", "gho_abc123", "https")
149 },
150 httpStubs: func(reg *httpmock.Registry) {
151 // mocks for HeaderHasMinimumScopes api requests to a non-github.com host
152 reg.Register(httpmock.REST("GET", "api/v3/"), httpmock.ScopesResponder("repo,read:org"))
153 },
154 wantOut: heredoc.Doc(`
155 ghe.io
156 ✓ Logged in to ghe.io account monalisa-ghe (GH_CONFIG_DIR/hosts.yml)
157 - Active account: true
158 - Git operations protocol: https
159 - Token: gho_******
160 - Token scopes: 'repo', 'read:org'
161 `),
162 },
163 {

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
ScopesResponderFunction · 0.92
StatusStringResponseFunction · 0.92
WithHeaderFunction · 0.92
GraphQLFunction · 0.92
StringResponseFunction · 0.92
TestFunction · 0.92
NewIsolatedTestConfigFunction · 0.92
NewJSONExporterFunction · 0.92
ConfigDirFunction · 0.92

Tested by

no test coverage detected