diff --git a/test/snmpkit/snmp_lib/host_parser_test.exs b/test/snmpkit/snmp_lib/host_parser_test.exs index 9466b2a7..106a2c0a 100644 --- a/test/snmpkit/snmp_lib/host_parser_test.exs +++ b/test/snmpkit/snmp_lib/host_parser_test.exs @@ -322,9 +322,10 @@ defmodule SnmpKit.SnmpLib.HostParserTest do assert HostParser.valid?("::1") == true # "localhost" resolves to 127.0.0.1 assert HostParser.valid?("localhost") == true - # Unresolvable hostnames are invalid - assert HostParser.valid?("invalid") == false + # Invalid IP tuples are invalid assert HostParser.valid?({256, 0, 0, 0}) == false + # Malformed IP strings with dots are invalid + assert HostParser.valid?("999.999.999.999") == false end test "parse_ip function" do @@ -333,8 +334,8 @@ defmodule SnmpKit.SnmpLib.HostParserTest do assert {:ok, {192, 168, 1, 1}} = HostParser.parse_ip({192, 168, 1, 1}) # "localhost" resolves to an IP tuple assert {:ok, {127, 0, 0, 1}} = HostParser.parse_ip("localhost") - # Unresolvable hostnames return error - assert {:error, :hostname_resolution_failed} = HostParser.parse_ip("invalid") + # Malformed IP strings return error + assert {:error, :invalid_ipv4} = HostParser.parse_ip("999.999.999.999") end test "parse_port function" do diff --git a/test/snmpkit/snmpkit_test.exs b/test/snmpkit/snmpkit_test.exs index 7ffb6817..5b697ee3 100644 --- a/test/snmpkit/snmpkit_test.exs +++ b/test/snmpkit/snmpkit_test.exs @@ -6,5 +6,35 @@ defmodule SnmpKitTest do # Simple test to verify module loads test "module loads correctly" do assert is_atom(SnmpKit) + assert is_atom(SnmpKit.SNMP) + assert is_atom(SnmpKit.MIB) end + + describe "SnmpKit.SNMP bang methods" do + test "get_bulk!/2 raises on error" do + # Bang method should raise when underlying function returns error + assert_raise RuntimeError, ~r/get_bulk! failed/, fn -> + SnmpKit.SNMP.get_bulk!("192.0.2.1", "1.3.6.1.2.1.1") + end + end + + test "get_bulk!/3 raises on error with options" do + assert_raise RuntimeError, ~r/get_bulk! failed/, fn -> + SnmpKit.SNMP.get_bulk!("192.0.2.1", "1.3.6.1.2.1.1", timeout: 100) + end + end + + test "bulk_walk!/2 raises on error" do + assert_raise RuntimeError, ~r/bulk_walk! failed/, fn -> + SnmpKit.SNMP.bulk_walk!("192.0.2.1", "1.3.6.1.2.1.1") + end + end + + test "bulk_walk!/3 raises on error with options" do + assert_raise RuntimeError, ~r/bulk_walk! failed/, fn -> + SnmpKit.SNMP.bulk_walk!("192.0.2.1", "1.3.6.1.2.1.1", timeout: 100) + end + end + end + end