(t *testing.T)
| 90 | } |
| 91 | |
| 92 | func Test_listRun(t *testing.T) { |
| 93 | sampleDate := time.Now().Add(-6 * time.Hour) // 6h ago |
| 94 | sampleDateString := sampleDate.Format(time.RFC3339) |
| 95 | |
| 96 | tests := []struct { |
| 97 | name string |
| 98 | tty bool |
| 99 | capiStubs func(*testing.T, *capi.CapiClientMock) |
| 100 | limit int |
| 101 | web bool |
| 102 | jsonFields []string |
| 103 | wantOut string |
| 104 | wantErr error |
| 105 | wantStderr string |
| 106 | wantBrowserURL string |
| 107 | }{ |
| 108 | { |
| 109 | name: "viewer-scoped no sessions", |
| 110 | tty: true, |
| 111 | capiStubs: func(t *testing.T, m *capi.CapiClientMock) { |
| 112 | m.ListLatestSessionsForViewerFunc = func(ctx context.Context, limit int) ([]*capi.Session, error) { |
| 113 | return nil, nil |
| 114 | } |
| 115 | }, |
| 116 | wantErr: cmdutil.NewNoResultsError("no agent tasks found"), |
| 117 | }, |
| 118 | { |
| 119 | name: "viewer-scoped respects --limit", |
| 120 | tty: true, |
| 121 | limit: 999, |
| 122 | capiStubs: func(t *testing.T, m *capi.CapiClientMock) { |
| 123 | m.ListLatestSessionsForViewerFunc = func(ctx context.Context, limit int) ([]*capi.Session, error) { |
| 124 | assert.Equal(t, 999, limit) |
| 125 | return nil, nil |
| 126 | } |
| 127 | }, |
| 128 | wantErr: cmdutil.NewNoResultsError("no agent tasks found"), // not important |
| 129 | }, |
| 130 | { |
| 131 | name: "viewer-scoped single session (tty)", |
| 132 | tty: true, |
| 133 | capiStubs: func(t *testing.T, m *capi.CapiClientMock) { |
| 134 | m.ListLatestSessionsForViewerFunc = func(ctx context.Context, limit int) ([]*capi.Session, error) { |
| 135 | return []*capi.Session{ |
| 136 | { |
| 137 | ID: "id1", |
| 138 | Name: "s1", |
| 139 | State: "completed", |
| 140 | CreatedAt: sampleDate, |
| 141 | ResourceType: "pull", |
| 142 | PullRequest: &api.PullRequest{ |
| 143 | Number: 101, |
| 144 | Repository: &api.PRRepository{ |
| 145 | NameWithOwner: "OWNER/REPO", |
| 146 | }, |
| 147 | }, |
| 148 | }, |
| 149 | }, nil |
nothing calls this directly
no test coverage detected