Skip to content

Add test for scan_host with offline hosts #4

@m-marinucci

Description

@m-marinucci

As suggested in PR #1 by @sourcery-ai[bot]:

scan_host is not tested for the case where ping_host returns False (host is offline).

Task: Add a test for when ping_host returns False to verify scan_host handles offline hosts correctly.

Expected behavior:

  • 'alive' should be False
  • 'open_ports' should be empty list
  • 'services' should be empty dict

Example test:

def test_scan_host_offline(self):
    """Test scan_host with offline host."""
    with patch('src.lancompute.network_scanner.ping_host', return_value=False):
        result = scan_host("192.168.1.100", [80, 8080])
        
        assert result['ip'] == "192.168.1.100"
        assert result['alive'] is False
        assert result['open_ports'] == []
        assert result['services'] == {}

File: tests/test_network_scanner.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions