(t *testing.T)
| 167 | } |
| 168 | |
| 169 | func Test_editRun(t *testing.T) { |
| 170 | tests := []struct { |
| 171 | name string |
| 172 | opts EditOptions |
| 173 | httpStubs func(*testing.T, *httpmock.Registry) |
| 174 | wantsStderr string |
| 175 | wantsErr string |
| 176 | }{ |
| 177 | { |
| 178 | name: "change name and description", |
| 179 | opts: EditOptions{ |
| 180 | Repository: ghrepo.NewWithHost("OWNER", "REPO", "github.com"), |
| 181 | Edits: EditRepositoryInput{ |
| 182 | Homepage: sp("newURL"), |
| 183 | Description: sp("hello world!"), |
| 184 | }, |
| 185 | }, |
| 186 | httpStubs: func(t *testing.T, r *httpmock.Registry) { |
| 187 | r.Register( |
| 188 | httpmock.REST("PATCH", "repos/OWNER/REPO"), |
| 189 | httpmock.RESTPayload(200, `{}`, func(payload map[string]interface{}) { |
| 190 | assert.Equal(t, 2, len(payload)) |
| 191 | assert.Equal(t, "newURL", payload["homepage"]) |
| 192 | assert.Equal(t, "hello world!", payload["description"]) |
| 193 | })) |
| 194 | }, |
| 195 | }, |
| 196 | { |
| 197 | name: "add and remove topics", |
| 198 | opts: EditOptions{ |
| 199 | Repository: ghrepo.NewWithHost("OWNER", "REPO", "github.com"), |
| 200 | AddTopics: []string{"topic1", "topic2"}, |
| 201 | RemoveTopics: []string{"topic3"}, |
| 202 | }, |
| 203 | httpStubs: func(t *testing.T, r *httpmock.Registry) { |
| 204 | r.Register( |
| 205 | httpmock.REST("GET", "repos/OWNER/REPO/topics"), |
| 206 | httpmock.StringResponse(`{"names":["topic2", "topic3", "go"]}`)) |
| 207 | r.Register( |
| 208 | httpmock.REST("PUT", "repos/OWNER/REPO/topics"), |
| 209 | httpmock.RESTPayload(200, `{}`, func(payload map[string]interface{}) { |
| 210 | assert.Equal(t, 1, len(payload)) |
| 211 | assert.Equal(t, []interface{}{"topic2", "go", "topic1"}, payload["names"]) |
| 212 | })) |
| 213 | }, |
| 214 | }, |
| 215 | { |
| 216 | name: "allow update branch", |
| 217 | opts: EditOptions{ |
| 218 | Repository: ghrepo.NewWithHost("OWNER", "REPO", "github.com"), |
| 219 | Edits: EditRepositoryInput{ |
| 220 | AllowUpdateBranch: bp(true), |
| 221 | }, |
| 222 | }, |
| 223 | httpStubs: func(t *testing.T, r *httpmock.Registry) { |
| 224 | r.Register( |
| 225 | httpmock.REST("PATCH", "repos/OWNER/REPO"), |
| 226 | httpmock.RESTPayload(200, `{}`, func(payload map[string]interface{}) { |
nothing calls this directly
no test coverage detected