(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func 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) { |
nothing calls this directly
no test coverage detected