Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/cmd/repo/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Co
if !opts.IO.CanPrompt() {
return cmdutil.FlagErrorf("cannot non-interactively delete current repository. Please specify a repository or run interactively")
}
_, _ = fmt.Fprintln(opts.IO.ErrOut, "Warning: `--yes` is ignored since no repository was specified")
opts.Confirmed = false
}

Expand Down
67 changes: 37 additions & 30 deletions pkg/cmd/repo/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import (

func TestNewCmdDelete(t *testing.T) {
tests := []struct {
name string
input string
tty bool
output DeleteOptions
wantErr bool
errMsg string
name string
input string
tty bool
output DeleteOptions
wantErr bool
wantErrMsg string
wantStderr string
}{
{
name: "confirm flag",
Expand All @@ -36,11 +37,11 @@ func TestNewCmdDelete(t *testing.T) {
output: DeleteOptions{RepoArg: "OWNER/REPO", Confirmed: true},
},
{
name: "no confirmation notty",
input: "OWNER/REPO",
output: DeleteOptions{RepoArg: "OWNER/REPO"},
wantErr: true,
errMsg: "--yes required when not running interactively",
name: "no confirmation notty",
input: "OWNER/REPO",
output: DeleteOptions{RepoArg: "OWNER/REPO"},
wantErr: true,
wantErrMsg: "--yes required when not running interactively",
},
{
name: "base repo resolution",
Expand All @@ -49,33 +50,37 @@ func TestNewCmdDelete(t *testing.T) {
output: DeleteOptions{},
},
{
name: "yes flag ignored when no argument tty",
tty: true,
input: "--yes",
output: DeleteOptions{Confirmed: false}, // --yes should be ignored
name: "yes flag ignored when no argument tty",
tty: true,
input: "--yes",
output: DeleteOptions{Confirmed: false}, // --yes should be ignored
wantErr: false,
wantStderr: "Warning: `--yes` is ignored since no repository was specified\n",
},
{
name: "yes flag error when no argument notty",
input: "--yes",
wantErr: true,
errMsg: "cannot non-interactively delete current repository. Please specify a repository or run interactively",
name: "yes flag error when no argument notty",
input: "--yes",
wantErr: true,
wantErrMsg: "cannot non-interactively delete current repository. Please specify a repository or run interactively",
},
{
name: "confirm flag error when no argument notty",
input: "--confirm",
wantErr: true,
errMsg: "cannot non-interactively delete current repository. Please specify a repository or run interactively",
name: "confirm flag error when no argument notty",
input: "--confirm",
wantErr: true,
wantErrMsg: "cannot non-interactively delete current repository. Please specify a repository or run interactively",
},
{
name: "confirm flag also ignored when no argument tty",
tty: true,
input: "--confirm",
output: DeleteOptions{Confirmed: false}, // --confirm should also be ignored
name: "confirm flag also ignored when no argument tty",
tty: true,
input: "--confirm",
output: DeleteOptions{Confirmed: false}, // --confirm should also be ignored
wantStderr: "Warning: `--yes` is ignored since no repository was specified\n",
// Note: This does not confuse the user, as deprecation warnings are shown: "Flag --confirm has been deprecated, use `--yes` instead"
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ios, _, _, _ := iostreams.Test()
ios, _, _, stdErr := iostreams.Test()
ios.SetStdinTTY(tt.tty)
ios.SetStdoutTTY(tt.tty)
f := &cmdutil.Factory{
Expand All @@ -91,15 +96,17 @@ func TestNewCmdDelete(t *testing.T) {
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(&bytes.Buffer{})
cmd.SetErr(&bytes.Buffer{})
cmd.SetErr(stdErr)

_, err = cmd.ExecuteC()

if tt.wantErr {
assert.Error(t, err)
assert.Equal(t, tt.errMsg, err.Error())
assert.Equal(t, tt.wantErrMsg, err.Error())
return
}
assert.NoError(t, err)
assert.Equal(t, tt.wantStderr, stdErr.String())
assert.Equal(t, tt.output.RepoArg, gotOpts.RepoArg)
})
}
Expand Down