@@ -817,3 +817,64 @@ func TestRepoCreate_WithGitIgnore_Org(t *testing.T) {
817817 t .Errorf ("expected %q, got %q" , "OWNERID" , ownerId )
818818 }
819819}
820+
821+ func TestRepoCreate_WithConfirmFlag (t * testing.T ) {
822+ cs , cmdTeardown := run .Stub ()
823+ defer cmdTeardown (t )
824+
825+ cs .Register (`git remote add -f origin https://github\.com/OWNER/REPO\.git` , 0 , "" )
826+ cs .Register (`git rev-parse --show-toplevel` , 0 , "" )
827+
828+ reg := & httpmock.Registry {}
829+
830+ reg .Register (
831+ httpmock .GraphQL (`mutation RepositoryCreate\b` ),
832+ httpmock .StringResponse (`
833+ { "data": { "createRepository": {
834+ "repository": {
835+ "id": "REPOID",
836+ "url": "https://github.com/OWNER/REPO",
837+ "name": "REPO",
838+ "owner": {
839+ "login": "OWNER"
840+ }
841+ }
842+ } } }` ),
843+ )
844+
845+ reg .Register (
846+ httpmock .REST ("GET" , "users/OWNER" ),
847+ httpmock .StringResponse (`{ "node_id": "OWNERID" }` ),
848+ )
849+
850+ httpClient := & http.Client {Transport : reg }
851+
852+ in := "OWNER/REPO --confirm --private"
853+ output , err := runCommand (httpClient , in , true )
854+ if err != nil {
855+ t .Errorf ("error running command `repo create %v`: %v" , in , err )
856+ }
857+
858+ assert .Equal (t , "" , output .String ())
859+ assert .Equal (t , "✓ Created repository OWNER/REPO on GitHub\n ✓ Added remote https://github.com/OWNER/REPO.git\n " , output .Stderr ())
860+
861+ var reqBody struct {
862+ Query string
863+ Variables struct {
864+ Input map [string ]interface {}
865+ }
866+ }
867+
868+ if len (reg .Requests ) != 2 {
869+ t .Fatalf ("expected 2 HTTP request, got %d" , len (reg .Requests ))
870+ }
871+
872+ bodyBytes , _ := ioutil .ReadAll (reg .Requests [1 ].Body )
873+ _ = json .Unmarshal (bodyBytes , & reqBody )
874+ if repoName := reqBody .Variables .Input ["name" ].(string ); repoName != "REPO" {
875+ t .Errorf ("expected %q, got %q" , "REPO" , repoName )
876+ }
877+ if repoVisibility := reqBody .Variables .Input ["visibility" ].(string ); repoVisibility != "PRIVATE" {
878+ t .Errorf ("expected %q, got %q" , "PRIVATE" , repoVisibility )
879+ }
880+ }
0 commit comments