(t *testing.T)
| 158 | } |
| 159 | |
| 160 | func 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", |
nothing calls this directly
no test coverage detected