forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_test.go
More file actions
77 lines (67 loc) · 1.67 KB
/
list_test.go
File metadata and controls
77 lines (67 loc) · 1.67 KB
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
package list
import (
"bytes"
"io/ioutil"
"testing"
"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/internal/config"
"github.com/cli/cli/pkg/cmdutil"
"github.com/cli/cli/pkg/iostreams"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAliasList(t *testing.T) {
tests := []struct {
name string
config string
isTTY bool
wantStdout string
wantStderr string
}{
{
name: "empty",
config: "",
isTTY: true,
wantStdout: "",
wantStderr: "no aliases configured\n",
},
{
name: "some",
config: heredoc.Doc(`
aliases:
co: pr checkout
gc: "!gh gist create \"$@\" | pbcopy"
`),
isTTY: true,
wantStdout: "co: pr checkout\ngc: !gh gist create \"$@\" | pbcopy\n",
wantStderr: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// TODO: change underlying config implementation so Write is not
// automatically called when editing aliases in-memory
defer config.StubWriteConfig(ioutil.Discard, ioutil.Discard)()
cfg := config.NewFromString(tt.config)
io, _, stdout, stderr := iostreams.Test()
io.SetStdoutTTY(tt.isTTY)
io.SetStdinTTY(tt.isTTY)
io.SetStderrTTY(tt.isTTY)
factory := &cmdutil.Factory{
IOStreams: io,
Config: func() (config.Config, error) {
return cfg, nil
},
}
cmd := NewCmdList(factory, nil)
cmd.SetArgs([]string{})
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(ioutil.Discard)
cmd.SetErr(ioutil.Discard)
_, err := cmd.ExecuteC()
require.NoError(t, err)
assert.Equal(t, tt.wantStdout, stdout.String())
assert.Equal(t, tt.wantStderr, stderr.String())
})
}
}