(t *testing.T)
| 144 | } |
| 145 | |
| 146 | func TestEditRun(t *testing.T) { |
| 147 | tests := []struct { |
| 148 | name string |
| 149 | opts EditOptions |
| 150 | bodyFileContent string // if non-empty, creates a temp file and sets opts.BodyFile |
| 151 | stdinContent string // if non-empty, writes to stdin buffer |
| 152 | isTTY bool |
| 153 | setupMock func(*client.DiscussionClientMock) |
| 154 | prompter *prompter.PrompterMock |
| 155 | wantErr string |
| 156 | wantOut string |
| 157 | }{ |
| 158 | { |
| 159 | name: "success non-tty title only", |
| 160 | opts: EditOptions{ |
| 161 | Title: "Updated title", |
| 162 | TitleProvided: true, |
| 163 | }, |
| 164 | setupMock: func(m *client.DiscussionClientMock) { |
| 165 | m.GetByNumberFunc = func(repo ghrepo.Interface, number int32) (*client.Discussion, error) { |
| 166 | return sampleDiscussion(), nil |
| 167 | } |
| 168 | m.UpdateFunc = func(repo ghrepo.Interface, input client.UpdateDiscussionInput) (*client.Discussion, error) { |
| 169 | assert.Equal(t, "D_1", input.DiscussionID) |
| 170 | require.NotNil(t, input.Title) |
| 171 | assert.Equal(t, "Updated title", *input.Title) |
| 172 | assert.Nil(t, input.Body) |
| 173 | assert.Nil(t, input.CategoryID) |
| 174 | return sampleDiscussion(), nil |
| 175 | } |
| 176 | }, |
| 177 | wantOut: "https://github.com/OWNER/REPO/discussions/5\n", |
| 178 | }, |
| 179 | { |
| 180 | name: "success non-tty body only", |
| 181 | opts: EditOptions{ |
| 182 | Body: "Updated body", |
| 183 | BodyProvided: true, |
| 184 | }, |
| 185 | setupMock: func(m *client.DiscussionClientMock) { |
| 186 | m.GetByNumberFunc = func(repo ghrepo.Interface, number int32) (*client.Discussion, error) { |
| 187 | return sampleDiscussion(), nil |
| 188 | } |
| 189 | m.UpdateFunc = func(repo ghrepo.Interface, input client.UpdateDiscussionInput) (*client.Discussion, error) { |
| 190 | assert.Nil(t, input.Title) |
| 191 | require.NotNil(t, input.Body) |
| 192 | assert.Equal(t, "Updated body", *input.Body) |
| 193 | assert.Nil(t, input.CategoryID) |
| 194 | return sampleDiscussion(), nil |
| 195 | } |
| 196 | }, |
| 197 | wantOut: "https://github.com/OWNER/REPO/discussions/5\n", |
| 198 | }, |
| 199 | { |
| 200 | name: "success non-tty category change", |
| 201 | opts: EditOptions{ |
| 202 | Category: "Q&A", |
| 203 | CategoryProvided: true, |
nothing calls this directly
no test coverage detected