test: cover Aprsme.Is TCP data buffering and deployment init

This commit is contained in:
Graham McIntire 2026-04-23 17:26:51 -05:00
parent 56bc152b49
commit fb2e997ca7
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59
2 changed files with 41 additions and 0 deletions

View file

@ -40,4 +40,11 @@ defmodule Aprsme.DeploymentNotifierTest do
assert_receive {:new_deployment, %{deployed_at: ^new_deploy}}, 500
end
end
describe "init/1" do
test "schedules a check and stores the current deployed_at in state" do
assert {:ok, %{deployed_at: %DateTime{}}} = DeploymentNotifier.init([])
# The 30s check is scheduled — we don't wait for it.
end
end
end

View file

@ -410,6 +410,40 @@ defmodule Aprsme.IsTest do
end
end
describe "handle_info({:tcp, socket, data}, state) buffer edge cases" do
test "routes a single newline-terminated line through dispatch" do
ensure_ets_table()
state = build_state()
raw_line = "N0CALL>APRS,WIDE1-1:>Hello\r\n"
capture_log(fn ->
{:noreply, new_state} = Aprsme.Is.handle_info({:tcp, :fake_socket, raw_line}, state)
assert new_state.buffer == ""
end)
end
test "keeps incomplete trailing data in buffer" do
ensure_ets_table()
state = build_state()
capture_log(fn ->
{:noreply, new_state} = Aprsme.Is.handle_info({:tcp, :fake_socket, "partial"}, state)
assert new_state.buffer == "partial"
end)
end
test "concatenates previous buffer + new data for a complete line" do
ensure_ets_table()
state = build_state(%{buffer: "prefix"})
capture_log(fn ->
{:noreply, new_state} = Aprsme.Is.handle_info({:tcp, :fake_socket, "suffix\n"}, state)
assert new_state.buffer == ""
end)
end
end
describe "terminate/2" do
test "terminates cleanly with nil socket" do
state = build_state(%{socket: nil})