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
113 lines (101 loc) · 2.3 KB
/
list_test.go
File metadata and controls
113 lines (101 loc) · 2.3 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package list
import (
"bytes"
"testing"
"github.com/cli/cli/v2/internal/config"
"github.com/cli/cli/v2/pkg/cmdutil"
"github.com/cli/cli/v2/pkg/iostreams"
"github.com/google/shlex"
"github.com/stretchr/testify/assert"
)
func TestNewCmdConfigList(t *testing.T) {
tests := []struct {
name string
input string
output ListOptions
wantsErr bool
}{
{
name: "no arguments",
input: "",
output: ListOptions{},
wantsErr: false,
},
{
name: "list with host",
input: "--host HOST.com",
output: ListOptions{Hostname: "HOST.com"},
wantsErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f := &cmdutil.Factory{
Config: func() (config.Config, error) {
return config.ConfigStub{}, nil
},
}
argv, err := shlex.Split(tt.input)
assert.NoError(t, err)
var gotOpts *ListOptions
cmd := NewCmdConfigList(f, func(opts *ListOptions) error {
gotOpts = opts
return nil
})
cmd.Flags().BoolP("help", "x", false, "")
cmd.SetArgs(argv)
cmd.SetIn(&bytes.Buffer{})
cmd.SetOut(&bytes.Buffer{})
cmd.SetErr(&bytes.Buffer{})
_, err = cmd.ExecuteC()
if tt.wantsErr {
assert.Error(t, err)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.output.Hostname, gotOpts.Hostname)
})
}
}
func Test_listRun(t *testing.T) {
tests := []struct {
name string
input *ListOptions
config config.ConfigStub
stdout string
wantErr bool
}{
{
name: "list",
config: config.ConfigStub{
"HOST:git_protocol": "ssh",
"HOST:editor": "/usr/bin/vim",
"HOST:prompt": "disabled",
"HOST:pager": "less",
"HOST:http_unix_socket": "",
"HOST:browser": "brave",
},
input: &ListOptions{Hostname: "HOST"}, // ConfigStub gives empty DefaultHost
stdout: `git_protocol=ssh
editor=/usr/bin/vim
prompt=disabled
pager=less
http_unix_socket=
browser=brave
`,
},
}
for _, tt := range tests {
io, _, stdout, _ := iostreams.Test()
tt.input.IO = io
tt.input.Config = func() (config.Config, error) {
return tt.config, nil
}
t.Run(tt.name, func(t *testing.T) {
err := listRun(tt.input)
assert.NoError(t, err)
assert.Equal(t, tt.stdout, stdout.String())
//assert.Equal(t, tt.stderr, stderr.String())
})
}
}