MCPcopy
hub / github.com/cli/cli / Test_createRun

Function Test_createRun

pkg/cmd/repo/create/create_test.go:189–1087  ·  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 gitignore and license",
203 opts: &CreateOptions{Interactive: true},
204 tty: true,
205 wantStdout: "✓ Created repository OWNER/REPO on github.com\n https://github.com/OWNER/REPO\n",
206 promptStubs: func(p *prompter.PrompterMock) {
207 p.ConfirmFunc = func(message string, defaultValue bool) (bool, error) {
208 switch message {
209 case "Would you like to add a README file?":
210 return false, nil
211 case "Would you like to add a .gitignore?":
212 return true, nil
213 case "Would you like to add a license?":
214 return true, nil
215 case `This will create "REPO" as a private repository on github.com. Continue?`:
216 return defaultValue, nil
217 case "Clone the new repository locally?":
218 return defaultValue, nil
219 default:
220 return false, fmt.Errorf("unexpected confirm prompt: %s", message)
221 }
222 }
223 p.InputFunc = func(message, defaultValue string) (string, error) {
224 switch message {
225 case "Repository name":
226 return "REPO", nil
227 case "Description":
228 return "my new repo", nil
229 default:
230 return "", fmt.Errorf("unexpected input prompt: %s", message)
231 }
232 }
233 p.SelectFunc = func(message, defaultValue string, options []string) (int, error) {
234 switch message {
235 case "What would you like to do?":
236 return prompter.IndexFor(options, "Create a new repository on github.com from scratch")
237 case "Visibility":
238 return prompter.IndexFor(options, "Private")
239 case "Choose a license":
240 return prompter.IndexFor(options, "GNU Lesser General Public License v3.0")
241 case "Choose a .gitignore template":
242 return prompter.IndexFor(options, "Go")
243 default:
244 return 0, fmt.Errorf("unexpected select prompt: %s", message)
245 }
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