Skip to content

Commit

Permalink
Add Simple test using the Python Zeroconf library.
Browse files Browse the repository at this point in the history
  • Loading branch information
willstott101 committed Dec 10, 2019
1 parent 4f953cd commit 8b4d495
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .github/workflows/zeroconf_test.yaml
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
target
Cargo.lock
__pycache__
*.pyc
2 changes: 1 addition & 1 deletion examples/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn main() {
let responder = libmdns::Responder::new().unwrap();
let _svc = responder.register(
"_http._tcp".to_owned(),
"Web Server".to_owned(),
"libmdns Web Server".to_owned(),
80,
&["path=/"],
);
Expand Down
31 changes: 31 additions & 0 deletions examples/zeroconf_test.py
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()

0 comments on commit 8b4d495

Please sign in to comment.