More client tests.

pull/2345/head
Roger A. Light 4 years ago
parent 9b2c64135f
commit 74b9ed0808

@ -70,6 +70,8 @@ if __name__ == '__main__':
do_test(['-U'], "Error: -U argument given but no unsubscribe topic specified.\n\n" + helps, 1)
do_test(['-W'], "Error: -W argument given but no timeout specified.\n\n" + helps, 1)
do_test(['--will-payload', 'payload'], "Error: Will payload given, but no will topic given.\n" + helps, 1)
# No -t or -U
do_test([], "Error: You must specify a topic to subscribe to (-t) or unsubscribe from (-U).\n" + helps, 1)
# Invalid combinations
do_test(['-i', 'id', '-I', 'id-prefix'], "Error: -i and -I argument cannot be used together.\n\n" + helps, 1)

@ -0,0 +1,74 @@
#!/usr/bin/env python3
#
from mosq_test_helper import *
def write_config(filename, port, V):
with open(filename, 'w') as f:
f.write("-p %d\n" % (port))
f.write("-V %s\n" % (V))
f.write("-q 1\n")
f.write("-t 03/pub/qos1/test\n")
f.write("-m message\n")
def do_test(proto_ver):
rc = 1
port = mosq_test.get_port()
conf_file = os.path.basename(__file__).replace('.py', '.conf')
if proto_ver == 5:
V = 'mqttv5'
elif proto_ver == 4:
V = 'mqttv311'
else:
V = 'mqttv31'
env = {
'LD_LIBRARY_PATH':'../../lib',
'XDG_CONFIG_HOME':'/tmp/missing'
}
cmd = ['../../client/mosquitto_pub',
'-o', conf_file
]
write_config(conf_file, port, V)
mid = 1
publish_packet = mosq_test.gen_publish("03/pub/qos1/test", qos=1, mid=mid, payload="message", proto_ver=proto_ver)
if proto_ver == 5:
puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver, reason_code=mqtt5_rc.MQTT_RC_NO_MATCHING_SUBSCRIBERS)
else:
puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver)
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
try:
sock = mosq_test.sub_helper(port=port, topic="#", qos=1, proto_ver=proto_ver)
pub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env)
pub.wait()
(stdo, stde) = pub.communicate()
mosq_test.expect_packet(sock, "publish", publish_packet)
rc = 0
sock.close()
except mosq_test.TestError:
pass
except Exception as e:
print(e)
finally:
os.remove(conf_file)
broker.terminate()
broker.wait()
(stdo, stde) = broker.communicate()
if rc:
print(stde.decode('utf-8'))
print("proto_ver=%d" % (proto_ver))
exit(rc)
do_test(proto_ver=3)
do_test(proto_ver=4)
do_test(proto_ver=5)

@ -16,6 +16,7 @@ test : 02 03
03 :
./03-publish-argv-errors.py
./03-publish-options-file.py
./03-publish-qos0-empty.py
./03-publish-qos1-properties.py
./03-publish-qos1.py

@ -12,6 +12,7 @@ tests = [
(1, './02-subscribe-verbose.py'),
(1, './03-publish-argv-errors.py'),
(1, './03-publish-options-file.py'),
(1, './03-publish-qos0-empty.py'),
(1, './03-publish-qos1-properties.py'),
(1, './03-publish-qos1.py'),

Loading…
Cancel
Save