Skip to content

assert query params in search_test #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 54 additions & 14 deletions pkg/github/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,37 @@ func Test_SearchRepositories(t *testing.T) {
{
name: "successful repository search",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.GetSearchRepositories,
mockSearchResult,
expectQueryParams(t, map[string]string{
"q": "golang test",
"page": "2",
"per_page": "10",
}).andThen(
mockResponse(t, http.StatusOK, mockSearchResult),
),
),
),
requestArgs: map[string]interface{}{
"query": "golang test",
"page": float64(1),
"per_page": float64(30),
"page": float64(2),
"per_page": float64(10),
},
expectError: false,
expectedResult: mockSearchResult,
},
{
name: "repository search with default pagination",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.GetSearchRepositories,
mockSearchResult,
expectQueryParams(t, map[string]string{
"q": "golang test",
"page": "1",
"per_page": "30",
}).andThen(
mockResponse(t, http.StatusOK, mockSearchResult),
),
),
),
requestArgs: map[string]interface{}{
Expand Down Expand Up @@ -195,9 +207,17 @@ func Test_SearchCode(t *testing.T) {
{
name: "successful code search with all parameters",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.GetSearchCode,
mockSearchResult,
expectQueryParams(t, map[string]string{
"q": "fmt.Println language:go",
"sort": "indexed",
"order": "desc",
"page": "1",
"per_page": "30",
}).andThen(
mockResponse(t, http.StatusOK, mockSearchResult),
),
),
),
requestArgs: map[string]interface{}{
Expand All @@ -213,9 +233,15 @@ func Test_SearchCode(t *testing.T) {
{
name: "code search with minimal parameters",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.GetSearchCode,
mockSearchResult,
expectQueryParams(t, map[string]string{
"q": "fmt.Println language:go",
"page": "1",
"per_page": "30",
}).andThen(
mockResponse(t, http.StatusOK, mockSearchResult),
),
),
),
requestArgs: map[string]interface{}{
Expand Down Expand Up @@ -336,9 +362,17 @@ func Test_SearchUsers(t *testing.T) {
{
name: "successful users search with all parameters",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.GetSearchUsers,
mockSearchResult,
expectQueryParams(t, map[string]string{
"q": "location:finland language:go",
"sort": "followers",
"order": "desc",
"page": "1",
"per_page": "30",
}).andThen(
mockResponse(t, http.StatusOK, mockSearchResult),
),
),
),
requestArgs: map[string]interface{}{
Expand All @@ -354,9 +388,15 @@ func Test_SearchUsers(t *testing.T) {
{
name: "users search with minimal parameters",
mockedClient: mock.NewMockedHTTPClient(
mock.WithRequestMatch(
mock.WithRequestMatchHandler(
mock.GetSearchUsers,
mockSearchResult,
expectQueryParams(t, map[string]string{
"q": "location:finland language:go",
"page": "1",
"per_page": "30",
}).andThen(
mockResponse(t, http.StatusOK, mockSearchResult),
),
),
),
requestArgs: map[string]interface{}{
Expand Down