(t *testing.T)
| 142 | } |
| 143 | |
| 144 | func TestCreateRun(t *testing.T) { |
| 145 | tests := []struct { |
| 146 | name string |
| 147 | opts CreateOptions |
| 148 | isTTY bool |
| 149 | stdinContent string |
| 150 | setupMock func(*client.DiscussionClientMock) |
| 151 | prompter *prompter.PrompterMock |
| 152 | wantErr string |
| 153 | wantOut string |
| 154 | }{ |
| 155 | { |
| 156 | name: "success non-tty", |
| 157 | opts: CreateOptions{ |
| 158 | Title: "My question", |
| 159 | Body: "Details", |
| 160 | Category: "Q&A", |
| 161 | }, |
| 162 | setupMock: func(m *client.DiscussionClientMock) { |
| 163 | m.ListCategoriesFunc = func(repo ghrepo.Interface) ([]client.DiscussionCategory, error) { |
| 164 | return sampleCategories(), nil |
| 165 | } |
| 166 | m.CreateFunc = func(repo ghrepo.Interface, input client.CreateDiscussionInput) (*client.Discussion, error) { |
| 167 | assert.Equal(t, "CAT2", input.CategoryID) |
| 168 | assert.Equal(t, "My question", input.Title) |
| 169 | assert.Equal(t, "Details", input.Body) |
| 170 | return sampleDiscussion(), nil |
| 171 | } |
| 172 | }, |
| 173 | wantOut: "https://github.com/OWNER/REPO/discussions/5\n", |
| 174 | }, |
| 175 | { |
| 176 | name: "success non-tty with label", |
| 177 | opts: CreateOptions{ |
| 178 | Title: "Feature request", |
| 179 | Body: "Details", |
| 180 | Category: "general", |
| 181 | Labels: []string{"enhancement", "bug"}, |
| 182 | }, |
| 183 | setupMock: func(m *client.DiscussionClientMock) { |
| 184 | m.ListCategoriesFunc = func(repo ghrepo.Interface) ([]client.DiscussionCategory, error) { |
| 185 | return sampleCategories(), nil |
| 186 | } |
| 187 | m.ListLabelsFunc = func(repo ghrepo.Interface) ([]client.DiscussionLabel, error) { |
| 188 | return []client.DiscussionLabel{ |
| 189 | {ID: "L_bug", Name: "bug"}, |
| 190 | {ID: "L_enh", Name: "enhancement"}, |
| 191 | }, nil |
| 192 | } |
| 193 | m.CreateFunc = func(repo ghrepo.Interface, input client.CreateDiscussionInput) (*client.Discussion, error) { |
| 194 | assert.Equal(t, []string{"L_enh", "L_bug"}, input.LabelIDs) |
| 195 | return sampleDiscussion(), nil |
| 196 | } |
| 197 | }, |
| 198 | wantOut: "https://github.com/OWNER/REPO/discussions/5\n", |
| 199 | }, |
| 200 | { |
| 201 | name: "success non-tty body-file from stdin", |
nothing calls this directly
no test coverage detected