"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/cmd/repo/create/create_test.go" between
gh-cli-1.12.1.tar.gz and gh-cli-1.13.1.tar.gz

About: GitHub CLI is GitHub’s official command line tool.

create_test.go  (gh-cli-1.12.1):create_test.go  (gh-cli-1.13.1)
skipping to change at line 609 skipping to change at line 609
httpClient := &http.Client{Transport: reg} httpClient := &http.Client{Transport: reg}
output, err := runCommand(httpClient, "OWNER/REPO", true) output, err := runCommand(httpClient, "OWNER/REPO", true)
if err != nil { if err != nil {
t.Errorf("error running command `repo create`: %v", err) t.Errorf("error running command `repo create`: %v", err)
} }
assert.Equal(t, "", output.String()) assert.Equal(t, "", output.String())
assert.Equal(t, "✓ Created repository OWNER/REPO on GitHub\n✓ Added remot e https://github.com/OWNER/REPO.git\n", output.Stderr()) assert.Equal(t, "✓ Created repository OWNER/REPO on GitHub\n✓ Added remot e https://github.com/OWNER/REPO.git\n", output.Stderr())
var reqBody struct {
Name string
Visibility string
OwnerId string
LicenseTemplate string
}
if len(reg.Requests) != 3 { if len(reg.Requests) != 3 {
t.Fatalf("expected 3 HTTP request, got %d", len(reg.Requests)) t.Fatalf("expected 3 HTTP request, got %d", len(reg.Requests))
} }
bodyBytes, _ := ioutil.ReadAll(reg.Requests[2].Body) reqBody := make(map[string]interface{})
_ = json.Unmarshal(bodyBytes, &reqBody) dec := json.NewDecoder(reg.Requests[2].Body)
if repoName := reqBody.Name; repoName != "REPO" { assert.NoError(t, dec.Decode(&reqBody))
t.Errorf("expected %q, got %q", "REPO", repoName)
} if gitignore := reqBody["gitignore_template"]; gitignore != "Go" {
if repoVisibility := reqBody.Visibility; repoVisibility != "private" { t.Errorf("expected %q, got %q", "Go", gitignore)
t.Errorf("expected %q, got %q", "private", repoVisibility)
} }
if ownerId := reqBody.OwnerId; ownerId != "OWNERID" { if license := reqBody["license_template"]; license != nil {
t.Errorf("expected %q, got %q", "OWNERID", ownerId) t.Errorf("expected %v, got %v", nil, license)
} }
} }
func TestRepoCreate_WithBothGitIgnoreLicense(t *testing.T) { func TestRepoCreate_WithBothGitIgnoreLicense(t *testing.T) {
cs, cmdTeardown := run.Stub() cs, cmdTeardown := run.Stub()
defer cmdTeardown(t) defer cmdTeardown(t)
cs.Register(`git remote add -f origin https://github\.com/OWNER/REPO\.git `, 0, "") cs.Register(`git remote add -f origin https://github\.com/OWNER/REPO\.git `, 0, "")
cs.Register(`git rev-parse --show-toplevel`, 0, "") cs.Register(`git rev-parse --show-toplevel`, 0, "")
skipping to change at line 674 skipping to change at line 666
as.Stub([]*prompt.QuestionStub{ as.Stub([]*prompt.QuestionStub{
{ {
Name: "addLicense", Name: "addLicense",
Value: true, Value: true,
}, },
}) })
as.Stub([]*prompt.QuestionStub{ as.Stub([]*prompt.QuestionStub{
{ {
Name: "chooseLicense", Name: "chooseLicense",
Value: "GNU Affero General Public License v3.0", Value: "GNU Lesser General Public License v3.0",
}, },
}) })
as.Stub([]*prompt.QuestionStub{ as.Stub([]*prompt.QuestionStub{
{ {
Name: "confirmSubmit", Name: "confirmSubmit",
Value: true, Value: true,
}, },
}) })
skipping to change at line 708 skipping to change at line 700
httpClient := &http.Client{Transport: reg} httpClient := &http.Client{Transport: reg}
output, err := runCommand(httpClient, "OWNER/REPO", true) output, err := runCommand(httpClient, "OWNER/REPO", true)
if err != nil { if err != nil {
t.Errorf("error running command `repo create`: %v", err) t.Errorf("error running command `repo create`: %v", err)
} }
assert.Equal(t, "", output.String()) assert.Equal(t, "", output.String())
assert.Equal(t, "✓ Created repository OWNER/REPO on GitHub\n✓ Added remot e https://github.com/OWNER/REPO.git\n", output.Stderr()) assert.Equal(t, "✓ Created repository OWNER/REPO on GitHub\n✓ Added remot e https://github.com/OWNER/REPO.git\n", output.Stderr())
var reqBody struct {
Name string
Visibility string
OwnerId string
LicenseTemplate string
}
if len(reg.Requests) != 4 { if len(reg.Requests) != 4 {
t.Fatalf("expected 4 HTTP request, got %d", len(reg.Requests)) t.Fatalf("expected 4 HTTP request, got %d", len(reg.Requests))
} }
bodyBytes, _ := ioutil.ReadAll(reg.Requests[3].Body) reqBody := make(map[string]interface{})
_ = json.Unmarshal(bodyBytes, &reqBody) dec := json.NewDecoder(reg.Requests[3].Body)
if repoName := reqBody.Name; repoName != "REPO" { assert.NoError(t, dec.Decode(&reqBody))
t.Errorf("expected %q, got %q", "REPO", repoName)
} if gitignore := reqBody["gitignore_template"]; gitignore != "Go" {
if repoVisibility := reqBody.Visibility; repoVisibility != "private" { t.Errorf("expected %q, got %q", "Go", gitignore)
t.Errorf("expected %q, got %q", "private", repoVisibility)
} }
if ownerId := reqBody.OwnerId; ownerId != "OWNERID" { if license := reqBody["license_template"]; license != "lgpl-3.0" {
t.Errorf("expected %q, got %q", "OWNERID", ownerId) t.Errorf("expected %q, got %q", "lgpl-3.0", license)
} }
} }
func TestRepoCreate_WithGitIgnore_Org(t *testing.T) { func TestRepoCreate_WithConfirmFlag(t *testing.T) {
cs, cmdTeardown := run.Stub() cs, cmdTeardown := run.Stub()
defer cmdTeardown(t) defer cmdTeardown(t)
cs.Register(`git remote add -f origin https://github\.com/OWNER/REPO\.git `, 0, "") cs.Register(`git remote add -f origin https://github\.com/OWNER/REPO\.git `, 0, "")
cs.Register(`git rev-parse --show-toplevel`, 0, "") cs.Register(`git rev-parse --show-toplevel`, 0, "")
as, surveyTearDown := prompt.InitAskStubber() reg := &httpmock.Registry{}
defer surveyTearDown()
as.Stub([]*prompt.QuestionStub{
{
Name: "repoVisibility",
Value: "PRIVATE",
},
})
as.Stub([]*prompt.QuestionStub{
{
Name: "addGitIgnore",
Value: true,
},
})
as.Stub([]*prompt.QuestionStub{
{
Name: "chooseGitIgnore",
Value: "Go",
},
})
as.Stub([]*prompt.QuestionStub{
{
Name: "addLicense",
Value: false,
},
})
as.Stub([]*prompt.QuestionStub{ reg.Register(
{ httpmock.GraphQL(`mutation RepositoryCreate\b`),
Name: "confirmSubmit", httpmock.StringResponse(`
Value: true, { "data": { "createRepository": {
}, "repository": {
}) "id": "REPOID",
"url": "https://github.com/OWNER/REPO",
"name": "REPO",
"owner": {
"login": "OWNER"
}
}
} } }`),
)
reg := &httpmock.Registry{}
reg.Register( reg.Register(
httpmock.REST("GET", "users/OWNER"), httpmock.REST("GET", "users/OWNER"),
httpmock.StringResponse(`{ "node_id": "OWNERID", "type":"Organiza httpmock.StringResponse(`{ "node_id": "OWNERID" }`),
tion" }`)) )
reg.Register(
httpmock.REST("GET", "gitignore/templates"),
httpmock.StringResponse(`["Actionscript","Android","AppceleratorT
itanium","Autotools","Bancha","C","C++","Go"]`))
reg.Register(
httpmock.REST("POST", "orgs/OWNER/repos"),
httpmock.StringResponse(`{"name":"REPO", "owner":{"login": "OWNER
"}, "html_url":"https://github.com/OWNER/REPO"}`))
httpClient := &http.Client{Transport: reg} httpClient := &http.Client{Transport: reg}
output, err := runCommand(httpClient, "OWNER/REPO", true) in := "OWNER/REPO --confirm --private"
output, err := runCommand(httpClient, in, true)
if err != nil { if err != nil {
t.Errorf("error running command `repo create`: %v", err) t.Errorf("error running command `repo create %v`: %v", in, err)
} }
assert.Equal(t, "", output.String()) assert.Equal(t, "", output.String())
assert.Equal(t, "✓ Created repository OWNER/REPO on GitHub\n✓ Added remot e https://github.com/OWNER/REPO.git\n", output.Stderr()) assert.Equal(t, "✓ Created repository OWNER/REPO on GitHub\n✓ Added remot e https://github.com/OWNER/REPO.git\n", output.Stderr())
var reqBody struct { var reqBody struct {
Name string Query string
Visibility string Variables struct {
OwnerId string Input map[string]interface{}
LicenseTemplate string }
} }
if len(reg.Requests) != 3 { if len(reg.Requests) != 2 {
t.Fatalf("expected 3 HTTP request, got %d", len(reg.Requests)) t.Fatalf("expected 2 HTTP request, got %d", len(reg.Requests))
} }
bodyBytes, _ := ioutil.ReadAll(reg.Requests[2].Body) bodyBytes, _ := ioutil.ReadAll(reg.Requests[1].Body)
_ = json.Unmarshal(bodyBytes, &reqBody) _ = json.Unmarshal(bodyBytes, &reqBody)
if repoName := reqBody.Name; repoName != "REPO" { if repoName := reqBody.Variables.Input["name"].(string); repoName != "REP O" {
t.Errorf("expected %q, got %q", "REPO", repoName) t.Errorf("expected %q, got %q", "REPO", repoName)
} }
if repoVisibility := reqBody.Visibility; repoVisibility != "private" { if repoVisibility := reqBody.Variables.Input["visibility"].(string); repo
t.Errorf("expected %q, got %q", "private", repoVisibility) Visibility != "PRIVATE" {
} t.Errorf("expected %q, got %q", "PRIVATE", repoVisibility)
if ownerId := reqBody.OwnerId; ownerId != "OWNERID" {
t.Errorf("expected %q, got %q", "OWNERID", ownerId)
} }
} }
 End of changes. 19 change blocks. 
96 lines changed or deleted 50 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)