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

Function TestBaseRepoQuerySelections

api/queries_repo_test.go:146–202  ·  view source on GitHub ↗

TestBaseRepoQuerySelections guards fields that must be explicitly requested. A field left out of a query is silently zero rather than an error, so the selection is asserted against the request instead of the response.

(t *testing.T)

Source from the content-addressed store, hash-verified

144// A field left out of a query is silently zero rather than an error, so the
145// selection is asserted against the request instead of the response.
146func TestBaseRepoQuerySelections(t *testing.T) {
147 tests := []struct {
148 name string
149 matcher httpmock.Matcher
150 body string
151 fields []string
152 call func(*Client) error
153 }{
154 {
155 name: "GitHubRepo",
156 matcher: httpmock.GraphQL(`query RepositoryInfo\b`),
157 body: `{ "data": { "repository": { "id": "REPOID", "databaseId": 1234 } } }`,
158 fields: []string{"databaseId", "sshUrl"},
159 call: func(client *Client) error {
160 _, err := GitHubRepo(client, ghrepo.New("OWNER", "REPO"))
161 return err
162 },
163 },
164 {
165 name: "RepoNetwork",
166 matcher: httpmock.GraphQL(`query RepositoryNetwork\b`),
167 body: `{ "data": { "repo_000": { "id": "REPOID", "databaseId": 1234 } } }`,
168 fields: []string{"databaseId"},
169 call: func(client *Client) error {
170 _, err := RepoNetwork(client, []ghrepo.Interface{ghrepo.New("OWNER", "REPO")})
171 return err
172 },
173 },
174 {
175 name: "IssueRepoInfo",
176 matcher: httpmock.GraphQL(`query IssueRepositoryInfo\b`),
177 body: `{ "data": { "repository": { "id": "REPOID", "databaseId": 1234 } } }`,
178 fields: []string{"databaseId"},
179 call: func(client *Client) error {
180 _, err := IssueRepoInfo(client, ghrepo.New("OWNER", "REPO"))
181 return err
182 },
183 },
184 }
185
186 for _, tt := range tests {
187 t.Run(tt.name, func(t *testing.T) {
188 httpReg := &httpmock.Registry{}
189 defer httpReg.Verify(t)
190
191 var query string
192 httpReg.Register(tt.matcher, httpmock.GraphQLQuery(tt.body, func(q string, _ map[string]any) {
193 query = q
194 }))
195
196 require.NoError(t, tt.call(newTestClient(httpReg)))
197 for _, field := range tt.fields {
198 assert.Contains(t, query, field)
199 }
200 })
201 }
202}
203

Callers

nothing calls this directly

Calls 11

VerifyMethod · 0.95
RegisterMethod · 0.95
GraphQLFunction · 0.92
NewFunction · 0.92
GraphQLQueryFunction · 0.92
GitHubRepoFunction · 0.85
RepoNetworkFunction · 0.85
IssueRepoInfoFunction · 0.85
newTestClientFunction · 0.85
ContainsMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected