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

Function TestSearcherCode

pkg/search/searcher_test.go:17–280  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestSearcherCode(t *testing.T) {
18 query := Query{
19 Keywords: []string{"keyword"},
20 Kind: "code",
21 Limit: 30,
22 Qualifiers: Qualifiers{
23 Language: "go",
24 },
25 }
26
27 values := url.Values{
28 "page": []string{"1"},
29 "per_page": []string{"30"},
30 "q": []string{"keyword language:go"},
31 }
32
33 tests := []struct {
34 name string
35 host string
36 query Query
37 result CodeResult
38 wantErr bool
39 errMsg string
40 httpStubs func(reg *httpmock.Registry)
41 }{
42 {
43 name: "searches code",
44 query: query,
45 result: CodeResult{
46 IncompleteResults: false,
47 Items: []Code{{Name: "file.go"}},
48 Total: 1,
49 },
50 httpStubs: func(reg *httpmock.Registry) {
51 reg.Register(
52 httpmock.QueryMatcher("GET", "search/code", values),
53 httpmock.JSONResponse(map[string]interface{}{
54 "incomplete_results": false,
55 "total_count": 1,
56 "items": []interface{}{
57 map[string]interface{}{
58 "name": "file.go",
59 },
60 },
61 }),
62 )
63 },
64 },
65 {
66 name: "searches code for enterprise host",
67 host: "enterprise.com",
68 query: query,
69 result: CodeResult{
70 IncompleteResults: false,
71 Items: []Code{{Name: "file.go"}},
72 Total: 1,
73 },
74 httpStubs: func(reg *httpmock.Registry) {

Callers

nothing calls this directly

Calls 11

RegisterMethod · 0.95
VerifyMethod · 0.95
CodeMethod · 0.95
QueryMatcherFunction · 0.92
JSONResponseFunction · 0.92
WithHeaderFunction · 0.92
StatusStringResponseFunction · 0.92
initializeFunction · 0.85
NewSearcherFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected