+# -*- coding: utf-8 -*-
+import pytest
+
+from distbot.common.broker_nats import _sanitize_subject
+
+
+@pytest.mark.parametrize("subject,expected", [
+ # A quoted, multi-word plugin argument (e.g. choose "'multi word
+ # option'") shows up as a single shlex token containing spaces, which
+ # AMQP's topic exchange tolerates as an arbitrary routing key but NATS's
+ # whitespace-delimited wire protocol ("PUB <subject> <#bytes>") does
+ # not - an unsanitized space here corrupts the PUB frame and the
+ # message never reaches any subscriber (confirmed against a live
+ # nats-server).
+ ("nick.choose.will ich nicht", "nick.choose.will_ich_nicht"),
+ ("nick.choose.a\tb", "nick.choose.a_b"),
+ ("nick.dice.5", "nick.dice.5"),
+])
+def test_sanitize_subject_strips_whitespace(subject, expected):
+ assert _sanitize_subject(subject) == expected