From da080ed55d74d50c0e416472112c26423f71dc8c Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 23 Apr 2026 17:31:47 -0500 Subject: [PATCH] test: add RegexCache bulk pattern test and PageController uptime format --- test/aprsme/regex_cache_test.exs | 14 ++++++++++++++ .../controllers/page_controller_test.exs | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/test/aprsme/regex_cache_test.exs b/test/aprsme/regex_cache_test.exs index b736e3a..42da87d 100644 --- a/test/aprsme/regex_cache_test.exs +++ b/test/aprsme/regex_cache_test.exs @@ -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 diff --git a/test/aprsme_web/controllers/page_controller_test.exs b/test/aprsme_web/controllers/page_controller_test.exs index 12c63f0..eba7b74 100644 --- a/test/aprsme_web/controllers/page_controller_test.exs +++ b/test/aprsme_web/controllers/page_controller_test.exs @@ -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