add prompt.StubConfirm
This commit is contained in:
parent
4c57566cdc
commit
dadcf4ba96
2 changed files with 15 additions and 24 deletions
|
|
@ -294,12 +294,7 @@ func TestRepoFork_outside_survey_yes(t *testing.T) {
|
|||
cs.Stub("") // git clone
|
||||
cs.Stub("") // git remote add
|
||||
|
||||
oldConfirm := prompt.Confirm
|
||||
prompt.Confirm = func(_ string, result *bool) error {
|
||||
*result = true
|
||||
return nil
|
||||
}
|
||||
defer func() { prompt.Confirm = oldConfirm }()
|
||||
defer prompt.StubConfirm(true)()
|
||||
|
||||
output, err := RunCommand("repo fork OWNER/REPO")
|
||||
if err != nil {
|
||||
|
|
@ -329,12 +324,7 @@ func TestRepoFork_outside_survey_no(t *testing.T) {
|
|||
return &test.OutputStub{}
|
||||
})()
|
||||
|
||||
oldConfirm := prompt.Confirm
|
||||
prompt.Confirm = func(_ string, result *bool) error {
|
||||
*result = false
|
||||
return nil
|
||||
}
|
||||
defer func() { prompt.Confirm = oldConfirm }()
|
||||
defer prompt.StubConfirm(false)()
|
||||
|
||||
output, err := RunCommand("repo fork OWNER/REPO")
|
||||
if err != nil {
|
||||
|
|
@ -367,12 +357,7 @@ func TestRepoFork_in_parent_survey_yes(t *testing.T) {
|
|||
return &test.OutputStub{}
|
||||
})()
|
||||
|
||||
oldConfirm := prompt.Confirm
|
||||
prompt.Confirm = func(_ string, result *bool) error {
|
||||
*result = true
|
||||
return nil
|
||||
}
|
||||
defer func() { prompt.Confirm = oldConfirm }()
|
||||
defer prompt.StubConfirm(true)()
|
||||
|
||||
output, err := RunCommand("repo fork")
|
||||
if err != nil {
|
||||
|
|
@ -411,12 +396,7 @@ func TestRepoFork_in_parent_survey_no(t *testing.T) {
|
|||
return &test.OutputStub{}
|
||||
})()
|
||||
|
||||
oldConfirm := prompt.Confirm
|
||||
prompt.Confirm = func(_ string, result *bool) error {
|
||||
*result = false
|
||||
return nil
|
||||
}
|
||||
defer func() { prompt.Confirm = oldConfirm }()
|
||||
defer prompt.StubConfirm(false)()
|
||||
|
||||
output, err := RunCommand("repo fork")
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,17 @@ package prompt
|
|||
|
||||
import "github.com/AlecAivazis/survey/v2"
|
||||
|
||||
func StubConfirm(result bool) func() {
|
||||
orig := Confirm
|
||||
Confirm = func(_ string, r *bool) error {
|
||||
*r = result
|
||||
return nil
|
||||
}
|
||||
return func() {
|
||||
Confirm = orig
|
||||
}
|
||||
}
|
||||
|
||||
var Confirm = func(prompt string, result *bool) error {
|
||||
p := &survey.Confirm{
|
||||
Message: prompt,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue