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

Function TestBaseRepoQueriesSelectDatabaseID

api/queries_repo_test.go:141–191  ·  view source on GitHub ↗

TestBaseRepoQueriesSelectDatabaseID guards the 3 queries that build the base repository. Each selection is written by hand, and a field left out of one of them 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

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

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