@@ -455,19 +455,15 @@ func TestRepoCreate_withoutNameArg(t *testing.T) {
455455 Name : "repoVisibility" ,
456456 Value : "PRIVATE" ,
457457 },
458+ })
459+
460+ as .Stub ([]* prompt.QuestionStub {
458461 {
459- Name : "optionToSkip" ,
460- Value : true ,
461- },
462- {
463- Name : "gitIgnoreLicense" ,
464- Value : "license" ,
465- },
466- {
467- Name : "repoLicense" ,
468- Value : "Apache License 2.0" ,
462+ Name : "addGitIgnoreLicense" ,
463+ Value : false ,
469464 },
470465 })
466+
471467 as .Stub ([]* prompt.QuestionStub {
472468 {
473469 Name : "confirmSubmit" ,
@@ -506,3 +502,100 @@ func TestRepoCreate_withoutNameArg(t *testing.T) {
506502 t .Errorf ("expected %q, got %q" , "OWNERID" , ownerId )
507503 }
508504}
505+
506+ func TestRepoCreate_withoutNameArgWithGitIgnoreLicense (t * testing.T ) {
507+ cs , cmdTeardown := run .Stub ()
508+ defer cmdTeardown (t )
509+
510+ cs .Register (`git remote add -f origin https://github\.com/OWNER/REPO\.git` , 0 , "" )
511+ cs .Register (`git rev-parse --show-toplevel` , 0 , "" )
512+
513+ as , surveyTearDown := prompt .InitAskStubber ()
514+ defer surveyTearDown ()
515+
516+ as .Stub ([]* prompt.QuestionStub {
517+ {
518+ Name : "repoName" ,
519+ Value : "OWNER/REPO" ,
520+ },
521+ {
522+ Name : "repoDescription" ,
523+ Value : "DESCRIPTION" ,
524+ },
525+ {
526+ Name : "repoVisibility" ,
527+ Value : "PRIVATE" ,
528+ },
529+ })
530+
531+ as .Stub ([]* prompt.QuestionStub {
532+ {
533+ Name : "addGitIgnoreLicense" ,
534+ Value : true ,
535+ },
536+ })
537+
538+ as .Stub ([]* prompt.QuestionStub {
539+ {
540+ Name : "gitIgnoreLicense" ,
541+ Value : []string {"license" },
542+ },
543+ })
544+
545+ as .Stub ([]* prompt.QuestionStub {
546+ {
547+ Name : "repoLicense" ,
548+ Value : "Apache License 2.0" ,
549+ },
550+ })
551+
552+ as .Stub ([]* prompt.QuestionStub {
553+ {
554+ Name : "confirmSubmit" ,
555+ Value : true ,
556+ },
557+ })
558+
559+ reg := & httpmock.Registry {}
560+ reg .Register (
561+ httpmock .REST ("GET" , "users/OWNER" ),
562+ httpmock .StringResponse (`{ "node_id": "OWNERID" }` ))
563+ reg .Register (
564+ httpmock .REST ("GET" , "licenses" ),
565+ httpmock .StringResponse (`[{"key":"apache-2.0", "name":"Apache License 2.0"}]` ))
566+ reg .Register (
567+ httpmock .REST ("POST" , "user/repos" ),
568+ httpmock .StringResponse (`{"name":"REPO", "owner":{"login": "OWNER"}, "html_url":"https://github.com/OWNER/REPO"}` ))
569+ httpClient := & http.Client {Transport : reg }
570+
571+ output , err := runCommand (httpClient , "" , true )
572+ if err != nil {
573+ t .Errorf ("error running command `repo create`: %v" , err )
574+ }
575+
576+ assert .Equal (t , "" , output .String ())
577+ assert .Equal (t , "✓ Created repository OWNER/REPO on GitHub\n ✓ Added remote https://github.com/OWNER/REPO.git\n " , output .Stderr ())
578+
579+ var reqBody struct {
580+ Name string
581+ Visibility string
582+ OwnerId string
583+ LicenseTemplate string
584+ }
585+
586+ if len (reg .Requests ) != 3 {
587+ t .Fatalf ("expected 3 HTTP request, got %d" , len (reg .Requests ))
588+ }
589+
590+ bodyBytes , _ := ioutil .ReadAll (reg .Requests [2 ].Body )
591+ _ = json .Unmarshal (bodyBytes , & reqBody )
592+ if repoName := reqBody .Name ; repoName != "REPO" {
593+ t .Errorf ("expected %q, got %q" , "REPO" , repoName )
594+ }
595+ if repoVisibility := reqBody .Visibility ; repoVisibility != "PRIVATE" {
596+ t .Errorf ("expected %q, got %q" , "PRIVATE" , repoVisibility )
597+ }
598+ if ownerId := reqBody .OwnerId ; ownerId != "OWNERID" {
599+ t .Errorf ("expected %q, got %q" , "OWNERID" , ownerId )
600+ }
601+ }
0 commit comments