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

Function Test_createRun

pkg/cmd/repo/create/create_test.go:189–1133  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

187}
188
189func Test_createRun(t *testing.T) {
190 tests := []struct {
191 name string
192 tty bool
193 opts *CreateOptions
194 httpStubs func(*httpmock.Registry)
195 promptStubs func(*prompter.PrompterMock)
196 execStubs func(*run.CommandStubber)
197 wantStdout string
198 wantErr bool
199 errMsg string
200 }{
201 {
202 name: "interactive create from scratch with empty name",
203 opts: &CreateOptions{Interactive: true},
204 tty: true,
205 promptStubs: func(p *prompter.PrompterMock) {
206 p.InputFunc = func(message, defaultValue string) (string, error) {
207 if message != "Repository name" || len(p.InputCalls()) != 1 {
208 return "", fmt.Errorf("unexpected input prompt: %s", message)
209 }
210 return "", nil
211 }
212 p.SelectFunc = func(message, defaultValue string, options []string) (int, error) {
213 switch message {
214 case "What would you like to do?":
215 return prompter.IndexFor(options, "Create a new repository on github.com from scratch")
216 default:
217 return 0, fmt.Errorf("unexpected select prompt: %s", message)
218 }
219 }
220 },
221 wantErr: true,
222 errMsg: "repository name cannot be blank",
223 },
224 {
225 name: "interactive create from scratch with whitespace-only name",
226 opts: &CreateOptions{Interactive: true},
227 tty: true,
228 promptStubs: func(p *prompter.PrompterMock) {
229 p.InputFunc = func(message, defaultValue string) (string, error) {
230 if message != "Repository name" || len(p.InputCalls()) != 1 {
231 return "", fmt.Errorf("unexpected input prompt: %s", message)
232 }
233 return " \t ", nil
234 }
235 p.SelectFunc = func(message, defaultValue string, options []string) (int, error) {
236 switch message {
237 case "What would you like to do?":
238 return prompter.IndexFor(options, "Create a new repository on github.com from scratch")
239 default:
240 return 0, fmt.Errorf("unexpected select prompt: %s", message)
241 }
242 }
243 },
244 wantErr: true,
245 errMsg: "repository name cannot be blank",
246 },

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
SetHostsMethod · 0.95
SetDefaultHostMethod · 0.95
VerifyMethod · 0.95
IndexForFunction · 0.92
GraphQLFunction · 0.92
StringResponseFunction · 0.92
RESTFunction · 0.92
FileResponseFunction · 0.92
RESTPayloadFunction · 0.92
GraphQLQueryFunction · 0.92
GraphQLMutationFunction · 0.92

Tested by

no test coverage detected