-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathtest_valkey.py
More file actions
79 lines (57 loc) · 2.48 KB
/
test_valkey.py
File metadata and controls
79 lines (57 loc) · 2.48 KB
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
75
76
77
78
79
import socket
from testcontainers.valkey import ValkeyContainer
def test_docker_run_valkey():
with ValkeyContainer() as valkey:
host = valkey.get_host()
port = valkey.get_exposed_port()
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host, port))
s.sendall(b"*1\r\n$4\r\nPING\r\n")
response = s.recv(1024)
assert b"+PONG" in response
def test_docker_run_valkey_with_password():
with ValkeyContainer().with_password("mypass") as valkey:
host = valkey.get_host()
port = valkey.get_exposed_port()
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host, port))
# Authenticate
s.sendall(b"*2\r\n$4\r\nAUTH\r\n$6\r\nmypass\r\n")
auth_response = s.recv(1024)
assert b"+OK" in auth_response
# Test SET command
s.sendall(b"*3\r\n$3\r\nSET\r\n$5\r\nhello\r\n$5\r\nworld\r\n")
set_response = s.recv(1024)
assert b"+OK" in set_response
# Test GET command
s.sendall(b"*2\r\n$3\r\nGET\r\n$5\r\nhello\r\n")
get_response = s.recv(1024)
assert b"world" in get_response
def test_get_connection_url():
with ValkeyContainer() as valkey:
url = valkey.get_connection_url()
assert url.startswith("valkey://")
assert str(valkey.get_exposed_port()) in url
def test_get_connection_url_with_password():
with ValkeyContainer().with_password("secret") as valkey:
url = valkey.get_connection_url()
assert url.startswith("valkey://:secret@")
assert str(valkey.get_exposed_port()) in url
def test_with_image_tag():
container = ValkeyContainer().with_image_tag("8.0")
assert "valkey/valkey:8.0" in container.image
def test_with_bundle():
container = ValkeyContainer().with_bundle()
assert container.image == "valkey/valkey-bundle:latest"
def test_with_bundle_and_tag():
container = ValkeyContainer().with_bundle().with_image_tag("9.0")
assert container.image == "valkey/valkey-bundle:9.0"
def test_bundle_starts():
with ValkeyContainer().with_bundle() as valkey:
host = valkey.get_host()
port = valkey.get_exposed_port()
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host, port))
s.sendall(b"*1\r\n$4\r\nPING\r\n")
response = s.recv(1024)
assert b"+PONG" in response