summaryrefslogtreecommitdiffstats
path: root/tests/cli_tests/test_dsn.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 17:38:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 17:38:04 +0000
commite0847dd62461001851da4c89f279e16b14c3eb4c (patch)
tree87422376dd9a7eee55850f0fce9a8bb4c13e44a2 /tests/cli_tests/test_dsn.py
parentInitial commit. (diff)
downloadiredis-upstream.tar.xz
iredis-upstream.zip
Adding upstream version 1.13.0.upstream/1.13.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/cli_tests/test_dsn.py')
-rw-r--r--tests/cli_tests/test_dsn.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/cli_tests/test_dsn.py b/tests/cli_tests/test_dsn.py
new file mode 100644
index 0000000..8c9528d
--- /dev/null
+++ b/tests/cli_tests/test_dsn.py
@@ -0,0 +1,53 @@
+import os
+
+import pexpect
+from textwrap import dedent
+import pytest
+
+
+def test_using_dsn():
+ config_content = dedent(
+ """
+ [alias_dsn]
+ local = redis://localhost:6379/15
+ """
+ )
+ with open("/tmp/iredisrc", "w+") as etc_config:
+ etc_config.write(config_content)
+
+ cli = pexpect.spawn("iredis --iredisrc /tmp/iredisrc --dsn local", timeout=1)
+ cli.logfile_read = open("cli_test.log", "ab")
+ cli.expect(["iredis", "localhost:6379[15]>"])
+ cli.close()
+
+ # overwrite with -n
+ cli = pexpect.spawn("iredis --iredisrc /tmp/iredisrc --dsn local -n 3", timeout=1)
+ cli.logfile_read = open("cli_test.log", "ab")
+ cli.expect(["iredis", "localhost:6379[3]>"])
+ cli.close()
+
+ # dsn not exists
+ cli = pexpect.spawn("iredis --iredisrc /tmp/iredisrc --dsn ghost-dsn", timeout=1)
+ cli.expect(["Could not find the specified DSN in the config file."])
+ cli.close()
+ assert cli.status == 1
+
+
+@pytest.mark.skipif(
+ not os.path.exists("/tmp/redis/redis.sock"), reason="unix socket is not found"
+)
+def test_using_dsn_unix():
+ config_content = dedent(
+ """
+ [alias_dsn]
+ unix = unix:///tmp/redis/redis.sock?db=3
+ """
+ )
+ with open("/tmp/iredisrc", "w+") as etc_config:
+ etc_config.write(config_content)
+
+ cli = pexpect.spawn("iredis --iredisrc /tmp/iredisrc --dsn unix", timeout=2)
+ cli.logfile_read = open("cli_test.log", "ab")
+ cli.expect(["iredis", "redis /tmp/redis/redis.sock[3]>"])
+
+ cli.close()