Changes under lib/ (source):
- iemre_fetch_worker: replace `if transient_failure?/1` boolean predicate
+ `if/else` with a classifier that pattern-matches the error reason
directly, returning `:transient | :permanent`, and dispatch via
`case`. Three-clause head is clearer than the boolean predicate.
- scores_file.extract_points and nexrad_client.extract_box: force `//1`
step on the row/col comprehensions so an image box whose centre
lands outside the raster collapses to an empty iteration instead
of firing Elixir 1.19's ambiguous-range warning. Adds a regression
test for the right-edge box.
Test coverage added:
- Feature wrappers in Backtest.Features (theta_e_jump, shear_at_top,
duct_thickness, best_duct_freq, duct_usable_for_band,
distance_to_front / parallel_to_front stubs, all_features/0).
- NotifyListener handle_info tolerance for malformed payloads +
unknown messages, plus the PubSub broadcast side effect.
- Viewshed.effective_reach_km across every verdict / diffraction
tier / ducting-score tier combination.
- SnmpClient parse_af60_output unit conversions + unknown-column
handling; parse_snmpget_output OID normalisation and junk-line
tolerance.
- HrrrNativeClient native_level_count, native_variables,
native_messages shape, duct_messages / duct_byte_ranges.
- Changeset coverage for GeomagneticObservation, SolarFluxObservation,
SolarXrayObservation, Ionosphere.Observation, HrrrClimatology, and
Metar5minObservation — lifted each from ~50% / 0% to 100%.
- Property tests: GefsClient.dewpoint_from_rh invariants (Td ≤ T,
monotonic in RH, finite across the operating envelope) + idempotent
nearest_run. NexradClient.pixel_to_dbz monotonicity + bounded
output; latlon_to_pixel round-trip for every grid cell.
Also cleared several unrelated compiler/linter warnings:
- Three private test helpers (create_contact, insert_contact,
current_hour) had `\\ %{}` / `\\ 0` defaults that no caller used.
- profiles_file_test bound `dir` in a pattern match without using it.
Suite: 2,359 tests + 146 properties pass (was 2,300 / 139); coverage
70.38% → 70.89%; credo strict clean.
174 lines
6.2 KiB
Elixir
174 lines
6.2 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
|
|
end
|