@@ -622,8 +622,8 @@ func TestRepoCreate_WithGitIgnore(t *testing.T) {
622622 if repoName := reqBody .Name ; repoName != "REPO" {
623623 t .Errorf ("expected %q, got %q" , "REPO" , repoName )
624624 }
625- if repoVisibility := reqBody .Visibility ; repoVisibility != "PRIVATE " {
626- t .Errorf ("expected %q, got %q" , "PRIVATE " , repoVisibility )
625+ if repoVisibility := reqBody .Visibility ; repoVisibility != "private " {
626+ t .Errorf ("expected %q, got %q" , "private " , repoVisibility )
627627 }
628628 if ownerId := reqBody .OwnerId ; ownerId != "OWNERID" {
629629 t .Errorf ("expected %q, got %q" , "OWNERID" , ownerId )
@@ -721,8 +721,97 @@ func TestRepoCreate_WithBothGitIgnoreLicense(t *testing.T) {
721721 if repoName := reqBody .Name ; repoName != "REPO" {
722722 t .Errorf ("expected %q, got %q" , "REPO" , repoName )
723723 }
724- if repoVisibility := reqBody .Visibility ; repoVisibility != "PRIVATE" {
725- t .Errorf ("expected %q, got %q" , "PRIVATE" , repoVisibility )
724+ if repoVisibility := reqBody .Visibility ; repoVisibility != "private" {
725+ t .Errorf ("expected %q, got %q" , "private" , repoVisibility )
726+ }
727+ if ownerId := reqBody .OwnerId ; ownerId != "OWNERID" {
728+ t .Errorf ("expected %q, got %q" , "OWNERID" , ownerId )
729+ }
730+ }
731+
732+ func TestRepoCreate_WithGitIgnore_Org (t * testing.T ) {
733+ cs , cmdTeardown := run .Stub ()
734+ defer cmdTeardown (t )
735+
736+ cs .Register (`git remote add -f origin https://github\.com/OWNER/REPO\.git` , 0 , "" )
737+ cs .Register (`git rev-parse --show-toplevel` , 0 , "" )
738+
739+ as , surveyTearDown := prompt .InitAskStubber ()
740+ defer surveyTearDown ()
741+
742+ as .Stub ([]* prompt.QuestionStub {
743+ {
744+ Name : "repoVisibility" ,
745+ Value : "PRIVATE" ,
746+ },
747+ })
748+
749+ as .Stub ([]* prompt.QuestionStub {
750+ {
751+ Name : "addGitIgnore" ,
752+ Value : true ,
753+ },
754+ })
755+
756+ as .Stub ([]* prompt.QuestionStub {
757+ {
758+ Name : "chooseGitIgnore" ,
759+ Value : "Go" ,
760+ },
761+ })
762+
763+ as .Stub ([]* prompt.QuestionStub {
764+ {
765+ Name : "addLicense" ,
766+ Value : false ,
767+ },
768+ })
769+
770+ as .Stub ([]* prompt.QuestionStub {
771+ {
772+ Name : "confirmSubmit" ,
773+ Value : true ,
774+ },
775+ })
776+
777+ reg := & httpmock.Registry {}
778+ reg .Register (
779+ httpmock .REST ("GET" , "users/OWNER" ),
780+ httpmock .StringResponse (`{ "node_id": "OWNERID", "type":"Organization" }` ))
781+ reg .Register (
782+ httpmock .REST ("GET" , "gitignore/templates" ),
783+ httpmock .StringResponse (`["Actionscript","Android","AppceleratorTitanium","Autotools","Bancha","C","C++","Go"]` ))
784+ reg .Register (
785+ httpmock .REST ("POST" , "orgs/OWNER/repos" ),
786+ httpmock .StringResponse (`{"name":"REPO", "owner":{"login": "OWNER"}, "html_url":"https://github.com/OWNER/REPO"}` ))
787+ httpClient := & http.Client {Transport : reg }
788+
789+ output , err := runCommand (httpClient , "OWNER/REPO" , true )
790+ if err != nil {
791+ t .Errorf ("error running command `repo create`: %v" , err )
792+ }
793+
794+ assert .Equal (t , "" , output .String ())
795+ assert .Equal (t , "✓ Created repository OWNER/REPO on GitHub\n ✓ Added remote https://github.com/OWNER/REPO.git\n " , output .Stderr ())
796+
797+ var reqBody struct {
798+ Name string
799+ Visibility string
800+ OwnerId string
801+ LicenseTemplate string
802+ }
803+
804+ if len (reg .Requests ) != 3 {
805+ t .Fatalf ("expected 3 HTTP request, got %d" , len (reg .Requests ))
806+ }
807+
808+ bodyBytes , _ := ioutil .ReadAll (reg .Requests [2 ].Body )
809+ _ = json .Unmarshal (bodyBytes , & reqBody )
810+ if repoName := reqBody .Name ; repoName != "REPO" {
811+ t .Errorf ("expected %q, got %q" , "REPO" , repoName )
812+ }
813+ if repoVisibility := reqBody .Visibility ; repoVisibility != "private" {
814+ t .Errorf ("expected %q, got %q" , "private" , repoVisibility )
726815 }
727816 if ownerId := reqBody .OwnerId ; ownerId != "OWNERID" {
728817 t .Errorf ("expected %q, got %q" , "OWNERID" , ownerId )
0 commit comments