defmodule Towerops.Test.StubTerrain do @moduledoc """ In-memory stand-in for `Towerops.Lidar` used by coverage worker tests. Tests configure `:towerops, :coverage_terrain_module` to this module and put a precomputed grid into the process dictionary; the worker's `get_elevation_grid/2` call returns that grid verbatim. Returning the grid via the process dictionary means each test owns its own terrain without setting up a global agent. """ @doc "Sets the grid that subsequent calls will return." @spec put_grid(map() | {:error, term()}) :: :ok def put_grid(result) do Process.put(__MODULE__, result) :ok end @doc "Mirrors the relevant subset of `Towerops.Lidar.get_elevation_grid/2`." @spec get_elevation_grid(tuple(), number()) :: {:ok, map()} | {:error, term()} def get_elevation_grid(_bbox, _cell_size_deg) do case Process.get(__MODULE__) do nil -> {:error, :no_stub_grid_configured} {:error, _} = err -> err grid when is_map(grid) -> {:ok, grid} end end end