"""Tests for expanding discovery targets.""" from neotalk.core.entities.responses import ResponseTypes from neotalk.core.use_cases.discovery.expand_targets import ( expand_discovery_targets_use_case, ) def test_empty_spec_gives_no_targets(): # When the spec is blank response = expand_discovery_targets_use_case(" ") # Then there are no targets assert response["type"] == ResponseTypes.SUCCESS assert response["data"]["targets"] == [] def test_single_ip(): # When a single IP is given response = expand_discovery_targets_use_case("10.0.200.151") # Then it is the only target assert response["data"]["targets"] == ["10.0.200.151"] def test_subnet_expands_to_hosts(): # When a small subnet is given response = expand_discovery_targets_use_case("192.168.0.0/30") # Then it expands to the usable hosts assert response["data"]["targets"] == ["192.168.0.1", "192.168.0.2"] def test_mixed_and_deduplicated(): # Given IPs and a subnet with an overlap, comma/space separated response = expand_discovery_targets_use_case("10.0.0.1, 192.168.0.0/30 192.168.0.1") # Then results are deduplicated, order preserved assert response["data"]["targets"] == [ "10.0.0.1", "192.168.0.1", "192.168.0.2", ] def test_invalid_address_is_rejected(): # When the spec has garbage response = expand_discovery_targets_use_case("not-an-ip") # Then it is a parameters error assert response["type"] == ResponseTypes.PARAMETERS_ERROR assert response["errors"][0]["field"] == "discover" def test_too_large_subnet_is_rejected(): # When the subnet exceeds the cap response = expand_discovery_targets_use_case("10.0.0.0/16") # Then it is rejected assert response["type"] == ResponseTypes.PARAMETERS_ERROR