MCPcopy Create free account
hub / github.com/cli/cli / TestNewCmdView

Function TestNewCmdView

pkg/cmd/repo/gitignore/view/view_test.go:125–186  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

123}
124
125func TestNewCmdView(t *testing.T) {
126 tests := []struct {
127 name string
128 args []string
129 wantErr bool
130 wantOpts *ViewOptions
131 tty bool
132 }{
133 {
134 name: "No template",
135 args: []string{},
136 wantErr: true,
137 wantOpts: &ViewOptions{
138 Template: "",
139 },
140 },
141 {
142 name: "Happy path single template",
143 args: []string{"Go"},
144 wantErr: false,
145 wantOpts: &ViewOptions{
146 Template: "Go",
147 },
148 },
149 {
150 name: "Happy path too many templates",
151 args: []string{"Go", "Ruby"},
152 wantErr: true,
153 wantOpts: &ViewOptions{
154 Template: "",
155 },
156 },
157 }
158 for _, tt := range tests {
159 t.Run(tt.name, func(t *testing.T) {
160 ios, _, _, _ := iostreams.Test()
161 ios.SetStdinTTY(tt.tty)
162 ios.SetStdoutTTY(tt.tty)
163 ios.SetStderrTTY(tt.tty)
164
165 f := &cmdutil.Factory{
166 IOStreams: ios,
167 }
168 cmd := NewCmdView(f, func(*ViewOptions) error {
169 return nil
170 })
171 cmd.SetArgs(tt.args)
172 cmd.SetIn(&bytes.Buffer{})
173 cmd.SetOut(&bytes.Buffer{})
174 cmd.SetErr(&bytes.Buffer{})
175
176 _, err := cmd.ExecuteC()
177 if tt.wantErr {
178 assert.Error(t, err)
179 } else {
180 require.NoError(t, err)
181 }
182

Callers

nothing calls this directly

Calls 8

TestFunction · 0.92
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStderrTTYMethod · 0.80
EqualMethod · 0.80
NewCmdViewFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected