summaryrefslogtreecommitdiffstats
path: root/tests/cli_tests/test_command_input.py
blob: f70ee3ce2302cf60a5ab6d4a9e15b021694ced9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import pytest


def test_wrong_select_db_index(cli):
    cli.sendline("select 1")
    cli.expect(["OK", "127.0.0.1"])

    cli.sendline("select 128")
    cli.expect(["DB index is out of range", "127.0.0.1:6379[1]>"])

    if int(os.environ["REDIS_VERSION"]) > 5:
        text = "value is not an integer or out of range"
    else:
        text = "invalid DB index"

    cli.sendline("select abc")
    cli.expect([text, "127.0.0.1:6379[1]>"])

    cli.sendline("select 15")
    cli.expect("OK")


def test_set_command_with_shash(clean_redis, cli):
    cli.sendline("set a \\hello\\")  # legal redis command
    cli.expect("OK")

    cli.sendline("get a")
    cli.expect(r"hello")


def test_enter_key_binding(clean_redis, cli):
    cli.send("set")
    cli.expect("set")
    cli.send("\033[B")  # down
    cli.sendline()  # enter

    cli.sendline(" a 'hello'")
    cli.expect("OK")

    cli.sendline("get a")
    cli.expect(r"hello")


@pytest.mark.skipif("int(os.environ['REDIS_VERSION']) < 6")
def test_auth_hidden_password_with_username(clean_redis, cli):
    cli.send("auth  default hello-world")
    cli.expect("default")
    cli.expect(r"\*{11}")


@pytest.mark.skipif("int(os.environ['REDIS_VERSION']) > 5")
def test_auth_hidden_password(clean_redis, cli):
    cli.send("auth hello-world")
    cli.expect("auth")
    cli.expect(r"\*{11}")


def test_hello_command_is_not_supported(cli):
    cli.sendline("hello 3")
    cli.expect("IRedis currently not support RESP3")


def test_abort_reading_connection(cli):
    cli.sendline("blpop mylist 30")
    cli.send(chr(3))
    cli.expect(
        r"KeyboardInterrupt received! User canceled reading response!", timeout=10
    )

    cli.sendline("set foo bar")
    cli.expect("OK")
    cli.sendline("get foo")
    cli.expect("bar")