Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbdfb30c

Browse files
authored
assert query params (#97)
1 parent95c7b0a commitbdfb30c

File tree

1 file changed

+54
-14
lines changed

1 file changed

+54
-14
lines changed

‎pkg/github/search_test.go

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,37 @@ func Test_SearchRepositories(t *testing.T) {
6060
{
6161
name:"successful repository search",
6262
mockedClient:mock.NewMockedHTTPClient(
63-
mock.WithRequestMatch(
63+
mock.WithRequestMatchHandler(
6464
mock.GetSearchRepositories,
65-
mockSearchResult,
65+
expectQueryParams(t,map[string]string{
66+
"q":"golang test",
67+
"page":"2",
68+
"per_page":"10",
69+
}).andThen(
70+
mockResponse(t,http.StatusOK,mockSearchResult),
71+
),
6672
),
6773
),
6874
requestArgs:map[string]interface{}{
6975
"query":"golang test",
70-
"page":float64(1),
71-
"per_page":float64(30),
76+
"page":float64(2),
77+
"per_page":float64(10),
7278
},
7379
expectError:false,
7480
expectedResult:mockSearchResult,
7581
},
7682
{
7783
name:"repository search with default pagination",
7884
mockedClient:mock.NewMockedHTTPClient(
79-
mock.WithRequestMatch(
85+
mock.WithRequestMatchHandler(
8086
mock.GetSearchRepositories,
81-
mockSearchResult,
87+
expectQueryParams(t,map[string]string{
88+
"q":"golang test",
89+
"page":"1",
90+
"per_page":"30",
91+
}).andThen(
92+
mockResponse(t,http.StatusOK,mockSearchResult),
93+
),
8294
),
8395
),
8496
requestArgs:map[string]interface{}{
@@ -195,9 +207,17 @@ func Test_SearchCode(t *testing.T) {
195207
{
196208
name:"successful code search with all parameters",
197209
mockedClient:mock.NewMockedHTTPClient(
198-
mock.WithRequestMatch(
210+
mock.WithRequestMatchHandler(
199211
mock.GetSearchCode,
200-
mockSearchResult,
212+
expectQueryParams(t,map[string]string{
213+
"q":"fmt.Println language:go",
214+
"sort":"indexed",
215+
"order":"desc",
216+
"page":"1",
217+
"per_page":"30",
218+
}).andThen(
219+
mockResponse(t,http.StatusOK,mockSearchResult),
220+
),
201221
),
202222
),
203223
requestArgs:map[string]interface{}{
@@ -213,9 +233,15 @@ func Test_SearchCode(t *testing.T) {
213233
{
214234
name:"code search with minimal parameters",
215235
mockedClient:mock.NewMockedHTTPClient(
216-
mock.WithRequestMatch(
236+
mock.WithRequestMatchHandler(
217237
mock.GetSearchCode,
218-
mockSearchResult,
238+
expectQueryParams(t,map[string]string{
239+
"q":"fmt.Println language:go",
240+
"page":"1",
241+
"per_page":"30",
242+
}).andThen(
243+
mockResponse(t,http.StatusOK,mockSearchResult),
244+
),
219245
),
220246
),
221247
requestArgs:map[string]interface{}{
@@ -336,9 +362,17 @@ func Test_SearchUsers(t *testing.T) {
336362
{
337363
name:"successful users search with all parameters",
338364
mockedClient:mock.NewMockedHTTPClient(
339-
mock.WithRequestMatch(
365+
mock.WithRequestMatchHandler(
340366
mock.GetSearchUsers,
341-
mockSearchResult,
367+
expectQueryParams(t,map[string]string{
368+
"q":"location:finland language:go",
369+
"sort":"followers",
370+
"order":"desc",
371+
"page":"1",
372+
"per_page":"30",
373+
}).andThen(
374+
mockResponse(t,http.StatusOK,mockSearchResult),
375+
),
342376
),
343377
),
344378
requestArgs:map[string]interface{}{
@@ -354,9 +388,15 @@ func Test_SearchUsers(t *testing.T) {
354388
{
355389
name:"users search with minimal parameters",
356390
mockedClient:mock.NewMockedHTTPClient(
357-
mock.WithRequestMatch(
391+
mock.WithRequestMatchHandler(
358392
mock.GetSearchUsers,
359-
mockSearchResult,
393+
expectQueryParams(t,map[string]string{
394+
"q":"location:finland language:go",
395+
"page":"1",
396+
"per_page":"30",
397+
}).andThen(
398+
mockResponse(t,http.StatusOK,mockSearchResult),
399+
),
360400
),
361401
),
362402
requestArgs:map[string]interface{}{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp