MCPcopy
hub / github.com/cli/cli / Test_viewRun

Function Test_viewRun

pkg/cmd/agent-task/view/view_test.go:160–1324  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

158}
159
160func Test_viewRun(t *testing.T) {
161 sampleDate := time.Now().Add(-6 * time.Hour) // 6h ago
162 sampleCompletedAt := sampleDate.Add(5 * time.Minute)
163
164 tests := []struct {
165 name string
166 tty bool
167 opts ViewOptions
168 promptStubs func(*testing.T, *prompter.MockPrompter)
169 capiStubs func(*testing.T, *capi.CapiClientMock)
170 logRendererStubs func(*testing.T, *shared.LogRendererMock)
171 jsonFields []string
172 wantOut string
173 wantErr error
174 wantStderr string
175 wantBrowserURL string
176 }{
177 {
178 name: "with session id, not found (tty)",
179 tty: true,
180 opts: ViewOptions{
181 SelectorArg: "some-session-id",
182 SessionID: "some-session-id",
183 },
184 capiStubs: func(t *testing.T, m *capi.CapiClientMock) {
185 m.GetSessionFunc = func(_ context.Context, _ string) (*capi.Session, error) {
186 return nil, capi.ErrSessionNotFound
187 }
188 },
189 wantStderr: "session not found\n",
190 wantErr: cmdutil.SilentError,
191 },
192 {
193 name: "with session id, api error (tty)",
194 tty: true,
195 opts: ViewOptions{
196 SelectorArg: "some-session-id",
197 SessionID: "some-session-id",
198 },
199 capiStubs: func(t *testing.T, m *capi.CapiClientMock) {
200 m.GetSessionFunc = func(_ context.Context, _ string) (*capi.Session, error) {
201 return nil, errors.New("some error")
202 }
203 },
204 wantErr: errors.New("some error"),
205 },
206 {
207 name: "with session id, success, with pr and user data (tty)",
208 tty: true,
209 opts: ViewOptions{
210 SelectorArg: "some-session-id",
211 SessionID: "some-session-id",
212 },
213 capiStubs: func(t *testing.T, m *capi.CapiClientMock) {
214 m.GetSessionFunc = func(_ context.Context, id string) (*capi.Session, error) {
215 assert.Equal(t, "some-session-id", id)
216 return &capi.Session{
217 ID: "some-session-id",

Callers

nothing calls this directly

Calls 15

BrowsedURLMethod · 0.95
NewFunction · 0.92
NewWithHostFunction · 0.92
TestFunction · 0.92
NewJSONExporterFunction · 0.92
fetcherStruct · 0.85
EqualMethod · 0.80
SetStdoutTTYMethod · 0.80
SetFieldsMethod · 0.80
viewRunFunction · 0.70
AddMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected