test: store_bad_packet error-shape branches

This commit is contained in:
Graham McIntire 2026-04-24 08:57:10 -05:00
parent 509b859b0d
commit 4ea38c0585
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -292,6 +292,40 @@ defmodule Aprsme.PacketsTest do
end
end
describe "store_bad_packet/2 error shape coverage" do
test "stores bad packet from string with struct error" do
# An exception struct — should hit the struct-type branch for error_type.
error = %ArgumentError{message: "bad arg"}
assert {:ok, bad_packet} = Packets.store_bad_packet("INVALID", error)
assert bad_packet.raw_packet == "INVALID"
assert bad_packet.error_type == "ArgumentError"
assert bad_packet.error_message =~ "bad arg"
end
test "stores bad packet from string with unstructured error" do
# An error that's neither a map nor a struct — falls to UnknownError.
assert {:ok, bad_packet} = Packets.store_bad_packet("INVALID", :some_atom)
assert bad_packet.error_type == "UnknownError"
assert bad_packet.error_message == ":some_atom"
end
test "stores bad packet from map with struct error" do
error = %RuntimeError{message: "boom"}
assert {:ok, bad_packet} =
Packets.store_bad_packet(%{raw_packet: "MAP-STRUCT"}, error)
assert bad_packet.raw_packet == "MAP-STRUCT"
assert bad_packet.error_type == "RuntimeError"
end
test "stores bad packet from map with unstructured error" do
assert {:ok, bad_packet} = Packets.store_bad_packet(%{raw_packet: "MAP-UNK"}, :unknown)
assert bad_packet.error_type == "UnknownError"
end
end
describe "store_packet/1 error paths" do
test "storage exception path stores a bad packet" do
# Send data that causes changeset insertion to fail at the DB level.