defmodule Microwaveprop.Weather.NexradCacheTest do use ExUnit.Case, async: false alias Microwaveprop.Weather.NexradCache setup do NexradCache.clear() :ok end describe "fetch/1" do test "returns :miss when nothing is cached" do assert NexradCache.fetch(~U[2026-04-12 12:00:00Z]) == :miss end test "returns cached pixels + width after put" do NexradCache.put(~U[2026-04-12 12:00:00Z], <<1, 2, 3, 4>>, 2) assert {:ok, <<1, 2, 3, 4>>, 2} = NexradCache.fetch(~U[2026-04-12 12:00:00Z]) end test "isolates entries by timestamp" do NexradCache.put(~U[2026-04-12 12:00:00Z], <<1>>, 1) NexradCache.put(~U[2026-04-12 12:05:00Z], <<2>>, 1) assert {:ok, <<1>>, 1} = NexradCache.fetch(~U[2026-04-12 12:00:00Z]) assert {:ok, <<2>>, 1} = NexradCache.fetch(~U[2026-04-12 12:05:00Z]) end end describe "prune_older_than/1" do test "removes entries with a timestamp strictly before the cutoff" do NexradCache.put(~U[2026-04-12 11:50:00Z], <<1>>, 1) NexradCache.put(~U[2026-04-12 12:00:00Z], <<2>>, 1) NexradCache.prune_older_than(~U[2026-04-12 11:55:00Z]) assert NexradCache.fetch(~U[2026-04-12 11:50:00Z]) == :miss assert {:ok, <<2>>, 1} = NexradCache.fetch(~U[2026-04-12 12:00:00Z]) end test "keeps entries equal to the cutoff" do NexradCache.put(~U[2026-04-12 12:00:00Z], <<1>>, 1) NexradCache.prune_older_than(~U[2026-04-12 12:00:00Z]) assert {:ok, <<1>>, 1} = NexradCache.fetch(~U[2026-04-12 12:00:00Z]) end end end