MCPcopy Create free account
hub / github.com/cli/cli / TestUploadTarget

Function TestUploadTarget

pkg/cmd/issue/artifact/client/client_test.go:83–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestUploadTarget(t *testing.T) {
84 tests := []struct {
85 name string
86 repo ghrepo.Interface
87 response string
88 want *UploadTarget
89 wantURL string
90 wantErr string
91 }{
92 {
93 name: "an issue",
94 repo: ghrepo.New("monalisa", "monas-cafe"),
95 response: `{"data":{"repository":{"hasIssuesEnabled":true,"issue":{"__typename":"Issue","number":142,` +
96 `"repository":{"id":"R_1","name":"monas-cafe","nameWithOwner":"monalisa/monas-cafe","databaseId":1234,"viewerPermission":"WRITE"}}}}}`,
97 want: &UploadTarget{RepositoryID: 1234, ViewerPermission: "WRITE"},
98 wantURL: "https://api.github.com/graphql",
99 },
100 {
101 name: "a pull request",
102 repo: ghrepo.New("monalisa", "monas-cafe"),
103 response: `{"data":{"repository":{"hasIssuesEnabled":true,"issue":{"__typename":"PullRequest","number":142,` +
104 `"repository":{"id":"R_1","name":"monas-cafe","nameWithOwner":"monalisa/monas-cafe","databaseId":1234,"viewerPermission":"ADMIN"}}}}}`,
105 want: &UploadTarget{IsPullRequest: true, RepositoryID: 1234, ViewerPermission: "ADMIN"},
106 wantURL: "https://api.github.com/graphql",
107 },
108 {
109 name: "a repository on a ghe.com host",
110 repo: ghrepo.NewWithHost("monalisa", "monas-cafe", "monas-cafe.ghe.com"),
111 response: `{"data":{"repository":{"hasIssuesEnabled":true,"issue":{"__typename":"Issue","number":142,` +
112 `"repository":{"id":"R_1","name":"monas-cafe","nameWithOwner":"monalisa/monas-cafe","databaseId":1234,"viewerPermission":"READ"}}}}}`,
113 want: &UploadTarget{RepositoryID: 1234, ViewerPermission: "READ"},
114 wantURL: "https://api.monas-cafe.ghe.com/graphql",
115 },
116 {
117 name: "a number that is neither",
118 repo: ghrepo.New("monalisa", "monas-cafe"),
119 response: `{"data":{"repository":{"hasIssuesEnabled":true,"issue":null}},"errors":[{"type":"NOT_FOUND",` +
120 `"message":"Could not resolve to an issue or pull request with the number of 142.","path":["repository","issue"]}]}`,
121 wantURL: "https://api.github.com/graphql",
122 wantErr: "GraphQL: Could not resolve to an issue or pull request with the number of 142. (repository.issue)",
123 },
124 }
125
126 for _, tt := range tests {
127 t.Run(tt.name, func(t *testing.T) {
128 reg := &httpmock.Registry{}
129 defer reg.Verify(t)
130 reg.Register(
131 httpmock.GraphQL(`query IssueByNumber\b`),
132 httpmock.GraphQLQuery(tt.response, func(query string, vars map[string]any) {
133 assert.Contains(t, query, "databaseId")
134 assert.Contains(t, query, "viewerPermission")
135 assert.Equal(t, "monalisa", vars["owner"])
136 assert.Equal(t, "monas-cafe", vars["repo"])
137 assert.Equal(t, float64(142), vars["number"])
138 }),
139 )
140

Callers

nothing calls this directly

Calls 13

VerifyMethod · 0.95
RegisterMethod · 0.95
UploadTargetMethod · 0.95
NewFunction · 0.92
NewWithHostFunction · 0.92
GraphQLFunction · 0.92
GraphQLQueryFunction · 0.92
NewArtifactClientFunction · 0.85
ContainsMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected