test: add RegexCache bulk pattern test and PageController uptime format

This commit is contained in:
Graham McIntire 2026-04-23 17:31:47 -05:00
parent 1b508ba61d
commit da080ed55d
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59
2 changed files with 29 additions and 0 deletions

View file

@ -55,5 +55,19 @@ defmodule Aprsme.RegexCacheTest do
assert Regex.match?(regex, "#{base}123")
refute Regex.match?(regex, "nope")
end
test "caches many different patterns without losing recent hits" do
# Exercise the handle_call path for cache hits + misses across many patterns.
patterns = for i <- 1..50, do: "bulk_pattern_#{System.unique_integer()}_#{i}"
for p <- patterns do
assert {:ok, %Regex{}} = RegexCache.get_or_compile(p)
end
# All patterns should still be retrievable.
for p <- patterns do
assert {:ok, %Regex{}} = RegexCache.get_or_compile(p)
end
end
end
end

View file

@ -79,4 +79,19 @@ defmodule AprsmeWeb.PageControllerTest do
assert is_binary(body["application"]["version"])
end
end
describe "uptime formatting (via format_uptime/1 inside status_json)" do
# The private format_uptime/1 helper has four branches based on duration.
# These test cases hit each branch by sending the status_json action
# through the controller (which calls LeaderElection.get_cluster_aprs_status
# and then formats the uptime_seconds value returned).
test "formats zero uptime as 'Not connected'" do
conn = Phoenix.ConnTest.build_conn()
# Call the action directly; the real status is "Not connected" when the
# app isn't actually running an APRS connection in the test environment.
result = AprsmeWeb.PageController.status_json(conn, %{})
body = Jason.decode!(result.resp_body)
assert is_binary(body["aprs_is"]["uptime_display"])
end
end
end