defmodule Microwaveprop.Canopy.BulkFetchTest do use ExUnit.Case, async: false import ExUnit.CaptureLog alias Microwaveprop.Canopy.BulkFetch setup do cache_dir = Path.join(System.tmp_dir!(), "canopy_test_#{System.unique_integer([:positive])}") staging_dir = Path.join(System.tmp_dir!(), "canopy_staging_test_#{System.unique_integer([:positive])}") on_exit(fn -> File.rm_rf!(cache_dir) File.rm_rf!(staging_dir) end) %{cache_dir: cache_dir, staging_dir: staging_dir} end describe "run/4" do test "computes degree tiles and reports zero counters when COG fetch fails", %{ cache_dir: cache_dir, staging_dir: staging_dir } do # The default ETH cog URL won't be reachable from the test sandbox, # so the per-COG ensure step fails and increments the failed counter # for every degree tile. We just verify run/4 returns a counter map # with the expected keys and never crashes. capture_log(fn -> result = BulkFetch.run(32.5, -97.0, 1, cache_dir: cache_dir, staging_dir: staging_dir) send(self(), result) end) assert_received %{ downloaded: _, sliced: _, cached: _, failed: _, cache_dir: ^cache_dir } end test "creates the cache + staging directories", %{cache_dir: cache_dir, staging_dir: staging_dir} do capture_log(fn -> _ = BulkFetch.run(32.5, -97.0, 1, cache_dir: cache_dir, staging_dir: staging_dir) end) assert File.dir?(cache_dir) assert File.dir?(staging_dir) end end end