test: add coverage for MikroTik wrong unit type override
Adds test case for the real-world scenario where MikroTik devices report incorrect mtxrGaugeUnit values (e.g., reporting unit type 1 for celsius/temperature when the sensor is actually a voltage sensor). This test verifies that the name-based override logic in maybe_override_sensor_type/2 correctly handles this case: - Sensor name: "psu1-voltage" or "psu2-voltage" - Reported unit type: 1 (celsius/temperature) - Expected result: voltage sensor with divisor 10 The override code was added in commitf402dcb(Jan 22, 2026) and works correctly for new discoveries. Existing sensors created before this date need the migration from commit68a4ebfto fix their values. Related: 20260125182836_fix_misclassified_mikrotik_voltage_sensors.exs 🤖 Generated with Claude Code Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
68a4ebf601
commit
9c2efec473
1 changed files with 43 additions and 0 deletions
|
|
@ -343,5 +343,48 @@ defmodule Towerops.Snmp.Profiles.Vendors.RouterosTest do
|
|||
assert voltage_sensor.sensor_divisor == 10
|
||||
assert voltage_sensor.last_value == 12.0
|
||||
end
|
||||
|
||||
test "overrides sensor type when device reports wrong unit type" do
|
||||
expect(SnmpMock, :walk, fn _, @wl_ap_table, _ -> {:ok, []} end)
|
||||
expect(SnmpMock, :walk, fn _, @wl_stat_table, _ -> {:ok, []} end)
|
||||
expect(SnmpMock, :walk, fn _, @wl_60g_table, _ -> {:ok, []} end)
|
||||
expect(SnmpMock, :walk, fn _, @lte_modem_table, _ -> {:ok, []} end)
|
||||
|
||||
# Device incorrectly reports unit type 1 (celsius/temperature) for voltage sensor
|
||||
# This is the real-world bug case: sensor named "psu2-voltage" with unit type 1
|
||||
expect(SnmpMock, :walk, fn _, @gauge_table, _ ->
|
||||
{:ok,
|
||||
[
|
||||
# PSU voltage sensor incorrectly reported as temperature (unit type 1)
|
||||
%{oid: "#{@gauge_table}.2.7201", value: "psu1-voltage"},
|
||||
%{oid: "#{@gauge_table}.3.7201", value: 469},
|
||||
%{oid: "#{@gauge_table}.4.7201", value: 1},
|
||||
# Another voltage sensor with wrong unit type
|
||||
%{oid: "#{@gauge_table}.2.7202", value: "psu2-voltage"},
|
||||
%{oid: "#{@gauge_table}.3.7202", value: 469},
|
||||
%{oid: "#{@gauge_table}.4.7202", value: 1}
|
||||
]}
|
||||
end)
|
||||
|
||||
expect(SnmpMock, :walk, fn _, @optical_table, _ -> {:ok, []} end)
|
||||
expect(SnmpMock, :get, 2, fn _, _oid, _ -> {:error, :timeout} end)
|
||||
|
||||
sensors = Routeros.discover_wireless_sensors(@client_opts)
|
||||
|
||||
# Verify both sensors are correctly overridden to voltage with divisor 10
|
||||
psu1_sensor = Enum.find(sensors, &(&1.sensor_descr == "psu1-voltage"))
|
||||
assert psu1_sensor
|
||||
assert psu1_sensor.sensor_type == "voltage"
|
||||
assert psu1_sensor.sensor_unit == "V"
|
||||
assert psu1_sensor.sensor_divisor == 10
|
||||
assert psu1_sensor.last_value == 46.9
|
||||
|
||||
psu2_sensor = Enum.find(sensors, &(&1.sensor_descr == "psu2-voltage"))
|
||||
assert psu2_sensor
|
||||
assert psu2_sensor.sensor_type == "voltage"
|
||||
assert psu2_sensor.sensor_unit == "V"
|
||||
assert psu2_sensor.sensor_divisor == 10
|
||||
assert psu2_sensor.last_value == 46.9
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue