Skip to content

Commit 14ea6f9

Browse files
committed
Add software tests for covering parts of the "mqttwarn.commands" module
1 parent 7b707e5 commit 14ea6f9

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ you an idea how to pass relevant information on the command line using JSON::
174174
mqttwarn --plugin=ssh --config='{"host": "ssh.example.org", "port": 22, "user": "foo", "password": "bar"}' --options='{"addrs": ["command with substitution %s"], "payload": "{\"args\": \"192.168.0.1\"}"}'
175175

176176
# Launch "cloudflare_zone" service plugin from "mqttwarn-contrib", passing "--config" parameters via command line
177+
pip install mqttwarn-contrib
177178
mqttwarn --plugin=mqttwarn_contrib.services.cloudflare_zone --config='{"auth-email": "foo", "auth-key": "bar"}' --options='{"addrs": ["0815", "www.example.org", ""], "message": "192.168.0.1"}'
178179

179180

tests/test_commands.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
3+
4+
def test_command_dump_config(capfd):
5+
6+
command = "mqttwarn make-config"
7+
8+
os.system(command)
9+
stdout = capfd.readouterr().out
10+
11+
assert 'mqttwarn example configuration file "mqttwarn.ini"' in stdout, stdout
12+
13+
14+
def test_command_dump_samplefuncs(capfd):
15+
16+
command = "mqttwarn make-samplefuncs"
17+
18+
os.system(command)
19+
stdout = capfd.readouterr().out
20+
21+
assert '# mqttwarn example function extensions' in stdout, stdout
22+
23+
24+
def test_command_standalone_plugin(capfd):
25+
26+
command = """mqttwarn --plugin=log --options='{"message": "Hello world", "addrs": ["crit"]}'"""
27+
28+
os.system(command)
29+
stderr = capfd.readouterr().err
30+
31+
assert 'Successfully loaded service "log"' in stderr, stderr
32+
assert 'Hello world' in stderr, stderr
33+
assert 'Plugin response: True' in stderr, stderr

0 commit comments

Comments
 (0)