| 1 |
def test_auth(judge_command): |
| 2 |
judge_command("auth 123", {"command": "auth", "password": "123"}) |
| 3 |
|
| 4 |
|
| 5 |
def test_auth_redis6(judge_command): |
| 6 |
from iredis.commands import command2syntax |
| 7 |
from iredis.redis_grammar import get_command_grammar |
| 8 |
|
| 9 |
get_command_grammar.cache_clear() |
| 10 |
|
| 11 |
old = command2syntax["AUTH"] |
| 12 |
command2syntax["AUTH"] = "command_usernamex_password" |
| 13 |
judge_command( |
| 14 |
"auth default 123", |
| 15 |
{"command": "auth", "password": "123", "username": "default"}, |
| 16 |
) |
| 17 |
judge_command("AUTH 123", {"command": "AUTH", "password": "123"}) |
| 18 |
command2syntax["AUTH"] = old |
| 19 |
|
| 20 |
|
| 21 |
def test_echo(judge_command): |
| 22 |
judge_command("echo hello", {"command": "echo", "message": "hello"}) |
| 23 |
|
| 24 |
|
| 25 |
def test_ping(judge_command): |
| 26 |
judge_command("ping hello", {"command": "ping", "message": "hello"}) |
| 27 |
judge_command("ping", {"command": "ping", "message": None}) |
| 28 |
judge_command("ping hello world", None) |
| 29 |
|
| 30 |
|
| 31 |
def test_select(judge_command): |
| 32 |
for index in range(16): |
| 33 |
judge_command(f"select {index}", {"command": "select", "index": str(index)}) |
| 34 |
for index in range(16, 100): |
| 35 |
judge_command(f"select {index}", None) |
| 36 |
judge_command("select acb", None) |
| 37 |
|
| 38 |
|
| 39 |
def test_swapdb(judge_command): |
| 40 |
for index1 in range(16): |
| 41 |
for index2 in range(16): |
| 42 |
judge_command( |
| 43 |
f"swapdb {index1} {index2}", |
| 44 |
{"command": "swapdb", "index": [str(index1), str(index2)]}, |
| 45 |
) |
| 46 |
judge_command("swapdb abc 1", None) |
| 47 |
judge_command("swapdb 1", None) |
| 48 |
|
| 49 |
|
| 50 |
def test_client_no_evict_no_touch(judge_command): |
| 51 |
"""CLIENT NO-EVICT / CLIENT NO-TOUCH (since 7.0/7.2) accept ON|OFF (per commands.json).""" |
| 52 |
judge_command("CLIENT NO-EVICT ON", {"command": "CLIENT NO-EVICT", "on_off": "ON"}) |
| 53 |
judge_command( |
| 54 |
"CLIENT NO-EVICT OFF", {"command": "CLIENT NO-EVICT", "on_off": "OFF"} |
| 55 |
) |
| 56 |
judge_command("CLIENT NO-TOUCH ON", {"command": "CLIENT NO-TOUCH", "on_off": "ON"}) |
| 57 |
judge_command( |
| 58 |
"CLIENT NO-TOUCH off", {"command": "CLIENT NO-TOUCH", "on_off": "off"} |
| 59 |
) |
| 60 |
|
| 61 |
|
| 62 |
def test_client_caching(judge_command): |
| 63 |
judge_command("CLIENT CACHING YES", {"command": "CLIENT CACHING", "yes": "YES"}) |
| 64 |
judge_command("CLIENT CACHING NO", {"command": "CLIENT CACHING", "yes": "NO"}) |
| 65 |
judge_command("CLIENT CACHING", None) |
| 66 |
judge_command("CLIENT CACHING abc", None) |
| 67 |
|
| 68 |
|
| 69 |
def test_client_tracking(judge_command): |
| 70 |
judge_command("CLIENT TRACKING on", {"command": "CLIENT TRACKING", "on_off": "on"}) |
| 71 |
judge_command( |
| 72 |
"CLIENT TRACKING ON REDIRECT 123", |
| 73 |
{ |
| 74 |
"command": "CLIENT TRACKING", |
| 75 |
"on_off": "ON", |
| 76 |
"redirect_const": "REDIRECT", |
| 77 |
"clientid": "123", |
| 78 |
}, |
| 79 |
) |
| 80 |
judge_command( |
| 81 |
"CLIENT TRACKING ON PREFIX foo", |
| 82 |
{ |
| 83 |
"command": "CLIENT TRACKING", |
| 84 |
"on_off": "ON", |
| 85 |
"prefix_const": "PREFIX", |
| 86 |
"prefixes": "foo", |
| 87 |
}, |
| 88 |
) |
| 89 |
judge_command( |
| 90 |
"CLIENT TRACKING ON PREFIX foo", |
| 91 |
{ |
| 92 |
"command": "CLIENT TRACKING", |
| 93 |
"on_off": "ON", |
| 94 |
"prefix_const": "PREFIX", |
| 95 |
"prefixes": "foo", |
| 96 |
}, |
| 97 |
) |
| 98 |
judge_command( |
| 99 |
"CLIENT TRACKING ON PREFIX foo BCAST NOLOOP OPTIN", |
| 100 |
{ |
| 101 |
"command": "CLIENT TRACKING", |
| 102 |
"on_off": "ON", |
| 103 |
"prefix_const": "PREFIX", |
| 104 |
"prefixes": "foo", |
| 105 |
"bcast_const": "BCAST", |
| 106 |
"noloop_const": "NOLOOP", |
| 107 |
"optin_const": "OPTIN", |
| 108 |
}, |
| 109 |
) |
| 110 |
judge_command( |
| 111 |
"CLIENT TRACKING ON PREFIX foo bar ok BCAST NOLOOP OPTIN", |
| 112 |
{ |
| 113 |
"command": "CLIENT TRACKING", |
| 114 |
"on_off": "ON", |
| 115 |
"prefix_const": "PREFIX", |
| 116 |
"prefixes": "foo bar ok", |
| 117 |
"bcast_const": "BCAST", |
| 118 |
"noloop_const": "NOLOOP", |
| 119 |
"optin_const": "OPTIN", |
| 120 |
}, |
| 121 |
) |
| 122 |
|
| 123 |
|
| 124 |
def test_client_pause(judge_command): |
| 125 |
judge_command( |
| 126 |
"CLIENT PAUSE 20 WRITE", |
| 127 |
{"command": "CLIENT PAUSE", "timeout": "20", "pause_type": "WRITE"}, |
| 128 |
) |