Skip to content

Commit

Permalink
Mock files structure tests for GitLab.
Browse files Browse the repository at this point in the history
  • Loading branch information
maciekbanas committed Oct 7, 2024
1 parent 2730946 commit c9fd7a5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 37 deletions.
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/get_files_structure-GitLab.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

Code
gl_files_structure_from_orgs <- gitlab_testhost_priv$
get_files_structure_from_orgs(pattern = "\\.md|\\.R", depth = 1L, verbose = TRUE,
get_files_structure_from_orgs(pattern = "\\.md", depth = 1L, verbose = TRUE,
progress = FALSE)
Message
i [Host:GitLab][Engine:GraphQl][Scope:mbtests] Pulling files structure...[files matching pattern: '\.md|\.R']...
i [Host:GitLab][Engine:GraphQl][Scope:mbtests] Pulling files structure...[files matching pattern: '\.md']...

# get_files_content makes use of files_structure

Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/helper-fixtures.R
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ test_fixtures$gitlab_files_tree_response <- list(
),
list(
"name" = "project_metadata.yaml"
),
list(
"name" = "report.md"
)
)
)
Expand Down
73 changes: 38 additions & 35 deletions tests/testthat/test-get_files_structure-GitLab.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ test_that("get_files_structure_from_repo() pulls files structure from repo", {
test_that("only files with certain pattern are retrieved", {
md_files_structure <- test_graphql_gitlab_priv$filter_files_by_pattern(
files_structure = test_mocker$use("gl_files_structure"),
pattern = "\\.md|\\.qmd|\\.Rmd"
pattern = "\\.md"
)
files_structure <- test_mocker$use("files_structure")
expect_true(
Expand Down Expand Up @@ -110,50 +110,73 @@ test_that("get_files_structure_from_repo() pulls files structure (files matching
})

test_that("GitLab GraphQL Engine pulls files structure from repositories", {
gl_repos_data <- list(
"repositories" = c("tests_repo_1", "tests_repo_2")
)
mockery::stub(
test_graphql_gitlab$get_files_structure_from_org,
"private$get_repos_data",
gl_repos_data
)
mockery::stub(
test_graphql_gitlab$get_files_structure_from_org,
"private$get_files_structure_from_repo",
test_mocker$use("gl_files_structure")
)
gl_files_structure <- test_graphql_gitlab$get_files_structure_from_org(
org = "mbtests",
repos = c("graphql_tests"),
repos = c("tests_repo_1", "tests_repo_2"),
verbose = FALSE,
progress = FALSE
)
purrr::walk(gl_files_structure, ~ expect_true(length(.) > 0))
expect_equal(
names(gl_files_structure),
c("graphql_tests")
c("tests_repo_1", "tests_repo_2")
)
purrr::walk(gl_files_structure, ~ expect_false(all(grepl("/$", .)))) # no empty dirs
test_mocker$cache(gl_files_structure)
})

test_that("GitLab GraphQL Engine pulls files structure from repositories", {
gl_repos_data <- list(
"repositories" = c("tests_repo_1", "tests_repo_2")
)
mockery::stub(
test_graphql_gitlab$get_files_structure_from_org,
"private$get_repos_data",
gl_repos_data
)
mockery::stub(
test_graphql_gitlab$get_files_structure_from_org,
"private$get_files_structure_from_repo",
test_mocker$use("gl_md_files_structure")
)
gl_files_structure_shallow <- test_graphql_gitlab$get_files_structure_from_org(
org = "mbtests",
repos = c("gitstatstesting", "graphql_tests"),
repos = c("tests_repo_1", "tests_repo_2"),
pattern = "\\.md",
depth = 1L,
verbose = FALSE,
progress = FALSE
)
purrr::walk(gl_files_structure_shallow, ~ expect_true(length(.) > 0))
expect_equal(
names(gl_files_structure_shallow),
c("graphql_tests", "gitstatstesting")
c("tests_repo_1", "tests_repo_2")
)
purrr::walk(gl_files_structure_shallow, ~ expect_false(all(grepl("/", .)))) # no dirs
test_mocker$cache(gl_files_structure_shallow)
})

test_that("get_files_structure_from_orgs pulls files structure for repositories in orgs", {
gitlab_testhost_priv <- create_gitlab_testhost(
repos = c("mbtests/gitstatstesting", "mbtests/graphql_tests"),
mode = "private"
mockery::stub(
gitlab_testhost_priv$get_files_structure_from_orgs,
"graphql_engine$get_files_structure_from_org",
test_mocker$use("gl_files_structure_shallow")
)
expect_snapshot(
gl_files_structure_from_orgs <- gitlab_testhost_priv$get_files_structure_from_orgs(
pattern = "\\.md|\\.R",
pattern = "\\.md",
depth = 1L,
verbose = TRUE,
progress = FALSE
Expand All @@ -164,27 +187,7 @@ test_that("get_files_structure_from_orgs pulls files structure for repositories
c("mbtests")
)
purrr::walk(gl_files_structure_from_orgs[[1]], function(repo_files) {
expect_true(all(grepl("\\.md|\\.R", repo_files)))
})
})

test_that("get_files_structure_from_orgs pulls files structure for all repositories in orgs", {
gitlab_testhost_priv <- create_gitlab_testhost(
orgs = c("mbtests", "mbtestapps"),
mode = "private"
)
gl_files_structure_from_orgs <- gitlab_testhost_priv$get_files_structure_from_orgs(
pattern = "\\.md|\\.R",
depth = 1L,
verbose = FALSE,
progress = FALSE
)
expect_equal(
names(gl_files_structure_from_orgs),
c("mbtests", "mbtestapps")
)
purrr::walk(gl_files_structure_from_orgs[[1]], function(repo_files) {
expect_true(all(grepl("\\.md|\\.R", repo_files)))
expect_true(all(grepl("\\.md", repo_files)))
})
test_mocker$cache(gl_files_structure_from_orgs)
})
Expand All @@ -211,17 +214,17 @@ test_that("get_files_structure pulls files structure for repositories in orgs",
test_mocker$use("gl_files_structure_from_orgs")
)
gl_files_structure_from_orgs <- gitlab_testhost$get_files_structure(
pattern = "\\.md|\\.R",
depth = 2L,
pattern = "\\.md",
depth = 1L,
verbose = FALSE,
progress = FALSE
)
expect_equal(
names(gl_files_structure_from_orgs),
c("mbtests", "mbtestapps")
c("mbtests")
)
purrr::walk(gl_files_structure_from_orgs[[1]], function(repo_files) {
expect_true(all(grepl("\\.md|\\.R", repo_files)))
expect_true(all(grepl("\\.md", repo_files)))
})
test_mocker$cache(gl_files_structure_from_orgs)
})
Expand Down

0 comments on commit c9fd7a5

Please sign in to comment.