test: raise coverage 68.7% -> ~80.4%; add ~250 tests for new egress/DDNS/network paths
Unit Tests / test (push) Successful in 12m6s
Unit Tests / test (push) Successful in 12m6s
Coverage was below acceptable levels and several newly-added code paths (sshuttle egress, proxy egress, DDNS provider stubs, DNS overview route, peer-registry provisioning) had zero test coverage. ~250 new unit tests are added across 16 new test files. Existing test files are updated to match refactored interfaces (DHCP removed, constants introduced, network_manager restructured). .coveragerc is added to pin the source mapping and the 70% floor so regressions are caught at commit time. tests/test_enhanced_api.py was previously living in api/ (wrong location) and is moved to tests/ where it belongs. Integration test files are updated to remove references to DHCP endpoints and add coverage for the new DNS overview and DDNS sync endpoints. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -46,8 +46,7 @@ class TestNetworkManager(unittest.TestCase):
|
||||
self.assertEqual(self.network_manager.data_dir, self.data_dir)
|
||||
self.assertEqual(self.network_manager.config_dir, self.config_dir)
|
||||
self.assertTrue(os.path.exists(self.network_manager.dns_zones_dir))
|
||||
self.assertTrue(os.path.exists(os.path.dirname(self.network_manager.dhcp_leases_file)))
|
||||
|
||||
|
||||
def test_generate_zone_content(self):
|
||||
"""Test DNS zone content generation"""
|
||||
records = [
|
||||
@@ -124,57 +123,6 @@ test2 1800 IN CNAME test1
|
||||
self.assertEqual(records[1]['name'], 'test2')
|
||||
self.assertEqual(records[1]['type'], 'CNAME')
|
||||
|
||||
def test_get_dhcp_leases(self):
|
||||
"""Test getting DHCP leases"""
|
||||
# Create a test leases file
|
||||
leases_file = self.network_manager.dhcp_leases_file
|
||||
content = """1234567890 aa:bb:cc:dd:ee:ff 192.168.1.100 testhost *
|
||||
1234567891 11:22:33:44:55:66 192.168.1.101 anotherhost *
|
||||
"""
|
||||
|
||||
with open(leases_file, 'w') as f:
|
||||
f.write(content)
|
||||
|
||||
leases = self.network_manager.get_dhcp_leases()
|
||||
|
||||
self.assertEqual(len(leases), 2)
|
||||
self.assertEqual(leases[0]['mac'], 'aa:bb:cc:dd:ee:ff')
|
||||
self.assertEqual(leases[0]['ip'], '192.168.1.100')
|
||||
self.assertEqual(leases[0]['hostname'], 'testhost')
|
||||
self.assertEqual(leases[1]['mac'], '11:22:33:44:55:66')
|
||||
self.assertEqual(leases[1]['ip'], '192.168.1.101')
|
||||
|
||||
def test_add_dhcp_reservation(self):
|
||||
"""Test adding DHCP reservation"""
|
||||
success = self.network_manager.add_dhcp_reservation('aa:bb:cc:dd:ee:ff', '192.168.1.100', 'testhost')
|
||||
self.assertTrue(success)
|
||||
|
||||
# Check if reservation file was created
|
||||
reservation_file = os.path.join(self.config_dir, 'dhcp', 'reservations.conf')
|
||||
self.assertTrue(os.path.exists(reservation_file))
|
||||
|
||||
# Check content
|
||||
with open(reservation_file, 'r') as f:
|
||||
content = f.read()
|
||||
self.assertIn('aa:bb:cc:dd:ee:ff', content)
|
||||
self.assertIn('192.168.1.100', content)
|
||||
self.assertIn('testhost', content)
|
||||
|
||||
def test_remove_dhcp_reservation(self):
|
||||
"""Test removing DHCP reservation"""
|
||||
# Add a reservation first
|
||||
self.network_manager.add_dhcp_reservation('aa:bb:cc:dd:ee:ff', '192.168.1.100', 'testhost')
|
||||
|
||||
# Remove it
|
||||
success = self.network_manager.remove_dhcp_reservation('aa:bb:cc:dd:ee:ff')
|
||||
self.assertTrue(success)
|
||||
|
||||
# Check if reservation was removed
|
||||
reservation_file = os.path.join(self.config_dir, 'dhcp', 'reservations.conf')
|
||||
with open(reservation_file, 'r') as f:
|
||||
content = f.read()
|
||||
self.assertNotIn('aa:bb:cc:dd:ee:ff', content)
|
||||
|
||||
@patch('subprocess.run')
|
||||
def test_get_ntp_status(self, mock_run):
|
||||
"""Test getting NTP status"""
|
||||
@@ -216,19 +164,6 @@ test2 1800 IN CNAME test1
|
||||
self.assertFalse(result['success'])
|
||||
self.assertIn('NXDOMAIN', result['error'])
|
||||
|
||||
@patch('subprocess.run')
|
||||
def test_test_dhcp_functionality(self, mock_run):
|
||||
"""Test DHCP functionality testing"""
|
||||
# Mock DHCP service running
|
||||
mock_run.return_value.stdout = 'cell-dhcp\n'
|
||||
mock_run.return_value.returncode = 0
|
||||
|
||||
result = self.network_manager.test_dhcp_functionality()
|
||||
|
||||
self.assertTrue(result['running'])
|
||||
self.assertIn('leases_count', result)
|
||||
self.assertIn('leases', result)
|
||||
|
||||
@patch('subprocess.run')
|
||||
def test_test_ntp_functionality(self, mock_run):
|
||||
"""Test NTP functionality testing"""
|
||||
|
||||
Reference in New Issue
Block a user