60 lines
2 KiB
Elixir
60 lines
2 KiB
Elixir
defmodule SnmpKit.SnmpMgr.MIB.ParserTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
alias SnmpKit.SnmpLib.MIB.Parser
|
|
|
|
test "parser correctly extracts ubntAFLTU from UBNT-MIB" do
|
|
mib_path = Path.join(:code.priv_dir(:towerops), "mibs/ubnt/UBNT-MIB")
|
|
{:ok, content} = File.read(mib_path)
|
|
{:ok, parsed} = Parser.parse(content)
|
|
|
|
definitions = Map.get(parsed, :definitions, [])
|
|
|
|
# Find ubntAFLTU
|
|
ubnt_afltu = Enum.find(definitions, &(Map.get(&1, :name) == "ubntAFLTU"))
|
|
|
|
assert ubnt_afltu != nil, "ubntAFLTU should be in parsed definitions"
|
|
|
|
# Check its structure
|
|
assert Map.get(ubnt_afltu, :name) == "ubntAFLTU"
|
|
assert Map.get(ubnt_afltu, :parent) == "ubntMIB"
|
|
assert Map.get(ubnt_afltu, :__type__) == :object_identifier
|
|
|
|
# The sub_index should be 10
|
|
sub_index = Map.get(ubnt_afltu, :sub_index)
|
|
refute is_nil(sub_index), "sub_index should not be nil for ubntAFLTU"
|
|
|
|
# Decode the sub_index
|
|
decoded_index =
|
|
case String.to_charlist(sub_index) do
|
|
[code_point | _] -> code_point
|
|
[] -> :binary.decode_unsigned(sub_index)
|
|
end
|
|
|
|
assert decoded_index == 10, "Expected sub_index to decode to 10, got #{decoded_index}"
|
|
end
|
|
|
|
test "parser extracts all OBJECT-IDENTIFIER definitions with sub_index" do
|
|
mib_path = Path.join(:code.priv_dir(:towerops), "mibs/ubnt/UBNT-MIB")
|
|
{:ok, content} = File.read(mib_path)
|
|
{:ok, parsed} = Parser.parse(content)
|
|
|
|
definitions = Map.get(parsed, :definitions, [])
|
|
|
|
object_identifiers =
|
|
definitions
|
|
|> Enum.filter(&(Map.get(&1, :__type__) == :object_identifier))
|
|
|> Enum.map(fn def ->
|
|
name = Map.get(def, :name)
|
|
parent = Map.get(def, :parent)
|
|
sub_index = Map.get(def, :sub_index)
|
|
{name, parent, sub_index}
|
|
end)
|
|
|
|
# Check specific entries
|
|
assert Enum.any?(object_identifiers, fn {name, parent, sub_index} ->
|
|
name == "ubntAFLTU" and parent == "ubntMIB" and sub_index != nil
|
|
end),
|
|
"ubntAFLTU should have parent ubntMIB and non-nil sub_index"
|
|
end
|
|
end
|