Adds ~600 new test cases (2013 → 2613 tests; 170 properties; 0
failures) across 12 new test files plus expansions of eight existing
files. Big lifts per module:
ContactLive.Mechanism 33 → 100%
MetricsPlug 54 → ~100%
Microwaveprop.Release 15.8 → 70%+
Telemetry 38 → 76%
HrrrNativeGridWorker 27.7 → 76%
ContactLive.Show 34 → 48% (handler + render branches)
Admin.ContactEditLive 49.7 → 70%+
GefsFetchWorker 35.8 → ~55%
IonosphereFetchWorker 56.3 → 75%
PathLive 58.9 → 67%
WeatherMapLive 66.9 → 80.2%
RoverLive 0 → 70.3%
ContactMapLive 59.2 → 89.8%
ContactMapController 0 → 100%
Mix tasks (Rust.Golden, Notebook, Backtest, HrrrBackfill,
HrrrClimatology, HrrrNativeBackfill, NexradBackfill,
RadarBackfill, ImportContestLogs, PropagationGrid,
ResetEnrichment, Hrrr.PurgeGridPoints) 0 → ~60-100%
Two incidental fixes made while adding tests:
- ContactLive.Show.handle_event("toggle_flag", ...) was passing
socket.assigns.current_scope to admin?/1 instead of socket.assigns,
so admins never matched the pattern and every toggle ran the
"Admins only." flash branch. Flag now toggles for admins again.
- Commercial.PollWorker.fetch_weather/1 promoted from private to
@doc'd public so the IEM-fetch + ASOS-upsert path can be tested
directly without driving perform/1 through live SNMP (which was
timing out for ~50 s per test in the earlier attempt).
Stable property-test additions cover the dewpoint-from-RH monotonicity,
nearest_run/1 idempotence, and the ionosphere station envelope.
184 lines
6.6 KiB
Elixir
184 lines
6.6 KiB
Elixir
defmodule Microwaveprop.Commercial.SnmpClientTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
alias Microwaveprop.Commercial.SnmpClient
|
|
|
|
@af11x_output """
|
|
iso.3.6.1.4.1.41112.1.3.2.1.11.1 = INTEGER: -55
|
|
iso.3.6.1.4.1.41112.1.3.2.1.14.1 = INTEGER: -56
|
|
iso.3.6.1.4.1.41112.1.3.1.1.9.1 = INTEGER: 20
|
|
iso.3.6.1.4.1.41112.1.3.2.1.2.1 = INTEGER: 6
|
|
iso.3.6.1.4.1.41112.1.3.2.1.18.1 = INTEGER: 6
|
|
iso.3.6.1.4.1.41112.1.3.2.1.5.1 = INTEGER: 450
|
|
iso.3.6.1.4.1.41112.1.3.2.1.6.1 = INTEGER: 450
|
|
iso.3.6.1.4.1.41112.1.3.2.1.17.1 = INTEGER: 20
|
|
iso.3.6.1.4.1.41112.1.3.2.1.19.1 = INTEGER: -54
|
|
iso.3.6.1.4.1.41112.1.3.2.1.22.1 = INTEGER: -57
|
|
iso.3.6.1.4.1.41112.1.3.2.1.26.1 = INTEGER: 1
|
|
iso.3.6.1.4.1.41112.1.3.2.1.44.1 = INTEGER: 86400
|
|
iso.3.6.1.4.1.41112.1.3.2.1.8.1 = INTEGER: 45
|
|
iso.3.6.1.4.1.41112.1.3.2.1.10.1 = INTEGER: 47
|
|
iso.3.6.1.4.1.41112.1.3.1.1.5.1 = INTEGER: 11245
|
|
iso.3.6.1.4.1.41112.1.3.1.1.6.1 = INTEGER: 10720
|
|
iso.3.6.1.4.1.41112.1.3.2.1.4.1 = INTEGER: 7200
|
|
"""
|
|
|
|
describe "parse_snmpget_output/2" do
|
|
test "parses AF11X snmpget output into signal map" do
|
|
result = SnmpClient.parse_snmpget_output(@af11x_output, :af11x)
|
|
|
|
assert result.rx_power_0 == -55
|
|
assert result.rx_power_1 == -56
|
|
assert result.tx_power == 20
|
|
assert result.cur_tx_mod_rate == 6
|
|
assert result.remote_tx_mod_rate == 6
|
|
assert result.rx_capacity == 450
|
|
assert result.tx_capacity == 450
|
|
assert result.remote_tx_power == 20
|
|
assert result.remote_rx_power_0 == -54
|
|
assert result.remote_rx_power_1 == -57
|
|
assert result.link_state == 1
|
|
assert result.link_uptime == 86_400
|
|
assert result.radio_temp_0_c == 45
|
|
assert result.radio_temp_1_c == 47
|
|
assert result.tx_freq_mhz == 11_245
|
|
assert result.rx_freq_mhz == 10_720
|
|
assert result.link_distance_m == 7200
|
|
end
|
|
|
|
test "returns empty map for empty output" do
|
|
assert SnmpClient.parse_snmpget_output("", :af11x) == %{}
|
|
end
|
|
|
|
test "skips lines with No Such Instance" do
|
|
output = """
|
|
iso.3.6.1.4.1.41112.1.3.2.1.11.1 = INTEGER: -55
|
|
iso.3.6.1.4.1.41112.1.3.2.1.14.1 = No Such Instance currently exists at this OID
|
|
"""
|
|
|
|
result = SnmpClient.parse_snmpget_output(output, :af11x)
|
|
assert result.rx_power_0 == -55
|
|
refute Map.has_key?(result, :rx_power_1)
|
|
end
|
|
end
|
|
|
|
@af60_static_output """
|
|
iso.3.6.1.4.1.41112.1.11.1.2.5.1 = INTEGER: 52
|
|
iso.3.6.1.4.1.41112.1.11.1.2.6.1 = INTEGER: 1
|
|
iso.3.6.1.4.1.41112.1.11.1.1.2.1 = INTEGER: 60480
|
|
"""
|
|
|
|
@af60_station_output """
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.3.170.211.109.42.26.137 = INTEGER: -58
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.4.170.211.109.42.26.137 = INTEGER: 18
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.5.170.211.109.42.26.137 = INTEGER: 9
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.6.170.211.109.42.26.137 = INTEGER: 8
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.7.170.211.109.42.26.137 = INTEGER: 900000
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.8.170.211.109.42.26.137 = INTEGER: 850000
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.15.170.211.109.42.26.137 = INTEGER: 2800
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.17.170.211.109.42.26.137 = INTEGER: 8640000
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.18.170.211.109.42.26.137 = INTEGER: -57
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.19.170.211.109.42.26.137 = INTEGER: 19
|
|
"""
|
|
|
|
describe "parse_af60_output/2" do
|
|
test "parses AF60 static + station output" do
|
|
result = SnmpClient.parse_af60_output(@af60_static_output, @af60_station_output)
|
|
|
|
assert result.radio_temp_0_c == 52
|
|
assert result.link_state == 1
|
|
assert result.tx_freq_mhz == 60_480
|
|
assert result.rx_power_0 == -58
|
|
assert result.tx_power == 18
|
|
assert result.cur_tx_mod_rate == 9
|
|
assert result.remote_tx_mod_rate == 8
|
|
assert result.tx_capacity == 900
|
|
assert result.rx_capacity == 850
|
|
assert result.link_distance_m == 2800
|
|
assert result.link_uptime == 86_400
|
|
assert result.remote_rx_power_0 == -57
|
|
assert result.remote_tx_power == 19
|
|
end
|
|
|
|
test "returns empty map for empty output" do
|
|
assert SnmpClient.parse_af60_output("", "") == %{}
|
|
end
|
|
|
|
test "converts tx/rx_capacity from kbps to mbps (integer division)" do
|
|
# 450_500 kbps should round down to 450 mbps.
|
|
station = """
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.7.170.211.109.42.26.137 = INTEGER: 450500
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.8.170.211.109.42.26.137 = INTEGER: 999
|
|
"""
|
|
|
|
result = SnmpClient.parse_af60_output("", station)
|
|
assert result.tx_capacity == 450
|
|
# 999 kbps → 0 mbps (floor division)
|
|
assert result.rx_capacity == 0
|
|
end
|
|
|
|
test "converts link_uptime from centiseconds to seconds" do
|
|
station = """
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.17.170.211.109.42.26.137 = INTEGER: 12345
|
|
"""
|
|
|
|
result = SnmpClient.parse_af60_output("", station)
|
|
assert result.link_uptime == 123
|
|
end
|
|
|
|
test "ignores unknown OID columns in the station output" do
|
|
station = """
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.3.170.211.109.42.26.137 = INTEGER: -42
|
|
iso.3.6.1.4.1.41112.1.11.1.3.1.99.170.211.109.42.26.137 = INTEGER: 7777
|
|
"""
|
|
|
|
result = SnmpClient.parse_af60_output("", station)
|
|
assert result.rx_power_0 == -42
|
|
refute Map.has_key?(result, :col_99)
|
|
assert map_size(result) == 1
|
|
end
|
|
end
|
|
|
|
describe "parse_snmpget_output/2 OID normalisation" do
|
|
test "accepts SNMPv2-SMI::enterprises.* OID prefix" do
|
|
output = """
|
|
SNMPv2-SMI::enterprises.41112.1.3.2.1.11.1 = INTEGER: -61
|
|
"""
|
|
|
|
result = SnmpClient.parse_snmpget_output(output, :af11x)
|
|
assert result.rx_power_0 == -61
|
|
end
|
|
|
|
test "skips lines that don't parse as OID = value" do
|
|
output = """
|
|
iso.3.6.1.4.1.41112.1.3.2.1.11.1 = INTEGER: -55
|
|
garbage line
|
|
"""
|
|
|
|
result = SnmpClient.parse_snmpget_output(output, :af11x)
|
|
assert result.rx_power_0 == -55
|
|
assert map_size(result) == 1
|
|
end
|
|
|
|
test "skips values that aren't parseable as integers" do
|
|
output = """
|
|
iso.3.6.1.4.1.41112.1.3.2.1.11.1 = STRING: "not-a-number"
|
|
iso.3.6.1.4.1.41112.1.3.2.1.14.1 = INTEGER: -56
|
|
"""
|
|
|
|
result = SnmpClient.parse_snmpget_output(output, :af11x)
|
|
refute Map.has_key?(result, :rx_power_0)
|
|
assert result.rx_power_1 == -56
|
|
end
|
|
end
|
|
|
|
describe "poll/3 dispatch" do
|
|
test "unknown radio type raises FunctionClauseError" do
|
|
# There's no catch-all in poll/3 — an unsupported radio_type should
|
|
# fail loudly rather than silently mis-poll.
|
|
assert_raise FunctionClauseError, fn ->
|
|
SnmpClient.poll("10.0.0.1", "public", "unknown-model")
|
|
end
|
|
end
|
|
end
|
|
end
|