Skip to content

Commit

Permalink
Add tests, fix GitLab commits tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekbanas committed Dec 20, 2024
1 parent 4f357b5 commit 065b6f6
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 36 deletions.
19 changes: 18 additions & 1 deletion tests/testthat/_snaps/01-get_repos-GitHub.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
i [Host:GitHub][Engine:REST][Scope:] Pulling repositories...
i Preparing repositories table...

# `get_repos_with_code_from_orgs()` pulls minimum version of table
# `get_repos_with_code_from_repos()` pulls minimum version of table

Code
repos_with_code_from_repos_min <- github_testhost_priv$
Expand All @@ -52,10 +52,27 @@
Message
i [Host:GitHub][Engine:REST] Pulling repositories...

# get_repos_from_repos works

Code
gh_repos_individual <- github_testhost_priv$get_repos_from_repos(verbose = TRUE,
progress = FALSE)
Message
i [Host:GitHub][Engine:GraphQl][Scope:test_org] Pulling repositories...

# `get_all_repos()` is set to scan whole git host

Code
gh_repos <- github_testhost_all_priv$get_all_repos(verbose = TRUE, progress = FALSE)
Message
i [Host:GitHub][Engine:GraphQl] Pulling all organizations...

# `get_repos_contributors()` works on GitHost level

Code
gh_repos_with_contributors <- github_testhost_priv$get_repos_contributors(
repos_table = test_mocker$use("gh_repos_table_with_platform"), verbose = TRUE,
progress = FALSE)
Message
i [Host:GitHub][Engine:REST] Pulling contributors...

16 changes: 16 additions & 0 deletions tests/testthat/_snaps/01-get_repos-GitLab.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
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: fullPath\n }\n repo_url: webUrl\n }\n }\n }\n }\n }"

# `search_for_code()` works

Code
gl_search_repos_by_code <- test_rest_gitlab_priv$search_for_code(code = "test",
filename = "TESTFILE", verbose = TRUE, page_max = 2)
Message
i Searching for code [test]...

# `search_repos_for_code()` works

Code
gl_search_repos_by_code <- test_rest_gitlab_priv$search_repos_for_code(code = "test",
repos = "TestRepo", filename = "TESTFILE", verbose = TRUE, page_max = 2)
Message
i Searching for code [test]...

# get_repos_from_org prints proper message

Code
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/_snaps/02-get_commits-GitLab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# get_commits_from_orgs works

Code
gl_commits_table <- gitlab_testhost_priv$get_commits_from_orgs(since = "2023-03-01",
until = "2023-04-01", verbose = TRUE, progress = FALSE)
Message
i [Host:GitLab][Engine:REST][Scope:mbtests] Pulling commits...

# get_commits_from_repos works

Code
gl_commits_table <- gitlab_testhost_priv$get_commits_from_repos(since = "2023-03-01",
until = "2023-04-01", verbose = TRUE, progress = FALSE)
Message
i [Host:GitLab][Engine:REST][Scope:test_org/TestRepo] Pulling commits...

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/get_release-GitLab.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
Output
[1] "query GetReleasesFromRepo($project_path: ID!) {\n project(fullPath: $project_path) {\n name\n webUrl\n \t\t\t\t\t\treleases {\n nodes{\n name\n tagName\n releasedAt\n links {\n selfUrl\n }\n description\n }\n }\n }\n }"

# `get_release_logs_from_repos()` works

Code
releases_from_repos <- gitlab_testhost_priv$get_release_logs_from_repos(since = "2023-05-01",
until = "2023-09-30", verbose = TRUE, progress = FALSE)
Message
i [Host:GitLab][Engine:GraphQl][Scope:test_org/TestRepo] Pulling release logs...

13 changes: 13 additions & 0 deletions tests/testthat/_snaps/get_urls_repos-GitHub.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,16 @@
Message
i [Host:GitHub][Engine:REST][Scope:test_org] Pulling repositories (URLs)...

# get_repos_urls_from_repos prepares web repo_urls vector

Code
gh_repos_urls <- github_testhost_priv$get_repos_urls_from_repos(type = "web",
verbose = TRUE, progress = FALSE)
Message
i [Host:GitHub][Engine:REST][Scope:test_org] Pulling repositories (URLs)...

# get_all_repos_urls prepares web repo_urls vector

Code
gh_repos_urls <- github_testhost_priv$get_all_repos_urls(type = "web", verbose = TRUE)

2 changes: 1 addition & 1 deletion tests/testthat/helper-expect-responses.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ expect_gl_commit_rest_response <- function(object) {
"list"
)
expect_list_contains(
object[[1]],
object,
c(
"id", "short_id", "created_at", "parent_ids", "title", "message",
"author_name", "author_email", "authored_date", "committer_name",
Expand Down
4 changes: 1 addition & 3 deletions tests/testthat/helper-fixtures.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,7 @@ gitlab_commit <- list(
)
)

test_fixtures$gitlab_commits_response <- list(
rep(gitlab_commit, 5)
)
test_fixtures$gitlab_commits_response <- rep(list(gitlab_commit), 5)

test_fixtures$github_file_response <- list(
"data" = list(
Expand Down
20 changes: 12 additions & 8 deletions tests/testthat/test-01-get_repos-GitHub.R
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,11 @@ test_that("get_repos_from_repos works", {
)
github_testhost_priv$searching_scope <- c("org", "repo")
github_testhost_priv$orgs_repos <- list("test_org" = "TestRepo")
gh_repos_individual <- github_testhost_priv$get_repos_from_repos(
verbose = FALSE,
progress = FALSE
expect_snapshot(
gh_repos_individual <- github_testhost_priv$get_repos_from_repos(
verbose = TRUE,
progress = FALSE
)
)
expect_repos_table(
gh_repos_individual
Expand Down Expand Up @@ -679,7 +681,7 @@ test_that("`get_repos_contributors()` adds contributors to repos table", {
)
gh_repos_with_contributors <- test_rest_github$get_repos_contributors(
repos_table = test_mocker$use("gh_repos_table_with_platform"),
progress = FALSE
progress = FALSE
)
expect_repos_table(
gh_repos_with_contributors,
Expand All @@ -698,10 +700,12 @@ test_that("`get_repos_contributors()` works on GitHost level", {
"rest_engine$get_repos_contributors",
test_mocker$use("gh_repos_with_contributors")
)
gh_repos_with_contributors <- github_testhost_priv$get_repos_contributors(
repos_table = test_mocker$use("gh_repos_table_with_platform"),
verbose = FALSE,
progress = FALSE
expect_snapshot(
gh_repos_with_contributors <- github_testhost_priv$get_repos_contributors(
repos_table = test_mocker$use("gh_repos_table_with_platform"),
verbose = TRUE,
progress = FALSE
)
)
expect_repos_table(
gh_repos_with_contributors,
Expand Down
118 changes: 113 additions & 5 deletions tests/testthat/test-01-get_repos-GitLab.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,39 @@ test_that("`get_repos_from_org()` does not fail when GraphQL response is not com
)
})

test_that("`search_for_code()` works", {
mockery::stub(
test_rest_gitlab_priv$search_for_code,
"self$response",
list()
)
expect_snapshot(
gl_search_repos_by_code <- test_rest_gitlab_priv$search_for_code(
code = "test",
filename = "TESTFILE",
verbose = TRUE,
page_max = 2
)
)
})

test_that("`search_repos_for_code()` works", {
mockery::stub(
test_rest_gitlab_priv$search_repos_for_code,
"self$response",
list()
)
expect_snapshot(
gl_search_repos_by_code <- test_rest_gitlab_priv$search_repos_for_code(
code = "test",
repos = "TestRepo",
filename = "TESTFILE",
verbose = TRUE,
page_max = 2
)
)
})

test_that("`map_search_into_repos()` works", {
gl_search_response <- test_fixtures$gitlab_search_response
test_mocker$cache(gl_search_response)
Expand All @@ -132,20 +165,71 @@ test_that("`map_search_into_repos()` works", {
test_mocker$cache(gl_search_repos_by_code)
})

test_that("`get_repos_languages` works", {
test_that("`get_repos_languages()` works", {
repos_list <- test_mocker$use("gl_search_repos_by_code")
repos_list[[1]]$id <- "45300912"
mockery::stub(
test_rest_gitlab_priv$get_repos_languages,
"self$response",
test_fixtures$gitlab_languages_response
)
repos_list_with_languages <- test_rest_gitlab_priv$get_repos_languages(
gl_repos_list_with_languages <- test_rest_gitlab_priv$get_repos_languages(
repos_list = repos_list,
progress = FALSE
)
purrr::walk(repos_list_with_languages, ~ expect_list_contains(., "languages"))
expect_equal(repos_list_with_languages[[1]]$languages, c("Python", "R"))
purrr::walk(gl_repos_list_with_languages, ~ expect_list_contains(., "languages"))
expect_equal(gl_repos_list_with_languages[[1]]$languages, c("Python", "R"))
test_mocker$cache(gl_repos_list_with_languages)
})

test_that("`get_repos_by_code()` works", {
mockery::stub(
test_rest_gitlab$get_repos_by_code,
"private$search_for_code",
test_fixtures$gitlab_search_response
)
mockery::stub(
test_rest_gitlab$get_repos_by_code,
"private$map_search_into_repos",
test_mocker$use("gl_search_repos_by_code")
)
mockery::stub(
test_rest_gitlab$get_repos_by_code,
"private$get_repos_languages",
test_mocker$use("gl_repos_list_with_languages")
)
gl_repos_by_code <- test_rest_gitlab$get_repos_by_code(
code = "test",
org = "test_org"
)
expect_gl_repos_rest_response(
gl_repos_by_code
)
})

test_that("`get_repos_by_code()` works", {
mockery::stub(
test_rest_gitlab$get_repos_by_code,
"private$search_repos_for_code",
test_fixtures$gitlab_search_response
)
mockery::stub(
test_rest_gitlab$get_repos_by_code,
"private$map_search_into_repos",
test_mocker$use("gl_search_repos_by_code")
)
mockery::stub(
test_rest_gitlab$get_repos_by_code,
"private$get_repos_languages",
test_mocker$use("gl_repos_list_with_languages")
)
gl_repos_by_code <- test_rest_gitlab$get_repos_by_code(
code = "test",
repos = c("TestRepo1", "TestRepo2")
)
expect_gl_repos_rest_response(
gl_repos_by_code
)
})

test_that("`prepare_repos_table()` prepares repos table", {
Expand Down Expand Up @@ -186,7 +270,10 @@ test_that("GitHost adds `repo_api_url` column to GitLab repos table", {
test_that("`tailor_repos_response()` tailors precisely `repos_list`", {
gl_repos_by_code <- test_mocker$use("gl_search_repos_by_code")
gl_repos_by_code_tailored <-
test_rest_gitlab$tailor_repos_response(gl_repos_by_code)
test_rest_gitlab$tailor_repos_response(
repos_response = gl_repos_by_code,
output = "table_full"
)
gl_repos_by_code_tailored %>%
expect_type("list") %>%
expect_length(length(gl_repos_by_code))
Expand All @@ -206,6 +293,27 @@ test_that("`tailor_repos_response()` tailors precisely `repos_list`", {
test_mocker$cache(gl_repos_by_code_tailored)
})

test_that("`tailor_repos_response()` tailors precisely to minimal `repos_list`", {
gl_repos_by_code <- test_mocker$use("gl_search_repos_by_code")
gl_repos_by_code_tailored <-
test_rest_gitlab$tailor_repos_response(
repos_response = gl_repos_by_code,
output = "table_min"
)
gl_repos_by_code_tailored %>%
expect_type("list") %>%
expect_length(length(gl_repos_by_code))

expect_list_contains_only(
gl_repos_by_code_tailored[[1]],
c("repo_id", "repo_name", "created_at", "default_branch", "organization")
)
expect_lt(
length(gl_repos_by_code_tailored[[1]]),
length(gl_repos_by_code[[1]])
)
})

test_that("REST client prepares table from GitLab repositories response", {
gl_repos_by_code_table <- test_rest_gitlab$prepare_repos_table(
repos_list = test_mocker$use("gl_repos_by_code_tailored"),
Expand Down
Loading

0 comments on commit 065b6f6

Please sign in to comment.