test: PacketConsumer item/object detection branches
This commit is contained in:
parent
4f41b4106c
commit
bd3f5c0434
1 changed files with 45 additions and 0 deletions
|
|
@ -40,6 +40,51 @@ defmodule Aprsme.PacketConsumerTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "item/object detection" do
|
||||||
|
test "detects object via info_field prefix ';'" do
|
||||||
|
events = [
|
||||||
|
%{
|
||||||
|
sender: "INFOBJ-1",
|
||||||
|
data_type: "position",
|
||||||
|
lat: 35.0,
|
||||||
|
lon: -75.0,
|
||||||
|
destination: "APRS",
|
||||||
|
path: "WIDE1-1",
|
||||||
|
information_field: ";MYOBJ *192200z3500.00N/07500.00W#Test",
|
||||||
|
raw_packet: "INFOBJ-1>APRS",
|
||||||
|
data: %{"information_field" => ";MYOBJ *192200z3500.00N/07500.00W#Test"}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
state = %{batch: [], batch_length: 0, batch_size: 1, batch_timeout: 1000, max_batch_size: 100, timer: nil}
|
||||||
|
{:noreply, [], new_state} = PacketConsumer.handle_events(events, nil, state)
|
||||||
|
Process.sleep(50)
|
||||||
|
|
||||||
|
assert new_state.batch == []
|
||||||
|
end
|
||||||
|
|
||||||
|
test "detects item via :itemname" do
|
||||||
|
events = [
|
||||||
|
%{
|
||||||
|
sender: "ITEMS-1",
|
||||||
|
data_type: "item",
|
||||||
|
lat: 35.0,
|
||||||
|
lon: -75.0,
|
||||||
|
destination: "APRS",
|
||||||
|
path: "WIDE1-1",
|
||||||
|
itemname: "MyCustomItem",
|
||||||
|
raw_packet: "ITEMS-1>APRS"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
state = %{batch: [], batch_length: 0, batch_size: 1, batch_timeout: 1000, max_batch_size: 100, timer: nil}
|
||||||
|
{:noreply, [], new_state} = PacketConsumer.handle_events(events, nil, state)
|
||||||
|
Process.sleep(50)
|
||||||
|
|
||||||
|
assert new_state.batch == []
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "handle_events/3 batch sizing" do
|
describe "handle_events/3 batch sizing" do
|
||||||
test "partial batch just accumulates and re-schedules" do
|
test "partial batch just accumulates and re-schedules" do
|
||||||
{:consumer, state, _} = PacketConsumer.init(subscribe_to: [])
|
{:consumer, state, _} = PacketConsumer.init(subscribe_to: [])
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue