MCPcopy
hub / github.com/cli/cli / TestGetPullRequestDatabaseID

Function TestGetPullRequestDatabaseID

pkg/cmd/agent-task/capi/sessions_test.go:1841–1913  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1839 }
1840}
1841func TestGetPullRequestDatabaseID(t *testing.T) {
1842 tests := []struct {
1843 name string
1844 httpStubs func(*testing.T, *httpmock.Registry)
1845 wantErr string
1846 wantDatabaseID int64
1847 wantURL string
1848 }{
1849 {
1850 name: "graphql error",
1851 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
1852 reg.Register(
1853 httpmock.WithHost(httpmock.GraphQL(`query GetPullRequestFullDatabaseID\b`), "api.github.com"),
1854 httpmock.StringResponse(`{"data":{}, "errors": [{"message": "some gql error"}]}`),
1855 )
1856 },
1857 wantErr: "some gql error",
1858 },
1859 {
1860 // This never happens in practice and it's just to cover more code path
1861 name: "non-int database ID",
1862 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
1863 reg.Register(
1864 httpmock.WithHost(httpmock.GraphQL(`query GetPullRequestFullDatabaseID\b`), "api.github.com"),
1865 httpmock.StringResponse(`{"data": {"repository": {"pullRequest": {"fullDatabaseId": "non-int", "url": "some-url"}}}}`),
1866 )
1867 },
1868 wantErr: `strconv.ParseInt: parsing "non-int": invalid syntax`,
1869 wantURL: "some-url",
1870 },
1871 {
1872 name: "success",
1873 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
1874 reg.Register(
1875 httpmock.WithHost(httpmock.GraphQL(`query GetPullRequestFullDatabaseID\b`), "api.github.com"),
1876 httpmock.GraphQLQuery(`{"data": {"repository": {"pullRequest": {"fullDatabaseId": "999", "url": "some-url"}}}}`, func(s string, m map[string]interface{}) {
1877 assert.Equal(t, "OWNER", m["owner"])
1878 assert.Equal(t, "REPO", m["repo"])
1879 assert.Equal(t, float64(42), m["number"])
1880 }),
1881 )
1882 },
1883 wantDatabaseID: 999,
1884 wantURL: "some-url",
1885 },
1886 }
1887
1888 for _, tt := range tests {
1889 t.Run(tt.name, func(t *testing.T) {
1890 reg := &httpmock.Registry{}
1891 if tt.httpStubs != nil {
1892 tt.httpStubs(t, reg)
1893 }
1894 defer reg.Verify(t)
1895
1896 httpClient := &http.Client{Transport: reg}
1897
1898 capiClient := NewCAPIClient(httpClient, "", "github.com", "https://api.githubcopilot.com")

Callers

nothing calls this directly

Calls 10

RegisterMethod · 0.95
VerifyMethod · 0.95
WithHostFunction · 0.92
GraphQLFunction · 0.92
StringResponseFunction · 0.92
GraphQLQueryFunction · 0.92
NewCAPIClientFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected