# tests/testthat/test-manifest.R # # Tests for the guards on .fetch_or_cache_manifest() and cog_open() that # protect users from silent failures when USCOGDATA_URL is misconfigured # or returns non-JSON content. test_that("cog_open aborts with actionable error when URL is the placeholder default", { uscogdata:::cog_close() on.exit(uscogdata:::cog_close(), add = TRUE) placeholder <- "https://cloud.civilytics.org/s/REPLACE_WITH_SHARE_TOKEN/download/" withr::with_envvar(c(USCOGDATA_URL = placeholder), { expect_error( uscogdata:::cog_open(), class = "uscogdata_url_not_configured" ) }) }) test_that("placeholder guard fires for any URL containing the sentinel token", { uscogdata:::cog_close() on.exit(uscogdata:::cog_close(), add = TRUE) # Sentinel detection should be substring-based — covers any host that still # has REPLACE_WITH_SHARE_TOKEN baked in (default or partial user edit). withr::with_envvar(c(USCOGDATA_URL = "https://other.example/s/REPLACE_WITH_SHARE_TOKEN/x/"), { expect_error( uscogdata:::cog_open(), class = "uscogdata_url_not_configured" ) }) }) test_that("placeholder guard error names both env var and option as remediation", { uscogdata:::cog_close() on.exit(uscogdata:::cog_close(), add = TRUE) placeholder <- "https://cloud.civilytics.org/s/REPLACE_WITH_SHARE_TOKEN/download/" withr::with_envvar(c(USCOGDATA_URL = placeholder), { msg <- tryCatch(uscogdata:::cog_open(), error = conditionMessage) expect_match(msg, "USCOGDATA_URL", fixed = TRUE) expect_match(msg, "uscogdata.url", fixed = TRUE) }) }) test_that("local manifest containing HTML produces uscogdata_invalid_manifest, not raw parse error", { uscogdata:::cog_close() on.exit(uscogdata:::cog_close(), add = TRUE) tmp <- withr::local_tempdir() writeLines( c("", "