MCPcopy Index your code
hub / github.com/cli/cli / Test_listReposWithLanguage

Function Test_listReposWithLanguage

pkg/cmd/repo/list/http_test.go:15–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func Test_listReposWithLanguage(t *testing.T) {
16 reg := httpmock.Registry{}
17 defer reg.Verify(t)
18
19 var searchData struct {
20 Query string
21 Variables map[string]interface{}
22 }
23 reg.Register(
24 httpmock.GraphQL(`query RepositoryListSearch\b`),
25 func(req *http.Request) (*http.Response, error) {
26 jsonData, err := io.ReadAll(req.Body)
27 if err != nil {
28 return nil, err
29 }
30 err = json.Unmarshal(jsonData, &searchData)
31 if err != nil {
32 return nil, err
33 }
34
35 respBody, err := os.Open("./fixtures/repoSearch.json")
36 if err != nil {
37 return nil, err
38 }
39
40 return &http.Response{
41 StatusCode: 200,
42 Request: req,
43 Body: respBody,
44 }, nil
45 },
46 )
47
48 client := http.Client{Transport: &reg}
49 res, err := listRepos(&client, "github.com", 10, "", FilterOptions{
50 Language: "go",
51 })
52 require.NoError(t, err)
53
54 assert.Equal(t, 3, res.TotalCount)
55 assert.Equal(t, true, res.FromSearch)
56 assert.Equal(t, "octocat", res.Owner)
57 assert.Equal(t, "octocat/hello-world", res.Repositories[0].NameWithOwner)
58
59 assert.Equal(t, float64(10), searchData.Variables["perPage"])
60 assert.Equal(t, `sort:updated-desc fork:true language:go user:@me`, searchData.Variables["query"])
61}
62
63func Test_searchQuery(t *testing.T) {
64 type args struct {

Callers

nothing calls this directly

Calls 6

VerifyMethod · 0.95
RegisterMethod · 0.95
GraphQLFunction · 0.92
listReposFunction · 0.85
OpenMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected