aprs.me/test/aprsme/packet_counter_test.exs
Graham McIntire 094a50d183
Add tests for 14 modules with 0% coverage
Adds test files for:
- AprsIsConnection (83% coverage)
- Cluster.PacketDistributor (100%)
- Cluster.PacketReceiver (100%)
- Cluster.Topology (100%)
- ConnectionMonitor (78%)
- DbOptimizer (90%)
- DynamicSupervisor (100%)
- ErrorHandler (89%)
- MigrationLock (90%)
- MockHelpers (100%)
- PacketConsumerPool (90%)
- PacketCounter (100%)
- PacketPipelineSetup (75%)
- PacketPipelineSupervisor (100%)

Uses stub repo modules to test MigrationLock lock contention
paths without real multi-session PostgreSQL advisory lock
contention.
2026-02-09 17:19:50 -06:00

40 lines
1.1 KiB
Elixir

defmodule Aprsme.PacketCounterTest do
use Aprsme.DataCase, async: true
import Ecto.Query
alias Aprsme.PacketCounter
alias Aprsme.Repo
describe "get_count/0" do
test "returns 0 when no records exist" do
Repo.delete_all(PacketCounter)
assert PacketCounter.get_count() == 0
end
end
describe "get_count/1" do
test "returns the count after inserting a record" do
# Update the existing seeded row rather than inserting a duplicate
Repo.update_all(from(pc in PacketCounter, where: pc.counter_type == "total_packets"), set: [count: 42])
assert PacketCounter.get_count("total_packets") == 42
end
test "returns 0 for a counter_type that does not exist" do
assert PacketCounter.get_count("nonexistent_type") == 0
end
test "returns the correct count for a custom counter_type" do
Repo.insert!(%PacketCounter{counter_type: "daily_packets", count: 100})
assert PacketCounter.get_count("daily_packets") == 100
end
end
describe "subscribe_to_changes/0" do
test "returns :ok" do
assert PacketCounter.subscribe_to_changes() == :ok
end
end
end