(t *testing.T)
| 70 | } |
| 71 | |
| 72 | func TestSearchService_RepositoriesTextMatch(t *testing.T) { |
| 73 | t.Parallel() |
| 74 | client, mux, _ := setup(t) |
| 75 | |
| 76 | mux.HandleFunc("/search/repositories", func(w http.ResponseWriter, r *http.Request) { |
| 77 | testMethod(t, r, "GET") |
| 78 | textMatchResponse := ` |
| 79 | { |
| 80 | "total_count": 1, |
| 81 | "incomplete_results": false, |
| 82 | "items": [ |
| 83 | { |
| 84 | "name":"gopher1" |
| 85 | } |
| 86 | ] |
| 87 | } |
| 88 | ` |
| 89 | list := strings.Split(r.Header.Get("Accept"), ",") |
| 90 | aMap := make(map[string]struct{}) |
| 91 | for _, s := range list { |
| 92 | aMap[strings.TrimSpace(s)] = struct{}{} |
| 93 | } |
| 94 | if _, ok := aMap["application/vnd.github.v3.text-match+json"]; ok { |
| 95 | textMatchResponse = ` |
| 96 | { |
| 97 | "total_count": 1, |
| 98 | "incomplete_results": false, |
| 99 | "items": [ |
| 100 | { |
| 101 | "name":"gopher1", |
| 102 | "text_matches": [ |
| 103 | { |
| 104 | "fragment": "I'm afraid my friend what you have found\nIs a gopher who lives to feed", |
| 105 | "matches": [ |
| 106 | { |
| 107 | "text": "gopher", |
| 108 | "indices": [ |
| 109 | 14, |
| 110 | 21 |
| 111 | ] |
| 112 | } |
| 113 | ] |
| 114 | } |
| 115 | ] |
| 116 | } |
| 117 | ] |
| 118 | } |
| 119 | ` |
| 120 | } |
| 121 | |
| 122 | fmt.Fprint(w, textMatchResponse) |
| 123 | }) |
| 124 | |
| 125 | opts := &SearchOptions{Sort: "forks", Order: "desc", ListOptions: ListOptions{Page: 2, PerPage: 2}, TextMatch: true} |
| 126 | ctx := t.Context() |
| 127 | result, _, err := client.Search.Repositories(ctx, "blah", opts) |
| 128 | if err != nil { |
| 129 | t.Errorf("Search.Code returned error: %v", err) |
nothing calls this directly
no test coverage detected
searching dependent graphs…