Skip to content

Commit

Permalink
Add test with large search response.
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekbanas committed Oct 8, 2024
1 parent 0822050 commit bd6149f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 46 deletions.
68 changes: 25 additions & 43 deletions tests/testthat/helper-fixtures.R
Original file line number Diff line number Diff line change
Expand Up @@ -393,52 +393,34 @@ test_fixtures$gitlab_search_response <- list(
)
)

github_search_item <- list(
"name" = "test1.R",
"path" = "examples/test1.R",
"sha" = "0d42b9d23ddfc0bca1",
"url" = "test_url",
"git_url" = "test_git_url",
"html_url" = "test_html_url",
"repository" = list(
"id" = 627452680,
"url" = "https://api.github.com/repos/r-world-devs/GitStats",
"html_url" = "https://github.com/r-world-devs/GitStats"
),
"score" = 1
)

test_fixtures$github_search_response <- list(
"total_count" = 3,
"total_count" = 250,
"incomplete_results" = FALSE,
"items" = list(
list(
"name" = "test1.R",
"path" = "examples/test1.R",
"sha" = "0d42b9d23ddfc0bca1",
"url" = "test_url",
"git_url" = "test_git_url",
"html_url" = "test_html_url",
"repository" = list(
"id" = 627452680,
"url" = "https://api.github.com/repos/r-world-devs/GitStats",
"html_url" = "https://github.com/r-world-devs/GitStats"
),
"score" = 1
),
list(
"name" = "test2.R",
"path" = "tests/test2.R",
"sha" = "01238xb",
"url" = "test_url",
"git_url" = "test_git_url",
"html_url" = "test_html_url",
"repository" = list(
"id" = 604718884,
"url" = "https://api.github.com/repos/r-world-devs/GitStats",
"html_url" = "https://github.com/r-world-devs/GitStats"
),
"score" = 1
),
list(
"name" = "test3.R",
"path" = "R/test3.R",
"sha" = "20e19af2dda26d04f6",
"url" = "test_url",
"git_url" = "test_git_url",
"html_url" = "test_html_url",
"repository" = list(
"id" = 495151911,
"url" = "https://api.github.com/repos/r-world-devs/GitStats",
"html_url" = "https://github.com/r-world-devs/GitStats"
),
"score" = 1
)
rep(github_search_item, 250)
)
)

test_fixtures$github_search_response_large <- list(
"total_count" = 1001,
"incomplete_results" = FALSE,
"items" = list(
rep(github_search_item, 1001)
)
)

Expand Down
20 changes: 17 additions & 3 deletions tests/testthat/test-01-get_repos-GitHub.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test_that("`get_repos_from_org()` prepares formatted list", {

# REST Engine search repos by code

test_that("`search_response()` performs search with limit under 100", {
test_that("`search_response()` performs search with limit under 1000", {
total_n <- test_fixtures$github_search_response[["total_count"]]
mockery::stub(
test_rest_github_priv$search_response,
Expand All @@ -53,8 +53,22 @@ test_that("`search_response()` performs search with limit under 100", {
)
gh_search_repos_response <- test_rest_github_priv$search_response(
search_endpoint = test_mocker$use("search_endpoint"),
total_n = total_n,
byte_max = 384000
total_n = total_n
)
expect_gh_search_response(gh_search_repos_response)
test_mocker$cache(gh_search_repos_response)
})

test_that("`search_response()` performs search with limit over 1000", {
total_n <- test_fixtures$github_search_response_large[["total_count"]]
mockery::stub(
test_rest_github_priv$search_response,
"self$response",
test_fixtures$github_search_response_large
)
gh_search_repos_response <- test_rest_github_priv$search_response(
search_endpoint = test_mocker$use("search_endpoint"),
total_n = total_n
)
expect_gh_search_response(gh_search_repos_response)
test_mocker$cache(gh_search_repos_response)
Expand Down

0 comments on commit bd6149f

Please sign in to comment.