tests/testthat/setup-susoflows.R

library("vcr") # *Required* as vcr is set up on loading

# locate vcr fixtures directory 
vcr_dir <- vcr::vcr_test_path("fixtures")

# if credentials are non-empty, replace with fake values to spoof functions for testing
if (!nzchar(Sys.getenv("SUSO_SERVER")) & !nzchar(Sys.getenv("SUSO_USER")) & !nzchar(Sys.getenv("SUSO_PASSWORD"))) {
  if (dir.exists(vcr_dir)) {
    Sys.setenv("SUSO_SERVER" = "<<fake_server>>")
    Sys.setenv("SUSO_USER" = "<<fake_user>>")
    Sys.setenv("SUSO_PASSWORD" = "<<fake_password>>")
  } else {
    stop("Cannot run tests. No fixtures folder found for `vcr`", call. = FALSE)
  }

}

# configure vcr, redacting secrets (i.e., server, user, and password)
invisible(vcr::vcr_configure(
  dir = vcr::vcr_test_path("fixtures"),
  filter_sensitive_data = list(
    "<<<fake_server>>>" = Sys.getenv('SUSO_SERVER'),
    "<<<fake_user>>>" = Sys.getenv('SUSO_USER'),
    "<<<fake_password>>>" = Sys.getenv('SUSO_PASSWORD')
  ), 
  write_disk_path = vcr_dir
))

# check that cassette names are unique
vcr::check_cassette_names()
arthur-shaw/susoflows documentation built on April 14, 2025, 4:02 p.m.