MCPcopy
hub / github.com/cli/cli / TestSearcherCode

Function TestSearcherCode

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

Source from the content-addressed store, hash-verified

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