forked from librespot-org/libmdns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Simple test using the Python Zeroconf library.
- Loading branch information
1 parent
4f953cd
commit 8b4d495
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Integration Test (Python zeroconf) | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: Compile example | ||
run: cargo build --example register | ||
|
||
- name: Install dependencies | ||
run: | | ||
sudo apt-get -y install python3-setuptools python3-wheel | ||
pip3 install --user zeroconf | ||
- name: Test zeroconf | ||
run: | | ||
timeout 5 cargo run --example register & | ||
python3 examples/zeroconf_test.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
target | ||
Cargo.lock | ||
__pycache__ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from zeroconf import ServiceBrowser, Zeroconf | ||
from time import sleep | ||
|
||
|
||
TYPE = "_http._tcp.local." | ||
NAME = "libmdns Web Server" | ||
|
||
|
||
class MyListener: | ||
def __init__(self): | ||
self.found = [] | ||
|
||
def has_found(self, name): | ||
return name in self.found | ||
|
||
def add_service(self, zeroconf, type, name): | ||
self.found.append(name.replace("." + TYPE, "")) | ||
|
||
|
||
zeroconf = Zeroconf() | ||
listener = MyListener() | ||
browser = ServiceBrowser(zeroconf, TYPE, listener) | ||
try: | ||
t = 0 | ||
while t < 5 and not listener.has_found(NAME): | ||
sleep(1) | ||
t += 1 | ||
assert listener.has_found(NAME) | ||
print('Success') | ||
finally: | ||
zeroconf.close() |