fix: test_dns_resolution tests mock socket not subprocess
The implementation uses socket.getaddrinfo; the tests were patching subprocess.run which had no effect, causing both tests to fail. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -199,29 +199,20 @@ test2 1800 IN CNAME test1
|
||||
self.assertFalse(status['running'])
|
||||
self.assertIn('stats', status)
|
||||
|
||||
@patch('subprocess.run')
|
||||
def test_test_dns_resolution(self, mock_run):
|
||||
@patch('socket.getaddrinfo')
|
||||
def test_test_dns_resolution(self, mock_getaddrinfo):
|
||||
"""Test DNS resolution testing"""
|
||||
# Mock successful DNS resolution
|
||||
mock_run.return_value.returncode = 0
|
||||
mock_run.return_value.stdout = 'test.cell -> 192.168.1.100'
|
||||
mock_run.return_value.stderr = ''
|
||||
|
||||
mock_getaddrinfo.return_value = [(None, None, None, None, ('192.168.1.100', 0))]
|
||||
result = self.network_manager.test_dns_resolution('test.cell')
|
||||
|
||||
self.assertTrue(result['success'])
|
||||
self.assertIn('192.168.1.100', result['output'])
|
||||
|
||||
@patch('subprocess.run')
|
||||
def test_test_dns_resolution_failure(self, mock_run):
|
||||
|
||||
@patch('socket.getaddrinfo')
|
||||
def test_test_dns_resolution_failure(self, mock_getaddrinfo):
|
||||
"""Test DNS resolution testing with failure"""
|
||||
# Mock failed DNS resolution
|
||||
mock_run.return_value.returncode = 1
|
||||
mock_run.return_value.stdout = ''
|
||||
mock_run.return_value.stderr = 'NXDOMAIN'
|
||||
|
||||
import socket
|
||||
mock_getaddrinfo.side_effect = socket.gaierror('NXDOMAIN')
|
||||
result = self.network_manager.test_dns_resolution('nonexistent.cell')
|
||||
|
||||
self.assertFalse(result['success'])
|
||||
self.assertIn('NXDOMAIN', result['error'])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user