Repository: cli/cli
File: pkg/cmd/release/create/create_test.go (Go)

Code before:
						return prompter.IndexFor(opts, "Publish release")
					})
				pm.RegisterInput("Title (optional)", func(_, d string) (string, error) {
					return d, nil
				})
				pm.RegisterConfirm("Is this a prerelease?", func(_ string, _ bool) (bool, error) {
					return false, nil
				})
			},
			runStubs: defaultRunStubs,
			httpStubs: func(reg *httpmock.Registry) {
				reg.Register(httpmock.REST("GET", "repos/OWNER/REPO/tags"), httpmock.StatusStringResponse(200, `[
					{ "name": "v1.2.3" }, { "name": "v1.2.2" }, { "name": "v1.0.0" }, { "name": "v0.1.2" }
				]`))
				reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases/generate-notes"),
					httpmock.StatusStringResponse(200, `{
						"name": "generated name",
						"body": "generated body"
					}`))
				reg.Register(httpmock.REST("POST", "repos/OWNER/REPO/releases"), httpmock.StatusStringResponse(201, `{
					"url": "https://api.github.com/releases/123",
					"upload_url": "https://api.github.com/assets/upload",
					"html_url": "https://github.com/OWNER/REPO/releases/tag/v1.2.3"
				}`))
			},
			wantOut: "https://github.com/OWNER/REPO/releases/tag/v1.2.3\n",
		},
		{
			name: "create a release from new tag",
			opts: &CreateOptions{},
			prompterStubs: func(t *testing.T, pm *prompter.MockPrompter) {
				pm.RegisterSelect("Choose a tag",
					[]string{"v1.2.2", "v1.0.0", "v0.1.2", "Create a new tag"},
					func(_, _ string, opts []string) (int, error) {
						return prompter.IndexFor(opts, "Create a new tag")
					})
				pm.RegisterSelect("Release notes",
					[]string{"Write my own", "Write using generated notes as template", "Leave blank"},
					func(_, _ string, opts []string) (int, error) {
						return prompter.IndexFor(opts, "Leave blank")
					})
				pm.RegisterSelect("Submit?",
					[]string{"Publish release", "Save as draft", "Cancel"},
					func(_, _ string, opts []string) (int, error) {
						return prompter.IndexFor(opts, "Publish release")
					})
				pm.RegisterInput("Tag name", func(_, d string) (string, error) {
					return "v1.2.3", nil
				})
				pm.RegisterInput("Title (optional)", func(_, d string) (string, error) {
					return d, nil

Review comment (bug):
Not sure why this `return` was here, it seems like it might have been a mistake.

I needed to remove it to get my test to initially fail since my test wants a `SilentError` while also wanting text on stderr 🧐 

Code after:
				tt.httpStubs(t, fakeHTTP)
			}
			defer fakeHTTP.Verify(t)

			tt.opts.IO = ios
			tt.opts.HttpClient = func() (*http.Client, error) {
				return &http.Client{Transport: fakeHTTP}, nil
			}
			tt.opts.BaseRepo = func() (ghrepo.Interface, error) {
				return ghrepo.FromFullName("OWNER/REPO")
			}

			tt.opts.GitClient = &git.Client{GitPath: "some/path/git"}

			rs, teardown := run.Stub()
			defer teardown(t)
			if tt.runStubs != nil {
				tt.runStubs(rs)
			}

			err := createRun(&tt.opts)
			if tt.wantErr != "" {
				require.EqualError(t, err, tt.wantErr)
			} else {
				require.NoError(t, err)
			}

			assert.Equal(t, tt.wantStdout, stdout.String())
			assert.Equal(t, tt.wantStderr, stderr.String())
		})
	}
}

func Test_createRun_interactive(t *testing.T) {
	const contentCmd = `git tag --list .* --format=%\(contents\)`
	const signatureCmd = `git tag --list .* --format=%\(contents:signature\)`

	defaultRunStubs := func(rs *run.CommandStubber) {
		rs.Register(contentCmd, 1, "")
	}

	tests := []struct {
		name          string
		httpStubs     func(*httpmock.Registry)
		prompterStubs func(*testing.T, *prompter.MockPrompter)
		runStubs      func(*run.CommandStubber)
		opts          *CreateOptions
		wantParams    map[string]interface{}
		wantOut       string
		wantErr       string
	}{