(t *testing.T)
| 1305 | } |
| 1306 | |
| 1307 | func Test_createRun_interactive(t *testing.T) { |
| 1308 | const contentCmd = `git tag --list .* --format=%\(contents\)` |
| 1309 | const signatureCmd = `git tag --list .* --format=%\(contents:signature\)` |
| 1310 | |
| 1311 | defaultRunStubs := func(rs *run.CommandStubber) { |
| 1312 | rs.Register(contentCmd, 1, "") |
| 1313 | } |
| 1314 | |
| 1315 | tests := []struct { |
| 1316 | name string |
| 1317 | httpStubs func(*httpmock.Registry) |
| 1318 | prompterStubs func(*testing.T, *prompter.MockPrompter) |
| 1319 | runStubs func(*run.CommandStubber) |
| 1320 | opts *CreateOptions |
| 1321 | wantParams map[string]interface{} |
| 1322 | wantOut string |
| 1323 | wantErr string |
| 1324 | }{ |
| 1325 | { |
| 1326 | name: "create a release from existing tag", |
| 1327 | opts: &CreateOptions{}, |
| 1328 | prompterStubs: func(t *testing.T, pm *prompter.MockPrompter) { |
| 1329 | pm.RegisterSelect("Choose a tag", |
| 1330 | []string{"v1.2.3", "v1.2.2", "v1.0.0", "v0.1.2", "Create a new tag"}, |
| 1331 | func(_, _ string, opts []string) (int, error) { |
| 1332 | return prompter.IndexFor(opts, "v1.2.3") |
| 1333 | }) |
| 1334 | pm.RegisterSelect("Release notes", |
| 1335 | []string{"Write my own", "Write using generated notes as template", "Leave blank"}, |
| 1336 | func(_, _ string, opts []string) (int, error) { |
| 1337 | return prompter.IndexFor(opts, "Leave blank") |
| 1338 | }) |
| 1339 | pm.RegisterSelect("Submit?", |
| 1340 | []string{"Publish release", "Save as draft", "Cancel"}, |
| 1341 | func(_, _ string, opts []string) (int, error) { |
| 1342 | return prompter.IndexFor(opts, "Publish release") |
| 1343 | }) |
| 1344 | pm.RegisterInput("Title (optional)", func(_, d string) (string, error) { |
| 1345 | return d, nil |
| 1346 | }) |
| 1347 | pm.RegisterConfirm("Is this a prerelease?", func(_ string, _ bool) (bool, error) { |
| 1348 | return false, nil |
| 1349 | }) |
| 1350 | }, |
| 1351 | runStubs: defaultRunStubs, |
| 1352 | httpStubs: func(reg *httpmock.Registry) { |
| 1353 | reg.Register(httpmock.REST("GET", "repos/OWNER/REPO/tags"), httpmock.StatusStringResponse(200, `[ |
| 1354 | { "name": "v1.2.3" }, { "name": "v1.2.2" }, { "name": "v1.0.0" }, { "name": "v0.1.2" } |
| 1355 | ]`)) |
| 1356 | reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases/generate-notes"), |
| 1357 | httpmock.StatusStringResponse(200, `{ |
| 1358 | "name": "generated name", |
| 1359 | "body": "generated body" |
| 1360 | }`)) |
| 1361 | reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.StatusStringResponse(201, `{ |
| 1362 | "url": "https://api.github.com/releases/123", |
| 1363 | "upload_url": "https://api.github.com/assets/upload", |
| 1364 | "html_url": "https://github.com/OWNER/REPO/releases/tag/v1.2.3" |
nothing calls this directly
no test coverage detected