From bd12522cb2d932b5b869bf815b8c57a975dd8541 Mon Sep 17 00:00:00 2001 From: Nate Smith Date: Tue, 8 Aug 2023 15:37:58 -0700 Subject: [PATCH] finish porting existing tests --- pkg/cmd/repo/edit/edit.go | 15 +++++---------- pkg/cmd/repo/edit/edit_test.go | 31 ++++++++++++++++--------------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/pkg/cmd/repo/edit/edit.go b/pkg/cmd/repo/edit/edit.go index 4841362e7..58e32a262 100644 --- a/pkg/cmd/repo/edit/edit.go +++ b/pkg/cmd/repo/edit/edit.go @@ -458,24 +458,19 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } opts.Edits.EnableAutoMerge = &r.AutoMergeAllowed - //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter - err = prompt.SurveyAskOne(&survey.Confirm{ - Message: "Enable Auto Merge?", - Default: r.AutoMergeAllowed, - }, opts.Edits.EnableAutoMerge) + c, err := opts.Prompter.Confirm("Enable Auto Merge?", r.AutoMergeAllowed) if err != nil { return err } + opts.Edits.EnableAutoMerge = &c opts.Edits.DeleteBranchOnMerge = &r.DeleteBranchOnMerge - //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter - err = prompt.SurveyAskOne(&survey.Confirm{ - Message: "Automatically delete head branches after merging?", - Default: r.DeleteBranchOnMerge, - }, opts.Edits.DeleteBranchOnMerge) + c, err = opts.Prompter.Confirm( + "Automatically delete head branches after merging?", r.DeleteBranchOnMerge) if err != nil { return err } + opts.Edits.DeleteBranchOnMerge = &c case optionTemplateRepo: opts.Edits.IsTemplate = &r.IsTemplate //nolint:staticcheck // SA1019: prompt.SurveyAskOne is deprecated: use Prompter diff --git a/pkg/cmd/repo/edit/edit_test.go b/pkg/cmd/repo/edit/edit_test.go index 98f1cb8cc..198b2fabd 100644 --- a/pkg/cmd/repo/edit/edit_test.go +++ b/pkg/cmd/repo/edit/edit_test.go @@ -7,8 +7,6 @@ import ( "net/http" "testing" - "github.com/cli/cli/v2/pkg/prompt" - "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/internal/prompter" "github.com/cli/cli/v2/pkg/cmdutil" @@ -193,7 +191,6 @@ func Test_editRun_interactive(t *testing.T) { tests := []struct { name string opts EditOptions - askStubs func(*prompt.AskStubber) promptStubs func(*prompter.MockPrompter) httpStubs func(*testing.T, *httpmock.Registry) wantsStderr string @@ -205,7 +202,6 @@ func Test_editRun_interactive(t *testing.T) { Repository: ghrepo.NewWithHost("OWNER", "REPO", "github.com"), InteractiveMode: true, }, - askStubs: func(as *prompt.AskStubber) {}, promptStubs: func(pm *prompter.MockPrompter) { pm.RegisterMultiSelect("What do you want to edit?", nil, editList, func(_ string, _, opts []string) ([]int, error) { @@ -252,7 +248,6 @@ func Test_editRun_interactive(t *testing.T) { Repository: ghrepo.NewWithHost("OWNER", "REPO", "github.com"), InteractiveMode: true, }, - askStubs: func(as *prompt.AskStubber) {}, promptStubs: func(pm *prompter.MockPrompter) { pm.RegisterMultiSelect("What do you want to edit?", nil, editList, func(_ string, _, opts []string) ([]int, error) { @@ -312,11 +307,22 @@ func Test_editRun_interactive(t *testing.T) { Repository: ghrepo.NewWithHost("OWNER", "REPO", "github.com"), InteractiveMode: true, }, - askStubs: func(as *prompt.AskStubber) { - as.StubPrompt("What do you want to edit?").AnswerWith([]string{"Merge Options"}) - as.StubPrompt("Allowed merge strategies").AnswerWith([]string{allowMergeCommits, allowRebaseMerge}) - as.StubPrompt("Enable Auto Merge?").AnswerWith(false) - as.StubPrompt("Automatically delete head branches after merging?").AnswerWith(false) + promptStubs: func(pm *prompter.MockPrompter) { + pm.RegisterMultiSelect("What do you want to edit?", nil, editList, + func(_ string, _, opts []string) ([]int, error) { + return []int{4}, nil + }) + pm.RegisterMultiSelect("Allowed merge strategies", nil, + []string{allowMergeCommits, allowSquashMerge, allowRebaseMerge}, + func(_ string, _, opts []string) ([]int, error) { + return []int{0, 2}, nil + }) + pm.RegisterConfirm("Enable Auto Merge?", func(_ string, _ bool) (bool, error) { + return false, nil + }) + pm.RegisterConfirm("Automatically delete head branches after merging?", func(_ string, _ bool) (bool, error) { + return false, nil + }) }, httpStubs: func(t *testing.T, reg *httpmock.Registry) { reg.Register( @@ -378,11 +384,6 @@ func Test_editRun_interactive(t *testing.T) { opts := &tt.opts opts.HTTPClient = &http.Client{Transport: httpReg} opts.IO = ios - //nolint:staticcheck // SA1019: prompt.NewAskStubber is deprecated: use PrompterMock - as := prompt.NewAskStubber(t) - if tt.askStubs != nil { - tt.askStubs(as) - } err := editRun(context.Background(), opts) if tt.wantsErr == "" {