test: cover Aprsme.Is TCP data buffering and deployment init
This commit is contained in:
parent
56bc152b49
commit
fb2e997ca7
2 changed files with 41 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue