Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekbanas committed Dec 19, 2024
1 parent ef59a17 commit dd6321a
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 30 deletions.
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/01-get_repos-GitLab.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Code
gl_repos_by_org_query
Output
[1] "\n query GetReposByOrg($org: ID! $repo_cursor: String!) {\n group(fullPath: $org) {\n projects(first: 100 after: $repo_cursor) {\n \n count\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n repo_id: id\n repo_name: name\n repo_path: path\n ... on Project {\n repository {\n rootRef\n }\n }\n stars: starCount\n forks: forksCount\n created_at: createdAt\n last_activity_at: lastActivityAt\n languages {\n name\n }\n issues: issueStatusCounts {\n all\n closed\n opened\n }\n namespace {\n path\n }\n repo_url: webUrl\n }\n }\n }\n }\n }"
[1] "\n query GetReposByOrg($org: ID! $repo_cursor: String!) {\n group(fullPath: $org) {\n projects(first: 100 after: $repo_cursor) {\n \n count\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n repo_id: id\n repo_name: name\n repo_path: path\n ... on Project {\n repository {\n rootRef\n }\n }\n stars: starCount\n forks: forksCount\n created_at: createdAt\n last_activity_at: lastActivityAt\n languages {\n name\n }\n issues: issueStatusCounts {\n all\n closed\n opened\n }\n namespace {\n path: fullPath\n }\n repo_url: webUrl\n }\n }\n }\n }\n }"

75 changes: 63 additions & 12 deletions tests/testthat/test-01-get_repos-GitHub.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,48 +128,73 @@ test_that("Mapping search result to repositories works", {
test_mocker$cache(gh_mapped_repos)
})

test_that("`get_repos_by_code()` returns repos output for code search in files", {
test_that("`search_for_code()` returns repos output for code search in files", {
mockery::stub(
test_rest_github$get_repos_by_code,
test_rest_github_priv$search_for_code,
"self$response",
list("total_count" = 3L)
)
mockery::stub(
test_rest_github$get_repos_by_code,
test_rest_github_priv$search_for_code,
"private$search_response",
test_fixtures$github_search_response
)
mockery::stub(
test_rest_github$get_repos_by_code,
test_rest_github_priv$search_for_code,
"private$map_search_into_repos",
test_mocker$use("gh_mapped_repos")
)
gh_repos_by_code <- test_rest_github$get_repos_by_code(
gh_search_for_code <- test_rest_github_priv$search_for_code(
code = "test_code",
filename = "test_file",
in_path = FALSE,
org = "test_org",
verbose = FALSE
verbose = FALSE,
progress = FALSE
)
expect_gh_repos_rest_response(gh_repos_by_code)
test_mocker$cache(gh_repos_by_code)
expect_gh_search_response(gh_search_for_code$items)
test_mocker$cache(gh_search_for_code)
})

test_that("`get_repos_by_code()` for GitHub prepares a raw search response", {
test_that("`search_repos_for_code()` returns repos output for code search in files", {
mockery::stub(
test_rest_github$get_repos_by_code,
test_rest_github_priv$search_repos_for_code,
"self$response",
list("total_count" = 3L)
)
mockery::stub(
test_rest_github$get_repos_by_code,
test_rest_github_priv$search_repos_for_code,
"private$search_response",
test_fixtures$github_search_response
)
mockery::stub(
test_rest_github$get_repos_by_code,
test_rest_github_priv$search_repos_for_code,
"private$map_search_into_repos",
test_mocker$use("gh_mapped_repos")
)
gh_search_repos_for_code <- test_rest_github_priv$search_repos_for_code(
code = "test_code",
filename = "test_file",
in_path = FALSE,
repos = c("TestRepo", "TestRepo1"),
verbose = FALSE,
progress = FALSE
)
expect_gh_search_response(gh_search_repos_for_code$items)
test_mocker$cache(gh_search_repos_for_code)
})

test_that("`get_repos_by_code()` for GitHub prepares a raw search response", {
mockery::stub(
test_rest_github$get_repos_by_code,
"private$search_for_code",
test_mocker$use("gh_search_for_code")
)
mockery::stub(
test_rest_github$get_repos_by_code,
"private$search_repos_for_code",
test_mocker$use("gh_search_repos_for_code")
)
gh_repos_by_code_raw <- test_rest_github$get_repos_by_code(
code = "test_code",
org = "test_org",
Expand All @@ -180,6 +205,32 @@ test_that("`get_repos_by_code()` for GitHub prepares a raw search response", {
test_mocker$cache(gh_repos_by_code_raw)
})

test_that("`get_repos_by_code()` for GitHub prepares a repository output", {
mockery::stub(
test_rest_github$get_repos_by_code,
"private$search_for_code",
test_mocker$use("gh_search_for_code")
)
mockery::stub(
test_rest_github$get_repos_by_code,
"private$search_repos_for_code",
test_mocker$use("gh_search_repos_for_code")
)
mockery::stub(
test_rest_github$get_repos_by_code,
"private$map_search_into_repos",
test_mocker$use("gh_mapped_repos")
)
gh_repos_by_code <- test_rest_github$get_repos_by_code(
code = "test_code",
org = "test_org",
output = "table_min",
verbose = FALSE
)
expect_gh_repos_rest_response(gh_repos_by_code)
test_mocker$cache(gh_repos_by_code)
})

test_that("GitHub tailors precisely `repos_list`", {
gh_repos_by_code <- test_mocker$use("gh_repos_by_code")
gh_repos_by_code_tailored <-
Expand Down
68 changes: 56 additions & 12 deletions tests/testthat/test-get_urls_repos-GitHub.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
test_that("get_repos_urls() works for whole orgs", {
mockery::stub(
test_rest_github$get_repos_urls,
"self$response",
"private$paginate_results",
test_fixtures$github_repositories_rest_response
)
gh_repos_urls <- test_rest_github$get_repos_urls(
type = "web",
org = "test-org",
org = "test_org",
repos = NULL
)
expect_length(
Expand All @@ -19,12 +19,12 @@ test_that("get_repos_urls() works for whole orgs", {
test_that("get_repos_urls() works for individual repos", {
mockery::stub(
test_rest_github$get_repos_urls,
"self$response",
"private$paginate_results",
test_fixtures$github_repositories_rest_response
)
gh_repos_urls <- test_rest_github$get_repos_urls(
type = "web",
org = "test-org",
org = "test_org",
repos = c("testRepo", "testRepo2")
)
expect_length(
Expand All @@ -35,14 +35,13 @@ test_that("get_repos_urls() works for individual repos", {
})

test_that("get_repos_urls prepares api repo_urls vector", {
github_testhost_priv <- create_github_testhost(orgs = "test-org",
mode = "private")
mockery::stub(
test_rest_github$get_repos_urls,
"self$response",
"private$paginate_results",
test_fixtures$github_repositories_rest_response
)
gh_api_repos_urls <- test_rest_github$get_repos_urls(
org = "test_org",
repos = NULL,
type = "api"
)
Expand Down Expand Up @@ -136,17 +135,62 @@ test_that("get_repo_url_from_response retrieves repositories URLS", {
test_mocker$cache(gh_repo_web_urls)
})

test_that("get_repos_urls returns repositories URLS", {
test_that("get_repos_urls_with_code_from_orgs returns repositories URLS", {
mockery::stub(
github_testhost$get_repos_urls,
github_testhost_priv$get_repos_urls_with_code_from_orgs,
"private$get_repo_url_from_response",
test_mocker$use("gh_repo_web_urls")
)
gh_repos_urls_with_code_in_files <- github_testhost$get_repos_urls(
gh_repos_urls_with_code_from_orgs <- github_testhost_priv$get_repos_urls_with_code_from_orgs(
type = "web",
with_code = "shiny",
code = "shiny",
in_files = "DESCRIPTION",
verbose = FALSE
in_path = FALSE,
verbose = FALSE,
progress= FALSE
)
expect_type(gh_repos_urls_with_code_from_orgs, "character")
expect_gt(length(gh_repos_urls_with_code_from_orgs), 0)
test_mocker$cache(gh_repos_urls_with_code_from_orgs)
})

test_that("get_repos_urls_with_code_from_repos returns repositories URLS", {
mockery::stub(
github_testhost_priv$get_repos_urls_with_code_from_repos,
"private$get_repo_url_from_response",
test_mocker$use("gh_repo_web_urls")
)
gh_repos_urls_with_code_from_repos <- github_testhost_priv$get_repos_urls_with_code_from_repos(
type = "web",
code = "shiny",
in_files = "DESCRIPTION",
in_path = FALSE,
verbose = FALSE,
progress = FALSE
)
expect_type(gh_repos_urls_with_code_from_repos, "character")
expect_gt(length(gh_repos_urls_with_code_from_repos), 0)
test_mocker$cache(gh_repos_urls_with_code_from_repos)
})

test_that("get_repos_urls_with_code_from_repos returns repositories URLS", {
mockery::stub(
github_testhost_priv$get_repos_urls_with_code,
"private$get_repos_urls_with_code_from_orgs",
test_mocker$use("gh_repos_urls_with_code_from_orgs")
)
mockery::stub(
github_testhost_priv$get_repos_urls_with_code,
"private$get_repos_urls_with_code_from_repos",
test_mocker$use("gh_repos_urls_with_code_from_repos")
)
gh_repos_urls_with_code_in_files <- github_testhost_priv$get_repos_urls_with_code(
type = "web",
code = "shiny",
in_files = "DESCRIPTION",
in_path = FALSE,
verbose = FALSE,
progress = FALSE
)
expect_type(gh_repos_urls_with_code_in_files, "character")
expect_gt(length(gh_repos_urls_with_code_in_files), 0)
Expand Down
55 changes: 50 additions & 5 deletions tests/testthat/test-get_urls_repos-GitLab.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,62 @@ test_that("`get_repo_url_from_response()` works", {
test_mocker$cache(gl_repo_web_urls)
})

test_that("get_repos_urls returns repositories URLS", {
test_that("get_repos_urls_with_code_from_orgs returns repositories URLS", {
mockery::stub(
gitlab_testhost$get_repos_urls,
gitlab_testhost_priv$get_repos_urls_with_code_from_orgs,
"private$get_repo_url_from_response",
test_mocker$use("gl_repo_web_urls")
)
gl_repos_urls_with_code_in_files <- gitlab_testhost$get_repos_urls(
gl_repos_urls_with_code_from_orgs <- gitlab_testhost_priv$get_repos_urls_with_code_from_orgs(
type = "web",
with_code = "shiny",
code = "shiny",
in_files = "DESCRIPTION",
verbose = FALSE
in_path = FALSE,
verbose = FALSE,
progress = FALSE
)
expect_type(gl_repos_urls_with_code_from_orgs, "character")
expect_gt(length(gl_repos_urls_with_code_from_orgs), 0)
test_mocker$cache(gl_repos_urls_with_code_from_orgs)
})

test_that("get_repos_urls_with_code_from_repos returns repositories URLS", {
mockery::stub(
gitlab_testhost_priv$get_repos_urls_with_code_from_repos,
"private$get_repo_url_from_response",
test_mocker$use("gl_repo_web_urls")
)
gl_repos_urls_with_code_from_repos <- gitlab_testhost_priv$get_repos_urls_with_code_from_repos(
type = "web",
code = "shiny",
in_files = "DESCRIPTION",
in_path = FALSE,
verbose = FALSE,
progress = FALSE
)
expect_type(gl_repos_urls_with_code_from_repos, "character")
expect_gt(length(gl_repos_urls_with_code_from_repos), 0)
test_mocker$cache(gl_repos_urls_with_code_from_repos)
})

test_that("get_repos_urls_with_code_from_repos returns repositories URLS", {
mockery::stub(
gitlab_testhost_priv$get_repos_urls_with_code,
"private$get_repos_urls_with_code_from_orgs",
test_mocker$use("gl_repos_urls_with_code_from_orgs")
)
mockery::stub(
gitlab_testhost_priv$get_repos_urls_with_code,
"private$get_repos_urls_with_code_from_repos",
test_mocker$use("gl_repos_urls_with_code_from_repos")
)
gl_repos_urls_with_code_in_files <- gitlab_testhost_priv$get_repos_urls_with_code(
type = "web",
code = "shiny",
in_files = "DESCRIPTION",
in_path = FALSE,
verbose = FALSE,
progress = FALSE
)
expect_type(gl_repos_urls_with_code_in_files, "character")
expect_gt(length(gl_repos_urls_with_code_in_files), 0)
Expand Down

0 comments on commit dd6321a

Please sign in to comment.