MCPcopy Index your code
hub / github.com/cli/cli / Test_statusRun

Function Test_statusRun

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

Source from the content-addressed store, hash-verified

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

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