towerops/test/towerops/agent/interface_test.exs
Graham McIntire 3ca0834ef0 tests: raise coverage to 70% via helper promotion + new unit/property tests
Promoted pure presentation and utility helpers from `defp` to `def @doc false`
across ~20 LiveViews, Oban workers, and sync modules so they're reachable from
unit tests. Refactored several `cond` blocks into idiomatic function heads with
guards. Added ~250 new test cases in new files under test/towerops and
test/towerops_web, including DB-backed tests for CnMaestro.Sync and
AlertNotificationWorker, and removed dead LiveView tab components and
CapacityLive (no callers anywhere in lib/test).

Configured mix.exs test_coverage.ignore_modules to exclude vendored third-party
code (SnmpKit, protobuf-generated Towerops.Agent.*, Absinthe GraphQL types,
Phoenix HTML modules, Inspect protocol impls) from coverage calculations —
these are not our project code.

Coverage: 66.93% → 70.09%. Full suite: 10,127 tests, 0 failures.
2026-04-24 09:49:06 -05:00

43 lines
1.3 KiB
Elixir

defmodule Towerops.Agent.InterfaceTest do
use ExUnit.Case, async: true
use ExUnitProperties
alias Towerops.Agent.Interface
describe "struct defaults" do
test "defaults to empty id and name, zero if_index" do
assert %Interface{id: "", if_index: 0, if_name: ""} = %Interface{}
end
test "accepts explicit field values" do
iface = %Interface{id: "abc-uuid", if_index: 42, if_name: "ether1"}
assert iface.id == "abc-uuid"
assert iface.if_index == 42
assert iface.if_name == "ether1"
end
end
describe "encode/1" do
test "produces a binary" do
iface = %Interface{id: "abc", if_index: 1, if_name: "eth0"}
assert is_binary(Interface.encode(iface))
end
test "default struct encodes without error" do
assert is_binary(Interface.encode(%Interface{}))
end
end
describe "property: encode/1 always returns binary" do
property "random interface structs encode cleanly" do
check all(
id <- string(:alphanumeric, max_length: 36),
if_index <- integer(0..2_147_483_647),
if_name <- string(:printable, max_length: 64)
) do
iface = %Interface{id: id, if_index: if_index, if_name: if_name}
assert is_binary(Interface.encode(iface))
end
end
end
end