1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
package delete
import (
"bytes"
"io"
"testing"
"gitlab.com/gitlab-org/cli/pkg/iostreams"
"github.com/MakeNowJust/heredoc/v2"
"gitlab.com/gitlab-org/cli/commands/cmdutils"
"gitlab.com/gitlab-org/cli/internal/config"
"github.com/google/shlex"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAliasDelete(t *testing.T) {
tests := []struct {
name string
config string
cli string
isTTY bool
wantStdout string
wantStderr string
wantErr string
}{
{
name: "no aliases",
config: "",
cli: "co",
isTTY: true,
wantStdout: "",
wantStderr: "",
wantErr: "no such alias 'co'.",
},
{
name: "delete one",
config: heredoc.Doc(`
aliases:
il: issue list
co: mr checkout
`),
cli: "co",
isTTY: true,
wantStdout: "",
wantStderr: "✓ Deleted alias 'co'; was 'mr checkout'.\n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer config.StubWriteConfig(io.Discard, io.Discard)()
cfg := config.NewFromString(tt.config)
ios, _, stdout, stderr := iostreams.Test()
ios.IsaTTY = tt.isTTY
ios.IsErrTTY = tt.isTTY
factoryConf := &cmdutils.Factory{
IO: ios,
Config: func() (config.Config, error) {
return cfg, nil
},
}
cmd := NewCmdDelete(factoryConf, nil)
argv, err := shlex.Split(tt.cli)
require.NoError(t, err)
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(io.Discard)
cmd.SetErr(io.Discard)
_, err = cmd.ExecuteC()
if tt.wantErr != "" {
if assert.Error(t, err) {
assert.Equal(t, tt.wantErr, err.Error())
}
return
}
require.NoError(t, err)
assert.Equal(t, tt.wantStdout, stdout.String())
assert.Equal(t, tt.wantStderr, stderr.String())
})
}
}
|