init
This commit is contained in:
commit
116abafc09
58 changed files with 5749 additions and 0 deletions
65
tests/testthat/test-sample-tiles.R
Normal file
65
tests/testthat/test-sample-tiles.R
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
test_that("protomaps_sample_tiles validates region", {
|
||||
expect_error(
|
||||
protomaps_sample_tiles(region = "invalid"),
|
||||
"sf-bay"
|
||||
)
|
||||
})
|
||||
|
||||
test_that("protomaps_sample_tiles uses cached file", {
|
||||
temp_dir <- tempdir()
|
||||
temp_file <- file.path(temp_dir, "protomapr-sample-sf-bay.pmtiles")
|
||||
|
||||
# Create fake cached file
|
||||
writeLines("test", temp_file)
|
||||
|
||||
expect_message(
|
||||
result <- protomaps_sample_tiles(cache_dir = temp_dir),
|
||||
"Using cached"
|
||||
)
|
||||
expect_equal(result, temp_file)
|
||||
|
||||
# Cleanup
|
||||
unlink(temp_file)
|
||||
})
|
||||
|
||||
test_that("protomaps_clear_cache handles missing directory", {
|
||||
expect_message(
|
||||
protomaps_clear_cache(cache_dir = "/nonexistent/path/12345"),
|
||||
"does not exist"
|
||||
)
|
||||
})
|
||||
|
||||
test_that("protomaps_clear_cache handles empty cache", {
|
||||
temp_dir <- tempdir()
|
||||
cache_subdir <- file.path(temp_dir, "protomapr_test_cache")
|
||||
dir.create(cache_subdir, showWarnings = FALSE)
|
||||
|
||||
expect_message(
|
||||
protomaps_clear_cache(cache_dir = cache_subdir),
|
||||
"No cached tiles"
|
||||
)
|
||||
|
||||
unlink(cache_subdir, recursive = TRUE)
|
||||
})
|
||||
|
||||
test_that("protomaps_clear_cache removes pmtiles files", {
|
||||
temp_dir <- tempdir()
|
||||
cache_subdir <- file.path(temp_dir, "protomapr_test_cache2")
|
||||
dir.create(cache_subdir, showWarnings = FALSE)
|
||||
|
||||
# Create fake cached files
|
||||
writeLines("test1", file.path(cache_subdir, "test1.pmtiles"))
|
||||
writeLines("test2", file.path(cache_subdir, "test2.pmtiles"))
|
||||
writeLines("keep", file.path(cache_subdir, "other.txt"))
|
||||
|
||||
result <- expect_message(
|
||||
protomaps_clear_cache(cache_dir = cache_subdir),
|
||||
"Removed 2"
|
||||
)
|
||||
|
||||
# Check pmtiles removed but other file kept
|
||||
expect_false(file.exists(file.path(cache_subdir, "test1.pmtiles")))
|
||||
expect_true(file.exists(file.path(cache_subdir, "other.txt")))
|
||||
|
||||
unlink(cache_subdir, recursive = TRUE)
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue