"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/cmd/repo/create/http_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.

http_test.go  (gh-cli-1.12.1):http_test.go  (gh-cli-1.13.1)
package create package create
import ( import (
"net/http"
"testing" "testing"
"github.com/cli/cli/api" "github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/pkg/httpmock" "github.com/cli/cli/pkg/httpmock"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func Test_RepoCreate(t *testing.T) { func Test_repoCreate(t *testing.T) {
reg := &httpmock.Registry{} tests := []struct {
httpClient := api.NewHTTPClient(api.ReplaceTripper(reg)) name string
hostname string
reg.Register( input repoCreateInput
httpmock.GraphQL(`mutation RepositoryCreate\b`), stubs func(t *testing.T, r *httpmock.Registry)
httpmock.GraphQLMutation(`{}`, wantErr bool
func(inputs map[string]interface{}) { wantRepo string
assert.Equal(t, inputs["description"], "roasted c }{
hestnuts") {
assert.Equal(t, inputs["homepageUrl"], "http://ex name: "create personal repository",
ample.com") hostname: "github.com",
}), input: repoCreateInput{
) Name: "winter-foods",
Description: "roasted chestnuts",
input := repoCreateInput{ HomepageURL: "http://example.com",
Description: "roasted chestnuts", Visibility: "public",
HomepageURL: "http://example.com", HasIssuesEnabled: true,
HasWikiEnabled: true,
},
stubs: func(t *testing.T, r *httpmock.Registry) {
r.Register(
httpmock.GraphQL(`mutation RepositoryCrea
te\b`),
httpmock.GraphQLMutation(
`{
"data": {
"createRepository
": {
"reposito
ry": {
"
id": "REPOID",
"
name": "REPO",
"
owner": {"login":"OWNER"},
"
url": "the://URL"
}
}
}
}`,
func(inputs map[string]interface{
}) {
assert.Equal(t, map[strin
g]interface{}{
"name":
"winter-foods",
"description":
"roasted chestnuts",
"homepageUrl":
"http://example.com",
"visibility":
"PUBLIC",
"hasIssuesEnabled
": true,
"hasWikiEnabled":
true,
}, inputs)
}),
)
},
wantRepo: "https://github.com/OWNER/REPO",
},
{
name: "create Enterprise repository",
hostname: "example.com",
input: repoCreateInput{
Name: "winter-foods",
Description: "roasted chestnuts",
HomepageURL: "http://example.com",
Visibility: "public",
HasIssuesEnabled: true,
HasWikiEnabled: true,
},
stubs: func(t *testing.T, r *httpmock.Registry) {
r.Register(
httpmock.GraphQL(`mutation RepositoryCrea
te\b`),
httpmock.GraphQLMutation(
`{
"data": {
"createRepository
": {
"reposito
ry": {
"
id": "REPOID",
"
name": "REPO",
"
owner": {"login":"OWNER"},
"
url": "the://URL"
}
}
}
}`,
func(inputs map[string]interface{
}) {
assert.Equal(t, map[strin
g]interface{}{
"name":
"winter-foods",
"description":
"roasted chestnuts",
"homepageUrl":
"http://example.com",
"visibility":
"PUBLIC",
"hasIssuesEnabled
": true,
"hasWikiEnabled":
true,
}, inputs)
}),
)
},
wantRepo: "https://example.com/OWNER/REPO",
},
{
name: "create in organization",
hostname: "github.com",
input: repoCreateInput{
Name: "crisps",
Visibility: "internal",
OwnerLogin: "snacks-inc",
HasIssuesEnabled: true,
HasWikiEnabled: true,
},
stubs: func(t *testing.T, r *httpmock.Registry) {
r.Register(
httpmock.REST("GET", "users/snacks-inc"),
httpmock.StringResponse(`{ "node_id": "OR
GID", "type": "Organization" }`))
r.Register(
httpmock.GraphQL(`mutation RepositoryCrea
te\b`),
httpmock.GraphQLMutation(
`{
"data": {
"createRepository
": {
"reposito
ry": {
"
id": "REPOID",
"
name": "REPO",
"
owner": {"login":"OWNER"},
"
url": "the://URL"
}
}
}
}`,
func(inputs map[string]interface{
}) {
assert.Equal(t, map[strin
g]interface{}{
"name":
"crisps",
"visibility":
"INTERNAL",
"ownerId":
"ORGID",
"hasIssuesEnabled
": true,
"hasWikiEnabled":
true,
}, inputs)
}),
)
},
wantRepo: "https://github.com/OWNER/REPO",
},
{
name: "create for team",
hostname: "github.com",
input: repoCreateInput{
Name: "crisps",
Visibility: "internal",
OwnerLogin: "snacks-inc",
TeamSlug: "munchies",
HasIssuesEnabled: true,
HasWikiEnabled: true,
},
stubs: func(t *testing.T, r *httpmock.Registry) {
r.Register(
httpmock.REST("GET", "orgs/snacks-inc/tea
ms/munchies"),
httpmock.StringResponse(`{ "node_id": "TE
AMID", "id": 1234, "organization": {"node_id": "ORGID"} }`))
r.Register(
httpmock.GraphQL(`mutation RepositoryCrea
te\b`),
httpmock.GraphQLMutation(
`{
"data": {
"createRepository
": {
"reposito
ry": {
"
id": "REPOID",
"
name": "REPO",
"
owner": {"login":"OWNER"},
"
url": "the://URL"
}
}
}
}`,
func(inputs map[string]interface{
}) {
assert.Equal(t, map[strin
g]interface{}{
"name":
"crisps",
"visibility":
"INTERNAL",
"ownerId":
"ORGID",
"teamId":
"TEAMID",
"hasIssuesEnabled
": true,
"hasWikiEnabled":
true,
}, inputs)
}),
)
},
wantRepo: "https://github.com/OWNER/REPO",
},
{
name: "create personal repo from template repo",
hostname: "github.com",
input: repoCreateInput{
Name: "gen-project",
Description: "my generated project",
Visibility: "private",
TemplateRepositoryID: "TPLID",
HasIssuesEnabled: true,
HasWikiEnabled: true,
},
stubs: func(t *testing.T, r *httpmock.Registry) {
r.Register(
httpmock.GraphQL(`query UserCurrent\b`),
httpmock.StringResponse(`{"data": {"viewe
r": {"id":"USERID"} } }`))
r.Register(
httpmock.GraphQL(`mutation CloneTemplateR
epository\b`),
httpmock.GraphQLMutation(
`{
"data": {
"cloneTemplateRep
ository": {
"reposito
ry": {
"
id": "REPOID",
"
name": "REPO",
"
owner": {"login":"OWNER"},
"
url": "the://URL"
}
}
}
}`,
func(inputs map[string]interface{
}) {
assert.Equal(t, map[strin
g]interface{}{
"name": "
gen-project",
"description": "
my generated project",
"visibility": "
PRIVATE",
"ownerId": "
USERID",
"repositoryId": "
TPLID",
}, inputs)
}),
)
},
wantRepo: "https://github.com/OWNER/REPO",
},
{
name: "create org repo from template repo",
hostname: "github.com",
input: repoCreateInput{
Name: "gen-project",
Description: "my generated project",
Visibility: "internal",
OwnerLogin: "myorg",
TemplateRepositoryID: "TPLID",
HasIssuesEnabled: true,
HasWikiEnabled: true,
},
stubs: func(t *testing.T, r *httpmock.Registry) {
r.Register(
httpmock.REST("GET", "users/myorg"),
httpmock.StringResponse(`{ "node_id": "OR
GID", "type": "Organization" }`))
r.Register(
httpmock.GraphQL(`mutation CloneTemplateR
epository\b`),
httpmock.GraphQLMutation(
`{
"data": {
"cloneTemplateRep
ository": {
"reposito
ry": {
"
id": "REPOID",
"
name": "REPO",
"
owner": {"login":"OWNER"},
"
url": "the://URL"
}
}
}
}`,
func(inputs map[string]interface{
}) {
assert.Equal(t, map[strin
g]interface{}{
"name": "
gen-project",
"description": "
my generated project",
"visibility": "
INTERNAL",
"ownerId": "
ORGID",
"repositoryId": "
TPLID",
}, inputs)
}),
)
},
wantRepo: "https://github.com/OWNER/REPO",
},
{
name: "create with license and gitignore",
hostname: "github.com",
input: repoCreateInput{
Name: "crisps",
Visibility: "private",
LicenseTemplate: "lgpl-3.0",
GitIgnoreTemplate: "Go",
HasIssuesEnabled: true,
HasWikiEnabled: true,
},
stubs: func(t *testing.T, r *httpmock.Registry) {
r.Register(
httpmock.REST("POST", "user/repos"),
httpmock.RESTPayload(201, `{"name":"crisp
s", "owner":{"login": "snacks-inc"}, "html_url":"the://URL"}`, func(payload map[
string]interface{}) {
assert.Equal(t, map[string]interf
ace{}{
"name": "cr
isps",
"private": tru
e,
"gitignore_template": "Go
",
"license_template": "lg
pl-3.0",
"has_issues": tru
e,
"has_wiki": tru
e,
}, payload)
}))
},
wantRepo: "https://github.com/snacks-inc/crisps",
},
{
name: "create with license and gitignore on Enterpris
e",
hostname: "example.com",
input: repoCreateInput{
Name: "crisps",
Visibility: "private",
LicenseTemplate: "lgpl-3.0",
GitIgnoreTemplate: "Go",
HasIssuesEnabled: true,
HasWikiEnabled: true,
},
stubs: func(t *testing.T, r *httpmock.Registry) {
r.Register(
httpmock.REST("POST", "api/v3/user/repos"
),
httpmock.RESTPayload(201, `{"name":"crisp
s", "owner":{"login": "snacks-inc"}, "html_url":"the://URL"}`, func(payload map[
string]interface{}) {
assert.Equal(t, map[string]interf
ace{}{
"name": "cr
isps",
"private": tru
e,
"gitignore_template": "Go
",
"license_template": "lg
pl-3.0",
"has_issues": tru
e,
"has_wiki": tru
e,
}, payload)
}))
},
wantRepo: "https://example.com/snacks-inc/crisps",
},
{
name: "create with license and gitignore in org",
hostname: "github.com",
input: repoCreateInput{
Name: "crisps",
Visibility: "INTERNAL",
OwnerLogin: "snacks-inc",
LicenseTemplate: "lgpl-3.0",
GitIgnoreTemplate: "Go",
HasIssuesEnabled: true,
HasWikiEnabled: true,
},
stubs: func(t *testing.T, r *httpmock.Registry) {
r.Register(
httpmock.REST("GET", "users/snacks-inc"),
httpmock.StringResponse(`{ "node_id": "OR
GID", "type": "Organization" }`))
r.Register(
httpmock.REST("POST", "orgs/snacks-inc/re
pos"),
httpmock.RESTPayload(201, `{"name":"crisp
s", "owner":{"login": "snacks-inc"}, "html_url":"the://URL"}`, func(payload map[
string]interface{}) {
assert.Equal(t, map[string]interf
ace{}{
"name": "cr
isps",
"private": fal
se,
"visibility": "in
ternal",
"gitignore_template": "Go
",
"license_template": "lg
pl-3.0",
"has_issues": tru
e,
"has_wiki": tru
e,
}, payload)
}))
},
wantRepo: "https://github.com/snacks-inc/crisps",
},
{
name: "create with license and gitignore for team",
hostname: "github.com",
input: repoCreateInput{
Name: "crisps",
Visibility: "internal",
OwnerLogin: "snacks-inc",
TeamSlug: "munchies",
LicenseTemplate: "lgpl-3.0",
GitIgnoreTemplate: "Go",
HasIssuesEnabled: true,
HasWikiEnabled: true,
},
stubs: func(t *testing.T, r *httpmock.Registry) {
r.Register(
httpmock.REST("GET", "orgs/snacks-inc/tea
ms/munchies"),
httpmock.StringResponse(`{ "node_id": "TE
AMID", "id": 1234, "organization": {"node_id": "ORGID"} }`))
r.Register(
httpmock.REST("POST", "orgs/snacks-inc/re
pos"),
httpmock.RESTPayload(201, `{"name":"crisp
s", "owner":{"login": "snacks-inc"}, "html_url":"the://URL"}`, func(payload map[
string]interface{}) {
assert.Equal(t, map[string]interf
ace{}{
"name": "cr
isps",
"private": fal
se,
"visibility": "in
ternal",
"gitignore_template": "Go
",
"license_template": "lg
pl-3.0",
"team_id": flo
at64(1234),
"has_issues": tru
e,
"has_wiki": tru
e,
}, payload)
}))
},
wantRepo: "https://github.com/snacks-inc/crisps",
},
} }
for _, tt := range tests {
_, err := repoCreate(httpClient, "github.com", input, "") t.Run(tt.name, func(t *testing.T) {
if err != nil { reg := &httpmock.Registry{}
t.Fatalf("unexpected error: %v", err) defer reg.Verify(t)
} tt.stubs(t, reg)
httpClient := &http.Client{Transport: reg}
if len(reg.Requests) != 1 { r, err := repoCreate(httpClient, tt.hostname, tt.input)
t.Fatalf("expected 1 HTTP request, seen %d", len(reg.Requests)) if tt.wantErr {
assert.Error(t, err)
return
} else {
assert.NoError(t, err)
}
assert.Equal(t, tt.wantRepo, ghrepo.GenerateRepoURL(r, ""
))
})
} }
} }
 End of changes. 4 change blocks. 
27 lines changed or deleted 540 lines changed or added

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