(t *testing.T)
| 187 | } |
| 188 | |
| 189 | func 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 | }, |
nothing calls this directly
no test coverage detected