Skip to content

Commit

Permalink
test: test if guess_where_config() works with path changes for the co…
Browse files Browse the repository at this point in the history
…nfig

- create a new dir for config
- move config to that dir and rename

=> test correctly identifies changes (changing dir AND changing filename) in the yaml-config.

attribute to @ALanguillaume with some minor tweaks

Co-authored-by: ALanguillaume <[email protected]>
  • Loading branch information
ilyaZar and ALanguillaume committed May 27, 2023
1 parent 83a96a7 commit 311df67
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tests/testthat/test-config.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,71 @@ test_that("config works", {
)
})
})
test_that("golem-config.yml can be moved to another location", {

path_dummy_golem <- tempfile(pattern = "dummygolem")

golem::create_golem(
path = path_dummy_golem,
open = FALSE
)

old_wd <- setwd(path_dummy_golem)
on.exit(setwd(old_wd))

# The good config path is returned
expect_equal(
golem:::guess_where_config(),
golem:::fs_path_abs(file.path(
path_dummy_golem,
"inst/golem-config.yml"
))
)
# document_and_reload does not throw an error
expect_error(
document_and_reload(),
regexp = NA
)
expect_equal(
get_golem_name(),
basename(path_dummy_golem)
)
expect_equal(
get_golem_wd(),
path_dummy_golem
)

## Move config file
dir.create(
"inst/config"
)
file.copy(
from = "inst/golem-config.yml",
to = "inst/config/golem.yml"
)
file.remove(
"inst/golem-config.yml"
)
# User adjusts the correct line in app_config.R:
tmp_app_config_r <- readLines("R/app_config.R")
tmp_app_config_r[36] <- " file = app_sys(\"config/golem.yml\")"
writeLines(tmp_app_config_r, "R/app_config.R")

# The good config path is returned
expect_equal(
golem:::guess_where_config(),
golem:::fs_path_abs(file.path(
path_dummy_golem,
"inst/config/golem.yml"
))
)
# document_and_reload does not throw an error
expect_error(
document_and_reload(),
regexp = NA
)
expect_equal(
get_golem_name(),
basename(path_dummy_golem)
)
})

0 comments on commit 311df67

Please sign in to comment.