Commit 5d23278e authored by Boxiang Sun's avatar Boxiang Sun

test_networkbench: Mock the return value of dns.resolve.query

parent ce634067
...@@ -30,8 +30,18 @@ import os.path ...@@ -30,8 +30,18 @@ import os.path
from slapos.networkbench import dnsbench from slapos.networkbench import dnsbench
from slapos.networkbench.ping import ping, ping6 from slapos.networkbench.ping import ping, ping6
from slapos.networkbench.http import request from slapos.networkbench.http import request
import dns
import mock
class MockIPAddress:
def __init__(self, ip_text):
self.ip = ip_text
def to_text(self):
return self.ip
MOCK_IP_ADDRESS_LIST = [MockIPAddress('161.97.166.226'), MockIPAddress('176.31.129.213')]
DNS_EXPECTED_LIST = ["161.97.166.226", "176.31.129.213"] DNS_EXPECTED_LIST = ["161.97.166.226", "176.31.129.213"]
class TestDNSBench(unittest.TestCase): class TestDNSBench(unittest.TestCase):
...@@ -40,6 +50,9 @@ class TestDNSBench(unittest.TestCase): ...@@ -40,6 +50,9 @@ class TestDNSBench(unittest.TestCase):
""" """
Test dns resolution Test dns resolution
""" """
with mock.patch.object(dns.resolver, "query") as query:
query.return_value = MOCK_IP_ADDRESS_LIST
info = dnsbench.resolve( info = dnsbench.resolve(
"eu.web.vifib.com", DNS_EXPECTED_LIST) "eu.web.vifib.com", DNS_EXPECTED_LIST)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment