@@ -118,6 +118,35 @@ def test_ip6_addresses_to_indexes():
118118 assert netutils .ip6_addresses_to_indexes (interfaces_2 ) == [(("2001:db8::" , 1 , 1 ), 1 )]
119119
120120
121+ @pytest .mark .parametrize ("interfaces" , [[], ["192.168.1.5" ], ["192.168.1.5" , "169.254.3.2" ]])
122+ def test_ip6_addresses_to_indexes_skips_scan_without_ipv6 (interfaces : list [str ]) -> None :
123+ """Test the adapters are not scanned when there are no IPv6 entries."""
124+ with patch ("zeroconf._utils.net.ifaddr.get_adapters" ) as mock_get_adapters :
125+ assert netutils .ip6_addresses_to_indexes (interfaces ) == []
126+ mock_get_adapters .assert_not_called ()
127+
128+
129+ def test_ip6_addresses_to_indexes_scans_once () -> None :
130+ """Test the adapters are scanned once for a mixed list."""
131+ with patch (
132+ "zeroconf._utils.net.ifaddr.get_adapters" ,
133+ return_value = _generate_mock_adapters (),
134+ ) as mock_get_adapters :
135+ assert netutils .ip6_addresses_to_indexes (["192.168.1.5" , "2001:db8::" , 1 , "fd00:db8::" ]) == [
136+ (("2001:db8::" , 1 , 1 ), 1 ),
137+ (("2001:db8::" , 1 , 1 ), 1 ),
138+ (("fd00:db8::" , 1 , 1 ), 1 ),
139+ ]
140+ mock_get_adapters .assert_called_once ()
141+
142+
143+ def test_normalize_interface_choice_ipv4_list_skips_scan () -> None :
144+ """Test an IPv4 only list is normalized without scanning the adapters."""
145+ with patch ("zeroconf._utils.net.ifaddr.get_adapters" ) as mock_get_adapters :
146+ assert netutils .normalize_interface_choice (["192.168.1.5" ]) == ["192.168.1.5" ]
147+ mock_get_adapters .assert_not_called ()
148+
149+
121150def test_normalize_interface_choice_errors ():
122151 """Test we generate exception on invalid input."""
123152 with (
0 commit comments