(t *testing.T)
| 1219 | } |
| 1220 | |
| 1221 | func TestSearcherURL(t *testing.T) { |
| 1222 | query := Query{ |
| 1223 | Keywords: []string{"keyword"}, |
| 1224 | Kind: "repositories", |
| 1225 | Limit: 30, |
| 1226 | Order: "desc", |
| 1227 | Sort: "stars", |
| 1228 | Qualifiers: Qualifiers{ |
| 1229 | Stars: ">=5", |
| 1230 | Topic: []string{"topic"}, |
| 1231 | }, |
| 1232 | } |
| 1233 | |
| 1234 | tests := []struct { |
| 1235 | name string |
| 1236 | host string |
| 1237 | query Query |
| 1238 | url string |
| 1239 | }{ |
| 1240 | { |
| 1241 | name: "outputs encoded query url", |
| 1242 | query: query, |
| 1243 | url: "https://github.com/search?order=desc&q=keyword+stars%3A%3E%3D5+topic%3Atopic&sort=stars&type=repositories", |
| 1244 | }, |
| 1245 | { |
| 1246 | name: "supports enterprise hosts", |
| 1247 | host: "enterprise.com", |
| 1248 | query: query, |
| 1249 | url: "https://enterprise.com/search?order=desc&q=keyword+stars%3A%3E%3D5+topic%3Atopic&sort=stars&type=repositories", |
| 1250 | }, |
| 1251 | { |
| 1252 | name: "outputs encoded query url with quoted multi-word keywords", |
| 1253 | query: Query{ |
| 1254 | Keywords: []string{"keyword with whitespace"}, |
| 1255 | Kind: "repositories", |
| 1256 | }, |
| 1257 | url: "https://github.com/search?q=%22keyword+with+whitespace%22&type=repositories", |
| 1258 | }, |
| 1259 | } |
| 1260 | for _, tt := range tests { |
| 1261 | t.Run(tt.name, func(t *testing.T) { |
| 1262 | if tt.host == "" { |
| 1263 | tt.host = "github.com" |
| 1264 | } |
| 1265 | searcher := NewSearcher(nil, tt.host, nil) |
| 1266 | assert.Equal(t, tt.url, searcher.URL(tt.query)) |
| 1267 | }) |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | // initialize generate slices over a range for test scenarios using the provided initializer. |
| 1272 | func initialize[T any](start int, stop int, initializer func(i int) T) []T { |
nothing calls this directly
no test coverage detected