Skip to content

Commit 4d5dfa4

Browse files
committed
chore(tests): add test for explicit question type flag
Add unit test to validate that the explicit question type flag is set correctly in outgoing requests.
1 parent 0d3dcff commit 4d5dfa4

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tests/services/test_info.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import zeroconf as r
1919
from zeroconf import DNSAddress, RecordUpdate, const
20+
from zeroconf._protocol.outgoing import DNSOutgoing
2021
from zeroconf._services import info
2122
from zeroconf._services.info import ServiceInfo
2223
from zeroconf._utils.net import IPVersion
@@ -1871,3 +1872,23 @@ async def test_address_resolver_ipv6():
18711872
aiozc.zeroconf.async_send(outgoing)
18721873
assert await resolve_task
18731874
assert resolver.ip_addresses_by_version(IPVersion.All) == [ip_address("fe80::52e:c2f2:bc5f:e9c6")]
1875+
1876+
1877+
@pytest.mark.asyncio
1878+
async def test_unicast_flag_if_requested() -> None:
1879+
"""Verify we try four times even with the random delay."""
1880+
type_ = "_typethatisnothere._tcp.local."
1881+
aiozc = AsyncZeroconf(interfaces=["127.0.0.1"])
1882+
1883+
def async_send(out: DNSOutgoing, addr: str | None = None, port: int = const._MDNS_PORT) -> None:
1884+
"""Sends an outgoing packet."""
1885+
for question in out.questions:
1886+
assert question.unicast
1887+
1888+
# patch the zeroconf send
1889+
with patch.object(aiozc.zeroconf, "async_send", async_send):
1890+
await aiozc.async_get_service_info(
1891+
f"willnotbefound.{type_}", type_, question_type=r.DNSQuestionType.QU
1892+
)
1893+
1894+
await aiozc.async_close()

0 commit comments

Comments
 (0)