| 1 |
def test_ip_match(judge_command): |
| 2 |
def ip_valid(ip, valid): |
| 3 |
if valid: |
| 4 |
judge_command( |
| 5 |
f"cluster meet {ip} 6379", |
| 6 |
{"command": "cluster meet", "ip": ip, "port": "6379"}, |
| 7 |
) |
| 8 |
else: |
| 9 |
judge_command(f"cluster meet {ip} 6379", None) |
| 10 |
|
| 11 |
ip_valid("192.168.0.1", True) |
| 12 |
ip_valid("255.255.255.255", True) |
| 13 |
ip_valid("192.168.0.256", False) |
| 14 |
ip_valid("192.256.0.26", False) |
| 15 |
ip_valid("192.255.256.26", False) |
| 16 |
ip_valid("0.0.0.0", True) |
| 17 |
ip_valid("99.999.100.1", False) |
| 18 |
ip_valid("300.168.0.1", False) |
| 19 |
|
| 20 |
|
| 21 |
def test_port_match(judge_command): |
| 22 |
def port_valid(port, valid): |
| 23 |
if valid: |
| 24 |
judge_command( |
| 25 |
f"cluster meet 192.168.0.1 {port}", |
| 26 |
{"command": "cluster meet", "ip": "192.168.0.1", "port": port}, |
| 27 |
) |
| 28 |
else: |
| 29 |
judge_command(f"cluster meet 192.168.0.1 {port}", None) |
| 30 |
|
| 31 |
port_valid("65535", True) |
| 32 |
port_valid("0", False) |
| 33 |
port_valid("1", True) |
| 34 |
port_valid("192.168.0.256", False) |
| 35 |
port_valid("65536", False) |
| 36 |
port_valid("65545", False) |
| 37 |
port_valid("65635", False) |
| 38 |
port_valid("66535", False) |
| 39 |
port_valid("75535", False) |
| 40 |
port_valid("1024", True) |
| 41 |
port_valid("6553", True) |
| 42 |
port_valid("99999", False) |
| 43 |
port_valid("99999999", False) |
| 44 |
|
| 45 |
|
| 46 |
def test_command_with_key_in_quotes(judge_command): |
| 47 |
judge_command( |
| 48 |
'cluster keyslot "mykey"', {"command": "cluster keyslot", "key": '"mykey"'} |
| 49 |
) |
| 50 |
judge_command( |
| 51 |
'cluster keyslot "\\"mykey"', |
| 52 |
{"command": "cluster keyslot", "key": '"\\"mykey"'}, |
| 53 |
) |
| 54 |
judge_command( |
| 55 |
'cluster keyslot "mykey "', {"command": "cluster keyslot", "key": '"mykey "'} |
| 56 |
) |
| 57 |
|
| 58 |
|
| 59 |
def test_timeout(token_should_match, token_should_not_match): |
| 60 |
from iredis.redis_grammar import TIMEOUT |
| 61 |
|
| 62 |
token_should_match(TIMEOUT, "1.1") |
| 63 |
token_should_match(TIMEOUT, "1.0") |
| 64 |
token_should_match(TIMEOUT, ".1") |
| 65 |
token_should_match(TIMEOUT, "123123.1123") |
| 66 |
token_should_not_match(TIMEOUT, "1.") |
| 67 |
token_should_not_match(TIMEOUT, ".") |
| 68 |
token_should_not_match(TIMEOUT, ".a") |
| 69 |
|
| 70 |
|
| 71 |
def test_lr_const(token_should_match, token_should_not_match): |
| 72 |
from iredis.redis_grammar import LR_CONST |
| 73 |
|
| 74 |
token_should_match(LR_CONST, "left") |
| 75 |
token_should_match(LR_CONST, "right") |
| 76 |
token_should_match(LR_CONST, "LEFT") |
| 77 |
token_should_match(LR_CONST, "RIGHT") |
| 78 |
token_should_not_match(LR_CONST, "righ") |
| 79 |
token_should_not_match(LR_CONST, "ab") |
| 80 |
token_should_not_match(LR_CONST, "123") |