(t *testing.T)
| 1327 | } |
| 1328 | |
| 1329 | func TestSearcherURL(t *testing.T) { |
| 1330 | query := Query{ |
| 1331 | Keywords: []string{"keyword"}, |
| 1332 | Kind: "repositories", |
| 1333 | Limit: 30, |
| 1334 | Order: "desc", |
| 1335 | Sort: "stars", |
| 1336 | Qualifiers: Qualifiers{ |
| 1337 | Stars: ">=5", |
| 1338 | Topic: []string{"topic"}, |
| 1339 | }, |
| 1340 | } |
| 1341 | |
| 1342 | tests := []struct { |
| 1343 | name string |
| 1344 | host string |
| 1345 | query Query |
| 1346 | url string |
| 1347 | }{ |
| 1348 | { |
| 1349 | name: "outputs encoded query url", |
| 1350 | query: query, |
| 1351 | url: "https://github.com/search?order=desc&q=keyword+stars%3A%3E%3D5+topic%3Atopic&sort=stars&type=repositories", |
| 1352 | }, |
| 1353 | { |
| 1354 | name: "supports enterprise hosts", |
| 1355 | host: "enterprise.com", |
| 1356 | query: query, |
| 1357 | url: "https://enterprise.com/search?order=desc&q=keyword+stars%3A%3E%3D5+topic%3Atopic&sort=stars&type=repositories", |
| 1358 | }, |
| 1359 | { |
| 1360 | name: "outputs encoded query url with quoted multi-word keywords", |
| 1361 | query: Query{ |
| 1362 | Keywords: []string{"keyword with whitespace"}, |
| 1363 | Kind: "repositories", |
| 1364 | }, |
| 1365 | url: "https://github.com/search?q=%22keyword+with+whitespace%22&type=repositories", |
| 1366 | }, |
| 1367 | } |
| 1368 | for _, tt := range tests { |
| 1369 | t.Run(tt.name, func(t *testing.T) { |
| 1370 | if tt.host == "" { |
| 1371 | tt.host = "github.com" |
| 1372 | } |
| 1373 | searcher := NewSearcher(nil, tt.host, nil) |
| 1374 | assert.Equal(t, tt.url, searcher.URL(tt.query)) |
| 1375 | }) |
| 1376 | } |
| 1377 | } |
| 1378 | |
| 1379 | // initialize generate slices over a range for test scenarios using the provided initializer. |
| 1380 | func initialize[T any](start int, stop int, initializer func(i int) T) []T { |
nothing calls this directly
no test coverage detected