(t *testing.T)
| 237 | } |
| 238 | |
| 239 | func TestCommentRun(t *testing.T) { |
| 240 | tests := []struct { |
| 241 | name string |
| 242 | opts CommentOptions |
| 243 | bodyFileContent string |
| 244 | stdinContent string |
| 245 | isTTY bool |
| 246 | setupMock func(*testing.T, *client.DiscussionClientMock) |
| 247 | prompter *prompter.PrompterMock |
| 248 | wantErr string |
| 249 | wantOut string |
| 250 | }{ |
| 251 | { |
| 252 | name: "non-tty add comment with body", |
| 253 | opts: CommentOptions{ |
| 254 | ParsedArg: &shared.ParsedDiscussionOrCommentArg{Number: 5}, |
| 255 | Body: "Hello world", |
| 256 | }, |
| 257 | setupMock: func(t *testing.T, m *client.DiscussionClientMock) { |
| 258 | m.GetByNumberFunc = func(repo ghrepo.Interface, number int32) (*client.Discussion, error) { |
| 259 | assert.Equal(t, int32(5), number) |
| 260 | return sampleDiscussion(), nil |
| 261 | } |
| 262 | m.AddCommentFunc = func(repo ghrepo.Interface, discussionID, body, replyToID string) (*client.DiscussionComment, error) { |
| 263 | assert.Equal(t, "D_1", discussionID) |
| 264 | assert.Equal(t, "Hello world", body) |
| 265 | assert.Equal(t, "", replyToID) |
| 266 | return sampleComment(), nil |
| 267 | } |
| 268 | }, |
| 269 | wantOut: "https://github.com/OWNER/REPO/discussions/5#discussioncomment-1\n", |
| 270 | }, |
| 271 | { |
| 272 | name: "non-tty add comment with body-file", |
| 273 | opts: CommentOptions{ |
| 274 | ParsedArg: &shared.ParsedDiscussionOrCommentArg{Number: 5}, |
| 275 | }, |
| 276 | bodyFileContent: "Body from file", |
| 277 | setupMock: func(t *testing.T, m *client.DiscussionClientMock) { |
| 278 | m.GetByNumberFunc = func(repo ghrepo.Interface, number int32) (*client.Discussion, error) { |
| 279 | return sampleDiscussion(), nil |
| 280 | } |
| 281 | m.AddCommentFunc = func(repo ghrepo.Interface, discussionID, body, replyToID string) (*client.DiscussionComment, error) { |
| 282 | assert.Equal(t, "Body from file", body) |
| 283 | return sampleComment(), nil |
| 284 | } |
| 285 | }, |
| 286 | wantOut: "https://github.com/OWNER/REPO/discussions/5#discussioncomment-1\n", |
| 287 | }, |
| 288 | { |
| 289 | name: "non-tty add comment with body-file from stdin", |
| 290 | opts: CommentOptions{ |
| 291 | ParsedArg: &shared.ParsedDiscussionOrCommentArg{Number: 5}, |
| 292 | BodyFile: "-", |
| 293 | }, |
| 294 | stdinContent: "Body from stdin", |
| 295 | setupMock: func(t *testing.T, m *client.DiscussionClientMock) { |
| 296 | m.GetByNumberFunc = func(repo ghrepo.Interface, number int32) (*client.Discussion, error) { |
nothing calls this directly
no test coverage detected