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)
| 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. |
| 146 | func 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 |
nothing calls this directly
no test coverage detected