From 9d18f306c1766f799b3a4128c095dc666d90b78e Mon Sep 17 00:00:00 2001 From: Michael Lohrer Date: Tue, 2 Jan 2024 13:50:16 -0500 Subject: [PATCH] Update zeroconf test to display expected result --- tests/test_zeroconf.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/test_zeroconf.py b/tests/test_zeroconf.py index a616941ec..56af82040 100644 --- a/tests/test_zeroconf.py +++ b/tests/test_zeroconf.py @@ -7,10 +7,17 @@ def test_zeroconf(): """ Unit test for zeroconf advertisement """ + FAKE_PORT = 9898 - # get default network interface + # get network interface and MAC address that the service is expected to be advertised on iface = ni.gateways()['default'][ni.AF_INET][1] - FAKE_PORT = 9898 + try: + mac_addr = ni.ifaddresses(iface)[ni.AF_LINK][0]['addr'] + except: + mac_addr = 'none' + + AMPLIPI_ZC_NAME = f'amplipi-{mac_addr}._amplipi._tcp.local.' + print(f'Expecting that "{AMPLIPI_ZC_NAME}" is advertised to interface {iface}') services_advertised = {} @@ -34,14 +41,6 @@ def on_service_state_change(zeroconf: Zeroconf, service_type: str, name: str, st # wait enough time for a response from the service sleep(2) - # figure out what the name will be - try: - mac_addr = ni.ifaddresses(iface)[ni.AF_LINK][0]['addr'] - except: - mac_addr = 'none' - - AMPLIPI_ZC_NAME = f'amplipi-{mac_addr}._amplipi._tcp.local.' - # stop the advertiser event.set() zc_reg.join()