diff --git a/tests/testthat/_snaps/applications.md b/tests/testthat/_snaps/applications.md index d60b6d36d..d36ff0ce8 100644 --- a/tests/testthat/_snaps/applications.md +++ b/tests/testthat/_snaps/applications.md @@ -1,7 +1,7 @@ # syncAppMetadata deletes deployment records if needed Code - syncAppMetadata(app) + syncAppMetadata(dir) Message Deleting deployment record for deleted app 123. diff --git a/tests/testthat/_snaps/bundlePackage.md b/tests/testthat/_snaps/bundlePackage.md index c06690a86..ee4deb111 100644 --- a/tests/testthat/_snaps/bundlePackage.md +++ b/tests/testthat/_snaps/bundlePackage.md @@ -1,7 +1,7 @@ # can snapshot deps with renv Code - pkgs <- bundlePackages(app_dir) + pkgs <- bundlePackages(dir) Message i Capturing R dependencies with renv v Found 1 dependency @@ -9,7 +9,7 @@ # can snapshot deps with packrat Code - pkgs <- bundlePackages(app_dir) + pkgs <- bundlePackages(dir) Message i Capturing R dependencies with packrat v Found 1 dependency @@ -17,7 +17,7 @@ # can capture deps from renv lockfile Code - pkgs <- bundlePackages(app_dir) + pkgs <- bundlePackages(dir) Message i Capturing R dependencies from renv.lock v Found 1 dependency @@ -25,7 +25,7 @@ # error if can't find source Code - . <- bundlePackages(app_dir) + . <- bundlePackages(dir) Message i Capturing R dependencies with renv v Found 1 dependency diff --git a/tests/testthat/_snaps/bundlePackagePackrat.md b/tests/testthat/_snaps/bundlePackagePackrat.md index b9a1a8559..c61220842 100644 --- a/tests/testthat/_snaps/bundlePackagePackrat.md +++ b/tests/testthat/_snaps/bundlePackagePackrat.md @@ -1,7 +1,7 @@ # uninstalled packages error Code - snapshotPackratDependencies(app) + snapshotPackratDependencies(dir) Condition Error in `addPackratSnapshot()`: ! Failed to snapshot dependencies diff --git a/tests/testthat/_snaps/deployApp.md b/tests/testthat/_snaps/deployApp.md index 9f0b1a3c5..07484813c 100644 --- a/tests/testthat/_snaps/deployApp.md +++ b/tests/testthat/_snaps/deployApp.md @@ -61,7 +61,7 @@ # applicationDeleted() errors or prompts as needed Code - applicationDeleted(client, target, app) + applicationDeleted(client, target, dir) Condition Error in `applicationDeleted()`: ! Failed to find existing application on server; it's probably been deleted. @@ -71,7 +71,7 @@ --- Code - . <- applicationDeleted(client, target, app) + . <- applicationDeleted(client, target, dir) Message Failed to find existing application on server; it's probably been deleted. What do you want to do? diff --git a/tests/testthat/_snaps/deploymentTarget.md b/tests/testthat/_snaps/deploymentTarget.md index e6d79370e..c12be4249 100644 --- a/tests/testthat/_snaps/deploymentTarget.md +++ b/tests/testthat/_snaps/deploymentTarget.md @@ -25,7 +25,7 @@ # errors if no previous deployments and multiple accounts Code - deploymentTarget(app_dir) + deploymentTarget(dir) Condition Error in `deploymentTarget()`: ! Found multiple accounts. @@ -33,7 +33,7 @@ i Available servers: "foo1" and "foo2". i Available account names: "ron". Code - deploymentTarget(app_dir, appName = "test") + deploymentTarget(dir, appName = "test") Condition Error in `deploymentTarget()`: ! Found multiple accounts. @@ -44,7 +44,7 @@ # handles accounts if only server specified Code - deploymentTarget(app_dir, server = "foo") + deploymentTarget(dir, server = "foo") Condition Error in `deploymentTarget()`: ! Found multiple accounts for `server` = "foo". @@ -54,7 +54,7 @@ # errors/prompts if multiple deployments Code - deploymentTarget(app_dir, appName = "test") + deploymentTarget(dir, appName = "test") Condition Error: ! This directory has been previously deployed in multiple places. @@ -63,7 +63,7 @@ * test (server: server1.com / username: ron): * test (server: server2.com / username: ron): Code - deploymentTarget(app_dir) + deploymentTarget(dir) Condition Error: ! This directory has been previously deployed in multiple places. @@ -75,7 +75,7 @@ --- Code - out <- deploymentTarget(app_dir) + out <- deploymentTarget(dir) Message This directory has been previously deployed in multiple places. Which deployment do you want to use? @@ -86,7 +86,7 @@ # errors if single deployment and appId doesn't match Code - deploymentTarget(app_dir, appName = "test", appId = "2") + deploymentTarget(dir, appName = "test", appId = "2") Condition Error: ! Supplied `appId` (2) does not match deployment record (1). diff --git a/tests/testthat/_snaps/deployments-find.md b/tests/testthat/_snaps/deployments-find.md index fa604ae59..e3a1b3eb0 100644 --- a/tests/testthat/_snaps/deployments-find.md +++ b/tests/testthat/_snaps/deployments-find.md @@ -1,7 +1,7 @@ # errors if no deployments Code - findDeployment(app) + findDeployment(dir) Condition Error: ! Couldn't find any deployments matching supplied criteria. @@ -9,7 +9,7 @@ # disambiguates multiple deployments Code - findDeployment(app) + findDeployment(dir) Condition Error: ! This directory has been previously deployed in multiple places. @@ -21,7 +21,7 @@ --- Code - dep <- findDeployment(app) + dep <- findDeployment(dir) Message This directory has been previously deployed in multiple places. Which deployment do you want to use? diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index e8d4a92ab..05573ee30 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -46,9 +46,10 @@ local_temp_config <- function(env = caller_env()) { withr::local_envvar(R_USER_CONFIG_DIR = path, .local_envir = env) } -local_temp_app <- function(files = list(), env = caller_env()) { - dir <- withr::local_tempdir(.local_envir = env) +local_temp_app <- function(..., .env = caller_env()) { + dir <- withr::local_tempdir(.local_envir = .env) + files <- list(...) for (name in names(files)) { content <- files[[name]] writeLines(content, file.path(dir, name)) diff --git a/tests/testthat/test-appDependencies.R b/tests/testthat/test-appDependencies.R index d488509e9..1551bc5f4 100644 --- a/tests/testthat/test-appDependencies.R +++ b/tests/testthat/test-appDependencies.R @@ -1,13 +1,13 @@ test_that("appDepenencies includes implicit deps", { - path <- local_temp_app(list("test.Rmd" = "")) - deps <- appDependencies(path) + dir <- local_temp_app(test.Rmd = "") + deps <- appDependencies(dir) expect_true("rmarkdown" %in% deps$Package) }) test_that("static project doesn't have deps", { - path <- local_temp_app(list("index.html" = "")) - deps <- appDependencies(path) + dir <- local_temp_app(index.html = "") + deps <- appDependencies(dir) expect_equal(deps, data.frame( Package = character(), diff --git a/tests/testthat/test-appMetadata.R b/tests/testthat/test-appMetadata.R index f8b9a5a85..d494a621d 100644 --- a/tests/testthat/test-appMetadata.R +++ b/tests/testthat/test-appMetadata.R @@ -6,7 +6,7 @@ test_that("clear error if no files", { }) test_that("quarto affects mode inference", { - dir <- local_temp_app(list("foo.Rmd" = "")) + dir <- local_temp_app(foo.Rmd = "") metadata <- appMetadata(dir) expect_equal(metadata$appMode, "rmd-static") @@ -16,18 +16,18 @@ test_that("quarto affects mode inference", { }) test_that("quarto path is deprecated", { - dir <- local_temp_app(list("foo.Rmd" = "")) + dir <- local_temp_app(foo.Rmd = "") expect_snapshot(. <- appMetadata(dir, quarto = "abc")) }) test_that("validates quarto argument", { - dir <- local_temp_app(list("foo.Rmd" = "")) + dir <- local_temp_app(foo.Rmd = "") expect_snapshot(appMetadata(dir, quarto = 1), error = TRUE) }) test_that("handles special case of appPrimaryDoc as R file", { - dir <- local_temp_app(list("foo.R" = "")) + dir <- local_temp_app(foo.R = "") metadata <- appMetadata(dir, appPrimaryDoc = "foo.R") expect_equal(metadata$appMode, "shiny") }) @@ -35,34 +35,34 @@ test_that("handles special case of appPrimaryDoc as R file", { # checkLayout ------------------------------------------------------------- test_that("checkLayout() errors if primary doc & app.R", { - dir <- local_temp_app(list( - "app.R" = "", - "myscript.R" = "" - )) + dir <- local_temp_app( + app.R = "", + myscript.R = "" + ) expect_snapshot(checkAppLayout(dir, "myscript.R"), error = TRUE) }) test_that("checkLayout fails if no known structure", { - dir <- local_temp_app(list( - "data.txt" = "", - "cats.csv" = "" - )) + dir <- local_temp_app( + data.txt = "", + cats.csv = "" + ) expect_snapshot(checkAppLayout(dir), error = TRUE) }) test_that("checkLayout succeeds with some common app structures", { - rmd <- local_temp_app(list("foo.Rmd" = "")) + rmd <- local_temp_app(foo.Rmd = "") expect_no_error(checkAppLayout(rmd)) - shiny1 <- local_temp_app(list("app.R" = "")) + shiny1 <- local_temp_app(app.R = "") expect_no_error(checkAppLayout(rmd)) - shiny2 <- local_temp_app(list("server.R" = "", "ui.R" = "")) + shiny2 <- local_temp_app(server.R = "", ui.R = "") expect_no_error(checkAppLayout(rmd)) - static <- local_temp_app(list("foo.html" = "")) + static <- local_temp_app(foo.html = "") expect_no_error(checkAppLayout(rmd)) }) @@ -79,7 +79,7 @@ test_that("can infer mode for shiny apps", { }) test_that("can infer mode for static quarto and rmd docs", { - dir <- local_temp_app(list("foo.Rmd" = "")) + dir <- local_temp_app(foo.Rmd = "") paths <- list.files(dir, full.names = TRUE) expect_equal(inferAppMode(paths), "rmd-static") @@ -93,25 +93,25 @@ test_that("can infer mode for shiny rmd docs", { c("---", paste0("runtime: ", runtime), "---") } - dir <- local_temp_app(list("index.Rmd" = yaml_runtime("shiny"))) + dir <- local_temp_app(index.Rmd = yaml_runtime("shiny")) paths <- list.files(dir, full.names = TRUE) expect_equal(inferAppMode(paths), "rmd-shiny") - dir <- local_temp_app(list("index.Rmd" = yaml_runtime("shinyrmd"))) + dir <- local_temp_app(index.Rmd = yaml_runtime("shinyrmd")) paths <- list.files(dir, full.names = TRUE) expect_equal(inferAppMode(paths), "rmd-shiny") - dir <- local_temp_app(list("index.Rmd" = yaml_runtime("shiny_prerendered"))) + dir <- local_temp_app(index.Rmd = yaml_runtime("shiny_prerendered")) paths <- list.files(dir, full.names = TRUE) expect_equal(inferAppMode(paths), "rmd-shiny") # can pair server.R with shiny runtime - dir <- local_temp_app(list("index.Rmd" = yaml_runtime("shiny"), "server.R" = "")) + dir <- local_temp_app(index.Rmd = yaml_runtime("shiny"), server.R = "") paths <- list.files(dir, full.names = TRUE) expect_equal(inferAppMode(paths), "rmd-shiny") # Beats static rmarkdowns - dir <- local_temp_app(list("index.Rmd" = yaml_runtime("shiny"), "foo.Rmd" = "")) + dir <- local_temp_app(index.Rmd = yaml_runtime("shiny"), foo.Rmd = "") paths <- list.files(dir, full.names = TRUE) expect_equal(inferAppMode(paths), "rmd-shiny") }) @@ -121,20 +121,20 @@ test_that("can infer mode for shiny qmd docs", { c("---", paste0("runtime: ", runtime), "---") } - dir <- local_temp_app(list("index.Qmd" = yaml_runtime("shiny"))) + dir <- local_temp_app(index.Qmd = yaml_runtime("shiny")) paths <- list.files(dir, full.names = TRUE) expect_equal(inferAppMode(paths), "quarto-shiny") # Can force Rmd to use quarto - dir <- local_temp_app(list("index.Rmd" = yaml_runtime("shiny"))) + dir <- local_temp_app(index.Rmd = yaml_runtime("shiny")) paths <- list.files(dir, full.names = TRUE) expect_equal(inferAppMode(paths, usesQuarto = TRUE), "quarto-shiny") # Prefers quarto if both present - dir <- local_temp_app(list( - "index.Qmd" = yaml_runtime("shiny"), - "index.Rmd" = yaml_runtime("shiny") - )) + dir <- local_temp_app( + index.Qmd = yaml_runtime("shiny"), + index.Rmd = yaml_runtime("shiny") + ) paths <- list.files(dir, full.names = TRUE) expect_equal(inferAppMode(paths), "quarto-shiny") }) @@ -187,29 +187,29 @@ test_that("errors if no files with needed extension", { # appHasParameters -------------------------------------------------------- test_that("non-documents don't have parameters", { - dir <- local_temp_app(list("foo.R" = "")) + dir <- local_temp_app(foo.R = "") expect_false(appHasParameters(dir, "foo.R", "static")) expect_false(appHasParameters(dir, "foo.R", "shiny")) }) test_that("documents don't have parameters if part of a site", { - dir <- local_temp_app(list("index.Rmd" = c("---", "params: [1, 2]", "---"))) + dir <- local_temp_app(index.Rmd = c("---", "params: [1, 2]", "---")) expect_false(appHasParameters(dir, "index.Rmd", "rmd-static", "site")) expect_false(appHasParameters(dir, "index.Rmd", "qmd-shiny", "site")) }) test_that("non-Rmd files don't have parameters", { - dir <- local_temp_app(list("app.r" = c(""))) + dir <- local_temp_app(app.r = c("")) expect_false(appHasParameters(dir, "app.R", "rmd-shiny")) }) test_that("otherwise look at yaml metadata", { - dir <- local_temp_app(list("index.Rmd" = c("---", "params: [1, 2]", "---"))) + dir <- local_temp_app(index.Rmd = c("---", "params: [1, 2]", "---")) expect_true(appHasParameters(dir, "index.Rmd", "rmd-shiny")) - dir <- local_temp_app(list("index.Rmd" = c("---", "params: ~", "---"))) + dir <- local_temp_app(index.Rmd = c("---", "params: ~", "---")) expect_false(appHasParameters(dir, "index.Rmd", "rmd-shiny")) }) @@ -219,17 +219,17 @@ test_that("dir without Rmds doesn't have have python", { dir <- local_temp_app() expect_false(detectPythonInDocuments(dir)) - dir <- local_temp_app(list("foo.R" = "")) + dir <- local_temp_app(foo.R = "") expect_false(detectPythonInDocuments(dir)) }) test_that("Rmd or qmd with python chunk has python", { - dir <- local_temp_app(list("foo.qmd" = c("```{r}", "1+1", "````"))) + dir <- local_temp_app(foo.qmd = c("```{r}", "1+1", "````")) expect_false(detectPythonInDocuments(dir)) - dir <- local_temp_app(list("foo.Rmd" = c("```{python}", "1+1", "````"))) + dir <- local_temp_app(foo.Rmd = c("```{python}", "1+1", "````")) expect_true(detectPythonInDocuments(dir)) - dir <- local_temp_app(list("foo.qmd" = c("```{python}", "1+1", "````"))) + dir <- local_temp_app(foo.qmd = c("```{python}", "1+1", "````")) expect_true(detectPythonInDocuments(dir)) }) diff --git a/tests/testthat/test-applications.R b/tests/testthat/test-applications.R index 0da2679a8..41d734353 100644 --- a/tests/testthat/test-applications.R +++ b/tests/testthat/test-applications.R @@ -3,16 +3,16 @@ test_that("syncAppMetadata updates deployment records", { addTestServer() addTestAccount("ron") - app <- local_temp_app() - addTestDeployment(app, appId = "123", metadata = list(when = 123)) + dir <- local_temp_app() + addTestDeployment(dir, appId = "123", metadata = list(when = 123)) local_mocked_bindings(clientForAccount = function(...) { list( getApplication = function(...) list(title = "newtitle", url = "newurl") ) }) - syncAppMetadata(app) - deps <- deployments(app) + syncAppMetadata(dir) + deps <- deployments(dir) expect_equal(deps$title, "newtitle") expect_equal(deps$url, "newurl") expect_equal(deps$when, NULL) @@ -23,14 +23,14 @@ test_that("syncAppMetadata deletes deployment records if needed", { addTestServer() addTestAccount("ron") - app <- local_temp_app() - addTestDeployment(app, appId = "123", metadata = list(when = 123)) + dir <- local_temp_app() + addTestDeployment(dir, appId = "123", metadata = list(when = 123)) local_mocked_bindings(clientForAccount = function(...) { list( getApplication = function(...) abort(class = "rsconnect_http_404") ) }) - expect_snapshot(syncAppMetadata(app)) - expect_equal(nrow(deployments(app)), 0) + expect_snapshot(syncAppMetadata(dir)) + expect_equal(nrow(deployments(dir)), 0) }) diff --git a/tests/testthat/test-bundle.R b/tests/testthat/test-bundle.R index 3c06ace27..f1f216aa5 100644 --- a/tests/testthat/test-bundle.R +++ b/tests/testthat/test-bundle.R @@ -171,8 +171,7 @@ test_that("tarImplementation: checks environment variable and option before usin # tweakRProfile ----------------------------------------------------------- test_that(".Rprofile tweaked automatically", { - dir <- withr::local_tempdir() - writeLines('source("renv/activate.R")', file.path(dir, ".Rprofile")) + dir <- local_temp_app(.Rprofile = 'source("renv/activate.R")') bundled <- bundleAppDir(dir, list.files(dir, all.files = TRUE)) expect_match( diff --git a/tests/testthat/test-bundleFiles.R b/tests/testthat/test-bundleFiles.R index 067a1ce7d..1f064f3d9 100644 --- a/tests/testthat/test-bundleFiles.R +++ b/tests/testthat/test-bundleFiles.R @@ -2,7 +2,7 @@ # listDeploymentFiles ------------------------------------------------------ test_that("can read all files from directory", { - dir <- local_temp_app(list("a.R" = "", "b.R" = "")) + dir <- local_temp_app(a.R = "", b.R = "") expect_equal(listDeploymentFiles(dir), c("a.R", "b.R")) expect_equal(listDeploymentFiles(dir, NULL, NULL), c("a.R", "b.R")) @@ -11,7 +11,7 @@ test_that("can read all files from directory", { }) test_that("can read selected files from directory", { - dir <- local_temp_app(list("a.R" = "", "b.R" = "")) + dir <- local_temp_app(a.R = "", b.R = "") expect_equal(listDeploymentFiles(dir, "b.R"), "b.R") expect_snapshot(out <- listDeploymentFiles(dir, c("b.R", "c.R"))) expect_equal(out, "b.R") @@ -19,30 +19,30 @@ test_that("can read selected files from directory", { }) test_that("can read selected files from manifest", { - dir <- local_temp_app(list( - "a.R" = "", - "b.R" = "", - "manifest" = "b.R" - )) + dir <- local_temp_app( + a.R = "", + b.R = "", + manifest = "b.R" + ) expect_equal( listDeploymentFiles(dir, appFileManifest = file.path(dir, "manifest")), "b.R" ) - dir <- local_temp_app(list( - "a.R" = "", - "b.R" = "", - "manifest" = c("b.R", "c.R") - )) + dir <- local_temp_app( + a.R = "", + b.R = "", + manifest = c("b.R", "c.R") + ) expect_snapshot( out <- listDeploymentFiles(dir, appFileManifest = file.path(dir, "manifest")), ) expect_equal(out, "b.R") # errors if no matching files - dir <- local_temp_app(list( - "manifest" = "" - )) + dir <- local_temp_app( + manifest = "" + ) expect_snapshot( listDeploymentFiles(dir, appFileManifest = file.path(dir, "manifest")), error = TRUE @@ -62,7 +62,7 @@ test_that("checks its inputs", { # listBundleFiles --------------------------------------------------------- test_that("bundle directories are recursively enumerated", { - dir <- withr::local_tempdir() + dir <- local_temp_app() # tree that resembles the case from https://github.com/rstudio/rsconnect/issues/464 files <- c( @@ -88,14 +88,17 @@ test_that("bundle directories are recursively enumerated", { }) test_that("ignores RStudio files", { - dir <- withr::local_tempdir() - file.create(file.path(dir, c("test.Rproj", ".Rproj.user", "rsconnect"))) + dir <- local_temp_app( + test.Rproj = "", + .Rproj.user = "", + rsconnect = "" + ) expect_equal(bundleFiles(dir), character()) }) test_that("ignores knitr cache directories", { - dir <- withr::local_tempdir() + dir <- local_temp_app() dirCreate(file.path(dir, c("foo_cache", "bar_cache"))) file.create(file.path(dir, c("foo_cache", "bar_cache"), "contents")) file.create(file.path(dir, c("foo.Rmd"))) @@ -104,7 +107,7 @@ test_that("ignores knitr cache directories", { }) test_that("ignores files anywhere in path", { - dir <- withr::local_tempdir() + dir <- local_temp_app() dirCreate(file.path(dir, "a/b/c")) file.create(file.path(dir, c("x", "a/b/.gitignore", "a/b/c/.DS_Store"))) @@ -133,7 +136,7 @@ test_that("ignores temporary files", { }) test_that("ignores python virtual envs", { - dir <- withr::local_tempdir() + dir <- local_temp_app() dirCreate(file.path(dir, "test", "bin")) file.create(file.path(dir, "test", "bin", "python")) dirCreate(file.path(dir, "venv")) @@ -145,7 +148,7 @@ test_that("ignores python virtual envs", { # explodeFiles ------------------------------------------------------------ test_that("returns relative paths", { - dir <- withr::local_tempdir() + dir <- local_temp_app() dirCreate(file.path(dir, "x")) file.create(file.path(dir, "x", c("a", "b", "c"))) @@ -153,7 +156,7 @@ test_that("returns relative paths", { }) test_that("drops drops non-existent files with warning", { - dir <- withr::local_tempdir() + dir <- local_temp_app() file.create(file.path(dir, c("a", "b", "c"))) expect_snapshot(out <- explodeFiles(dir, c("a", "d"))) @@ -161,7 +164,7 @@ test_that("drops drops non-existent files with warning", { }) test_that("expands files and directory", { - dir <- withr::local_tempdir() + dir <- local_temp_app() dirCreate(file.path(dir, "x")) file.create(file.path(dir, "x", c("a", "b"))) file.create(file.path(dir, "c")) @@ -170,7 +173,7 @@ test_that("expands files and directory", { }) test_that("can include nested files/directories", { - dir <- withr::local_tempdir() + dir <- local_temp_app() dirCreate(file.path(dir, "x", "y")) file.create(file.path(dir, "x", c("a", "b", "c"))) file.create(file.path(dir, "x", "y", c("d", "e"))) @@ -181,7 +184,7 @@ test_that("can include nested files/directories", { }) test_that("doesn't ignore user supplied files", { - dir <- withr::local_tempdir() + dir <- local_temp_app() dirCreate(file.path(dir, "x", "y")) file.create(file.path(dir, "x", "packrat")) file.create(file.path(dir, "x", "y", "packrat")) @@ -192,7 +195,7 @@ test_that("doesn't ignore user supplied files", { # enforceBundleLimits ----------------------------------------------------- test_that("explodeFiles() and bundleFiles() both eagerly enforce limits", { - dir <- withr::local_tempdir() + dir <- local_temp_app() dirCreate(file.path(dir, c("a", "b"))) file.create(file.path(dir, "a", letters)) file.create(file.path(dir, "b", letters)) @@ -205,7 +208,7 @@ test_that("explodeFiles() and bundleFiles() both eagerly enforce limits", { }) test_that("generate nicely formatted messages", { - dir <- withr::local_tempdir() + dir <- local_temp_app() file.create(file.path(dir, c("a", "b"))) writeLines(letters, file.path(dir, "c")) @@ -234,7 +237,7 @@ test_that("generate nicely formatted messages", { test_that("detectLongNames produces informative warning if needed", { skip_on_os("windows") - dir <- local_temp_app(c("a.r" = "", "b.r" = "", "c.r" = "")) + dir <- local_temp_app(a.r = "", b.r = "", c.r = "") expect_snapshot(detectLongNames(dir, 0)) expect_silent(detectLongNames(dir, Inf)) }) diff --git a/tests/testthat/test-bundlePackage.R b/tests/testthat/test-bundlePackage.R index fe8498045..ce5ffdab8 100644 --- a/tests/testthat/test-bundlePackage.R +++ b/tests/testthat/test-bundlePackage.R @@ -1,32 +1,32 @@ test_that("can snapshot deps with renv", { - app_dir <- local_temp_app(list("foo.R" = "library(MASS)")) - expect_snapshot(pkgs <- bundlePackages(app_dir)) + dir <- local_temp_app(foo.R = "library(MASS)") + expect_snapshot(pkgs <- bundlePackages(dir)) expect_named(pkgs, "MASS") # No renv lockfile left behind - expect_equal(list.files(app_dir), "foo.R") + expect_equal(list.files(dir), "foo.R") }) test_that("can snapshot deps with packrat", { withr::local_options(rsconnect.packrat = TRUE) - app_dir <- local_temp_app(list("foo.R" = "library(MASS)")) - expect_snapshot(pkgs <- bundlePackages(app_dir)) + dir <- local_temp_app(foo.R = "library(MASS)") + expect_snapshot(pkgs <- bundlePackages(dir)) expect_named(pkgs, "MASS") # No packrat lockfile left behind - expect_equal(list.files(app_dir), "foo.R") + expect_equal(list.files(dir), "foo.R") }) test_that("can capture deps from renv lockfile", { withr::local_options(renv.verbose = FALSE) - app_dir <- local_temp_app(list(foo.R = "library(foreign)")) - renv::snapshot(app_dir, prompt = FALSE) - expect_snapshot(pkgs <- bundlePackages(app_dir)) + dir <- local_temp_app(foo.R = "library(foreign)") + renv::snapshot(dir, prompt = FALSE) + expect_snapshot(pkgs <- bundlePackages(dir)) expect_named(pkgs, "foreign") # No renv lockfile or directory left behind - expect_equal(list.files(app_dir), "foo.R") + expect_equal(list.files(dir), "foo.R") }) # ------------------------------------------------------------------------- @@ -41,15 +41,14 @@ test_that("error if can't find source", { ) }) - app_dir <- withr::local_tempdir() - writeLines(con = file.path(app_dir, "index.Rmd"), c( + dir <- local_temp_app(index.Rmd = c( "```{r}", "library(shiny)", "```" )) expect_snapshot( - . <- bundlePackages(app_dir), + . <- bundlePackages(dir), error = TRUE ) }) diff --git a/tests/testthat/test-bundlePackagePackrat.R b/tests/testthat/test-bundlePackagePackrat.R index 7cf7a5e3b..699e57319 100644 --- a/tests/testthat/test-bundlePackagePackrat.R +++ b/tests/testthat/test-bundlePackagePackrat.R @@ -1,45 +1,45 @@ test_that("non-R apps don't have packages", { - app_dir <- local_temp_app(list(index.html = "")) - out <- snapshotPackratDependencies(app_dir) + dir <- local_temp_app(index.html = "") + out <- snapshotPackratDependencies(dir) expect_equal(out, data.frame()) }) test_that("uninstalled packages error", { - app <- local_temp_app(list("index.Rmd" = c( + dir <- local_temp_app(index.Rmd = c( "```{r}", "library(doesntexist1)", "library(doesntexist2)", "```" - ))) + )) expect_snapshot( - snapshotPackratDependencies(app), + snapshotPackratDependencies(dir), error = TRUE, transform = function(x) gsub('"', "'", x, fixed = TRUE) ) }) test_that("recommended packages are snapshotted", { - app <- local_temp_app(list("index.Rmd" = c( + dir <- local_temp_app(index.Rmd = c( "```{r}", "library(MASS)", "```" - ))) - deps <- snapshotPackratDependencies(app) + )) + deps <- snapshotPackratDependencies(dir) expect_true("MASS" %in% deps$Package) }) test_that("works with BioC packages", { - app <- local_temp_app(list("index.Rmd" = c( + dir <- local_temp_app(index.Rmd = c( "```{r}", "library(Biobase)", "```" - ))) + )) withr::local_options(repos = c( CRAN = "https://cran.rstudio.com", BioC = "https://bioconductor.org/packages/3.16/bioc" )) - deps <- snapshotPackratDependencies(app) + deps <- snapshotPackratDependencies(dir) Biobase <- deps[deps$Package == "Biobase", ] expect_equal(Biobase$Source, "Bioconductor") @@ -53,7 +53,7 @@ test_that("works with BioC packages", { # addPackratSnapshot() ---------------------------------------------------- test_that("cleans up implicit dependency files", { - dir <- withr::local_tempdir() + dir <- local_temp_app() addPackratSnapshot(dir, "rlang") expect_equal(list.files(dir), "packrat") }) diff --git a/tests/testthat/test-bundlePackageRenv.R b/tests/testthat/test-bundlePackageRenv.R index e8883d374..0fb9a0821 100644 --- a/tests/testthat/test-bundlePackageRenv.R +++ b/tests/testthat/test-bundlePackageRenv.R @@ -1,31 +1,31 @@ # snapshotRenvDependencies() ---------------------------------------------- test_that("non-R apps don't have packages", { - app_dir <- local_temp_app(list(index.html = "")) - out <- snapshotRenvDependencies(app_dir) + dir <- local_temp_app(index.html = "") + out <- snapshotRenvDependencies(dir) expect_equal(out, data.frame()) }) test_that("recommended packages are snapshotted", { - app <- local_temp_app(list("index.Rmd" = c( + dir <- local_temp_app(index.Rmd = c( "```{r}", "library(MASS)", "```" - ))) - deps <- snapshotRenvDependencies(app) + )) + deps <- snapshotRenvDependencies(dir) expect_true("MASS" %in% deps$Package) }) test_that("works with BioC packages", { - app <- local_temp_app(list("index.R" = c( + dir <- local_temp_app(index.R = c( "library(Biobase)" - ))) + )) withr::local_options(repos = c( CRAN = "https://cran.rstudio.com", BioC = "https://bioconductor.org/packages/3.16/bioc" )) expect_no_condition( - deps <- snapshotRenvDependencies(app), + deps <- snapshotRenvDependencies(dir), class = "rsconnect_biocRepos" ) Biobase <- deps[deps$Package == "Biobase", ] @@ -36,7 +36,7 @@ test_that("works with BioC packages", { CRAN = "https://cran.rstudio.com" )) expect_condition( - deps <- snapshotRenvDependencies(app), + deps <- snapshotRenvDependencies(dir), class = "rsconnect_biocRepos" ) @@ -50,10 +50,10 @@ test_that("works with BioC packages", { test_that("gets DESCRIPTION from renv library", { withr::local_options(renv.verbose = FALSE) - app_dir <- local_temp_app(list("foo.R" = "library(withr); library(foreign)")) - renv::snapshot(app_dir, prompt = FALSE) + dir <- local_temp_app(foo.R = "library(withr); library(foreign)") + renv::snapshot(dir, prompt = FALSE) - deps <- parseRenvDependencies(app_dir) + deps <- parseRenvDependencies(dir) expect_setequal(deps$Package, c("foreign", "withr")) }) diff --git a/tests/testthat/test-bundlePython.R b/tests/testthat/test-bundlePython.R index b6e25e36e..b8d9b8194 100644 --- a/tests/testthat/test-bundlePython.R +++ b/tests/testthat/test-bundlePython.R @@ -48,7 +48,7 @@ test_that("can infer env from existing directory", { test_that("doesn't override existing requirements.txt by default", { skip_on_cran() - dir <- local_temp_app(list(requirements.txt = "pip")) + dir <- local_temp_app(requirements.txt = "pip") env <- inferPythonEnv(dir, pythonPathOrSkip()) expect_equal(env$package_manager$contents, "pip\n") @@ -60,7 +60,7 @@ test_that("throws error if environment.py fails", { skip_on_cran() skip_on_os("windows") - dir <- local_temp_app(list(requirements.txt = "\\")) + dir <- local_temp_app(requirements.txt = "\\") Sys.chmod(file.path(dir, "requirements.txt"), "000") withr::local_dir(dir) diff --git a/tests/testthat/test-deployApp.R b/tests/testthat/test-deployApp.R index bc557214b..2b2c9922b 100644 --- a/tests/testthat/test-deployApp.R +++ b/tests/testthat/test-deployApp.R @@ -86,15 +86,15 @@ test_that("applicationDeleted() errors or prompts as needed", { local_temp_config() addTestServer("s") addTestAccount("a", "s") - app <- local_temp_app() - addTestDeployment(app, appName = "name", account = "a", server = "s") - target <- createDeploymentTarget("name", "title", "id", NULL, "a", "a", "s", 1) + dir <- local_temp_app() + addTestDeployment(dir, appName = "name", account = "a", server = "s") + target <- createDeploymentTarget("name", "title", "id", NULL, "a", "a", "s") client <- list(createApplication = function(...) NULL) - expect_snapshot(applicationDeleted(client, target, app), error = TRUE) - expect_length(dir(app, recursive = TRUE), 1) + expect_snapshot(applicationDeleted(client, target, dir), error = TRUE) + expect_length(dir(dir, recursive = TRUE), 1) simulate_user_input(2) - expect_snapshot(. <- applicationDeleted(client, target, app)) - expect_length(dir(app, recursive = TRUE), 0) + expect_snapshot(. <- applicationDeleted(client, target, dir)) + expect_length(dir(dir, recursive = TRUE), 0) }) diff --git a/tests/testthat/test-deployDoc.R b/tests/testthat/test-deployDoc.R index e1c446968..ab47d87c4 100644 --- a/tests/testthat/test-deployDoc.R +++ b/tests/testthat/test-deployDoc.R @@ -5,7 +5,7 @@ test_that("deployDoc correctly reports bad path", { # standardizeSingleDocDeployment ------------------------------------------ test_that("turns appDir into appDir + appPrimarySourceDoc", { - dir <- local_temp_app(list("foo.R" = "")) + dir <- local_temp_app(foo.R = "") doc <- standardizeSingleDocDeployment(file.path(dir, "foo.R")) expect_equal(doc$appDir, normalizePath(dir)) @@ -13,34 +13,34 @@ test_that("turns appDir into appDir + appPrimarySourceDoc", { }) test_that("shiny rmd deploys whole directory", { - dir <- local_temp_app(list("foo.Rmd" = c( + dir <- local_temp_app(foo.Rmd = c( "---", "runtime: shiny", "---" - ))) + )) doc <- standardizeSingleDocDeployment(file.path(dir, "foo.Rmd")) expect_equal(doc$appFiles, NULL) }) test_that("regular rmd deploys file and dependencies", { - dir <- local_temp_app(list( - "foo.Rmd" = c( + dir <- local_temp_app( + foo.Rmd = c( "---", "resource_files: [foo.csv]", "---" ), - "foo.csv" = "" - )) + foo.csv = "" + ) doc <- standardizeSingleDocDeployment(file.path(dir, "foo.Rmd"), quiet = TRUE) expect_equal(doc$appFiles, c("foo.Rmd", "foo.csv")) }) test_that("regular rmd deploys .Rprofile, if present", { - dir <- local_temp_app(list( - "foo.Rmd" = "", - ".Rprofile" = "" - )) + dir <- local_temp_app( + foo.Rmd = "", + .Rprofile = "" + ) doc <- standardizeSingleDocDeployment(file.path(dir, "foo.Rmd"), quiet = TRUE) expect_equal(doc$appFiles, c("foo.Rmd", ".Rprofile")) @@ -48,7 +48,7 @@ test_that("regular rmd deploys .Rprofile, if present", { test_that("other types deploy that one file", { - dir <- local_temp_app(list("foo.R" = "")) + dir <- local_temp_app(foo.R = "") doc <- standardizeSingleDocDeployment(file.path(dir, "foo.R")) expect_equal(doc$appFiles, "foo.R") }) diff --git a/tests/testthat/test-deploySite.R b/tests/testthat/test-deploySite.R index 04230d8a8..debacd508 100644 --- a/tests/testthat/test-deploySite.R +++ b/tests/testthat/test-deploySite.R @@ -1,24 +1,24 @@ test_that("can extract quarto metadata", { - app <- local_temp_app(list(`_quarto.yaml` = c( + dir <- local_temp_app(`_quarto.yaml` = c( "project:", " type: website", "", "website:", " title: 'website-quarto'" - ))) + )) - site <- quartoSite(app) + site <- quartoSite(dir) expect_equal(site$title, "website-quarto") - expect_equal(site$output_dir, normalizePath(file.path(app, "_site"))) + expect_equal(site$output_dir, normalizePath(file.path(dir, "_site"))) }) test_that("can extract rmarkdown metadata", { - app <- local_temp_app(list( + dir <- local_temp_app( `_site.yml` = 'name: "my-website"' - )) + ) - site <- rmarkdownSite(app) + site <- rmarkdownSite(dir) expect_equal(site$name, "my-website") expect_equal(site$title, NULL) - expect_equal(site$output_dir, normalizePath(file.path(app, "_site"))) + expect_equal(site$output_dir, normalizePath(file.path(dir, "_site"))) }) diff --git a/tests/testthat/test-deploymentTarget.R b/tests/testthat/test-deploymentTarget.R index 9f242b3c1..73e4115b5 100644 --- a/tests/testthat/test-deploymentTarget.R +++ b/tests/testthat/test-deploymentTarget.R @@ -22,12 +22,11 @@ test_that("errors if no previous deployments and multiple accounts", { addTestAccount("ron", "foo1") addTestAccount("ron", "foo2") - app_dir <- withr::local_tempdir() - file.create(file.path(app_dir, "app.R")) + dir <- local_temp_app(app.R = "") expect_snapshot(error = TRUE, { - deploymentTarget(app_dir) - deploymentTarget(app_dir, appName = "test") + deploymentTarget(dir) + deploymentTarget(dir, appName = "test") }) }) @@ -37,14 +36,12 @@ test_that("handles accounts if only server specified", { addTestAccount("ron", "foo") addTestAccount("john", "foo") local_mocked_bindings(applications = function(...) data.frame()) + dir <- local_temp_app(app.R = "") - app_dir <- withr::local_tempdir() - file.create(file.path(app_dir, "app.R")) - - expect_snapshot(deploymentTarget(app_dir, server = "foo"), error = TRUE) + expect_snapshot(deploymentTarget(dir, server = "foo"), error = TRUE) target <- deploymentTarget( - app_dir, + dir, server = "foo", account = "ron" ) @@ -58,17 +55,17 @@ test_that("errors/prompts if multiple deployments", { addTestAccount("ron", "server1.com") addTestAccount("ron", "server2.com") - app_dir <- withr::local_tempdir() - addTestDeployment(app_dir, server = "server1.com") - addTestDeployment(app_dir, server = "server2.com") + dir <- local_temp_app() + addTestDeployment(dir, server = "server1.com") + addTestDeployment(dir, server = "server2.com") expect_snapshot(error = TRUE, { - deploymentTarget(app_dir, appName = "test") - deploymentTarget(app_dir) + deploymentTarget(dir, appName = "test") + deploymentTarget(dir) }) simulate_user_input(1) - expect_snapshot(out <- deploymentTarget(app_dir)) + expect_snapshot(out <- deploymentTarget(dir)) expect_equal(out$appName, "test") }) @@ -77,21 +74,21 @@ test_that("succeeds if there's a single existing deployment", { addTestServer() addTestAccount("ron") - app_dir <- withr::local_tempdir() + dir <- local_temp_app() addTestDeployment( - app_dir, + dir, appName = "test", appId = "1", username = "ron", version = "999" ) - target <- deploymentTarget(app_dir) + target <- deploymentTarget(dir) expect_equal(target$appId, "1") expect_equal(target$username, "ron") expect_equal(target$version, "999") - target <- deploymentTarget(app_dir, appName = "test") + target <- deploymentTarget(dir, appName = "test") expect_equal(target$appId, "1") expect_equal(target$username, "ron") }) @@ -101,12 +98,12 @@ test_that("errors if single deployment and appId doesn't match", { addTestServer() addTestAccount("ron") - app_dir <- withr::local_tempdir() - addTestDeployment(app_dir, appName = "test", appId = "1", username = "ron") + dir <- local_temp_app() + addTestDeployment(dir, appName = "test", appId = "1", username = "ron") expect_snapshot( error = TRUE, - deploymentTarget(app_dir, appName = "test", appId = "2") + deploymentTarget(dir, appName = "test", appId = "2") ) }) @@ -115,46 +112,46 @@ test_that("new title overrides existing title", { addTestServer() addTestAccount("ron") local_mocked_bindings(applications = function(...) data.frame()) - app_dir <- withr::local_tempdir() - addTestDeployment(app_dir, appTitle = "old title") + dir <- local_temp_app() + addTestDeployment(dir, appTitle = "old title") - target <- deploymentTarget(app_dir) + target <- deploymentTarget(dir) expect_equal(target$appTitle, "old title") - target <- deploymentTarget(app_dir, appTitle = "new title") + target <- deploymentTarget(dir, appTitle = "new title") expect_equal(target$appTitle, "new title") }) test_that("new env vars overrides existing", { local_temp_config() - app <- local_temp_app() + dir <- local_temp_app() addTestServer() addTestAccount() - addTestDeployment(app, envVars = "TEST1") + addTestDeployment(dir, envVars = "TEST1") - target <- deploymentTarget(app) + target <- deploymentTarget(dir) expect_equal(target$envVars, "TEST1") - target <- deploymentTarget(app, envVars = "TEST2") + target <- deploymentTarget(dir, envVars = "TEST2") expect_equal(target$envVars, "TEST2") # And check that it works with vectors - addTestDeployment(app, envVars = c("TEST1", "TEST2")) - target <- deploymentTarget(app) + addTestDeployment(dir, envVars = c("TEST1", "TEST2")) + target <- deploymentTarget(dir) expect_equal(target$envVars, c("TEST1", "TEST2")) - target <- deploymentTarget(app, envVars = "TEST2") + target <- deploymentTarget(dir, envVars = "TEST2") expect_equal(target$envVars, "TEST2") }) test_that("empty character vector removes env vars", { local_temp_config() - app <- local_temp_app() + dir <- local_temp_app() addTestServer() addTestAccount() - addTestDeployment(app, envVars = "TEST1") + addTestDeployment(dir, envVars = "TEST1") - target <- deploymentTarget(app, envVars = character()) + target <- deploymentTarget(dir, envVars = character()) expect_equal(target$envVars, character()) }) @@ -164,14 +161,13 @@ test_that("succeeds if there are no deployments and a single account", { addTestAccount("ron") local_mocked_bindings(applications = function(...) data.frame()) - app_dir <- dirCreate(file.path(withr::local_tempdir(), "my_app")) - - target <- deploymentTarget(app_dir, envVars = c("TEST1", "TEST2")) + dir <- dirCreate(file.path(local_temp_app(), "my_app")) + target <- deploymentTarget(dir, envVars = c("TEST1", "TEST2")) expect_equal(target$appName, "my_app") expect_equal(target$username, "ron") expect_equal(target$envVars, c("TEST1", "TEST2")) - target <- deploymentTarget(app_dir, appName = "foo") + target <- deploymentTarget(dir, appName = "foo") expect_equal(target$username, "ron") }) @@ -181,8 +177,8 @@ test_that("default title is the empty string", { addTestAccount("ron") local_mocked_bindings(applications = function(...) data.frame()) - app_dir <- withr::local_tempdir() - target <- deploymentTarget(app_dir) + dir <- local_temp_app() + target <- deploymentTarget(dir) expect_equal(target$appTitle, "") }) @@ -200,8 +196,8 @@ test_that("can find existing application on server & use it", { shouldUpdateApp = function(...) TRUE ) - app_dir <- withr::local_tempdir() - target <- deploymentTarget(app_dir, appName = "my_app") + dir <- local_temp_app() + target <- deploymentTarget(dir, appName = "my_app") expect_equal(target$appId, 123) }) @@ -219,8 +215,8 @@ test_that("can find existing application on server & not use it", { shouldUpdateApp = function(...) FALSE ) - app_dir <- withr::local_tempdir() - target <- deploymentTarget(app_dir, appName = "my_app") + dir <- local_temp_app() + target <- deploymentTarget(dir, appName = "my_app") expect_equal(target$appName, "my_app-1") expect_equal(target$appId, NULL) }) diff --git a/tests/testthat/test-deployments-find.R b/tests/testthat/test-deployments-find.R index c9452fc08..26519f01d 100644 --- a/tests/testthat/test-deployments-find.R +++ b/tests/testthat/test-deployments-find.R @@ -1,27 +1,27 @@ test_that("errors if no deployments", { - app <- local_temp_app() - expect_snapshot(findDeployment(app), error = TRUE) + dir <- local_temp_app() + expect_snapshot(findDeployment(dir), error = TRUE) }) test_that("finds single deployment", { - app <- local_temp_app() + dir <- local_temp_app() addTestServer() addTestAccount() - addTestDeployment(app) + addTestDeployment(dir) - dep <- findDeployment(app) + dep <- findDeployment(dir) expect_equal(dep$name, "test") }) test_that("disambiguates multiple deployments", { - app <- local_temp_app() + dir <- local_temp_app() addTestServer() addTestAccount() - addTestDeployment(app, "test1") - addTestDeployment(app, "test2") - expect_snapshot(findDeployment(app), error = TRUE) + addTestDeployment(dir, "test1") + addTestDeployment(dir, "test2") + expect_snapshot(findDeployment(dir), error = TRUE) simulate_user_input(2) - expect_snapshot(dep <- findDeployment(app)) + expect_snapshot(dep <- findDeployment(dir)) expect_equal(dep$name, "test2") }) diff --git a/tests/testthat/test-deployments.R b/tests/testthat/test-deployments.R index 439b70ec1..dfd96a372 100644 --- a/tests/testthat/test-deployments.R +++ b/tests/testthat/test-deployments.R @@ -89,37 +89,37 @@ test_that("can read/write missing version", { }) test_that("can read/write env vars", { - app <- local_temp_app() - addTestDeployment(app, "test1", envVars = c("TEST1", "TEST2")) - addTestDeployment(app, "test2") + dir <- local_temp_app() + addTestDeployment(dir, "test1", envVars = c("TEST1", "TEST2")) + addTestDeployment(dir, "test2") - deps <- deployments(app, excludeOrphaned = FALSE) + deps <- deployments(dir, excludeOrphaned = FALSE) expect_equal(deps$envVars, list(c("TEST1", "TEST2"), character())) }) test_that("can read/write empty env vars", { # also tests we can read files written by previous versions of package - app <- local_temp_app() + dir <- local_temp_app() # With empty character vector - path <- addTestDeployment(app, "test1", envVars = character()) - deps <- deployments(app, excludeOrphaned = FALSE) + path <- addTestDeployment(dir, "test1", envVars = character()) + deps <- deployments(dir, excludeOrphaned = FALSE) expect_false("envVars" %in% rownames(read.dcf(path))) expect_equal(deps$envVars, list(character())) # Or with empty string - path <- addTestDeployment(app, "test1", envVars = "") - deps <- deployments(app, excludeOrphaned = FALSE) + path <- addTestDeployment(dir, "test1", envVars = "") + deps <- deployments(dir, excludeOrphaned = FALSE) expect_false("envVars" %in% rownames(read.dcf(path))) expect_equal(deps$envVars, list(character())) }) test_that("can read/write env vars", { - app <- local_temp_app() - addTestDeployment(app, "test1", envVars = c("TEST1", "TEST2")) - addTestDeployment(app, "test2") + dir <- local_temp_app() + addTestDeployment(dir, "test1", envVars = c("TEST1", "TEST2")) + addTestDeployment(dir, "test2") - deps <- deployments(app, excludeOrphaned = FALSE) + deps <- deployments(dir, excludeOrphaned = FALSE) expect_equal(deps$envVars, list(c("TEST1", "TEST2"), character())) })