/
client_test.rb
85 lines (67 loc) · 1.85 KB
/
client_test.rb
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
80
81
82
83
84
85
# frozen_string_literal: true
require_relative "helper"
class TestClient < Minitest::Test
include Helper::Client
def test_call
result = r.call("PING")
assert_equal result, "PONG"
end
def test_call_with_arguments
result = r.call("SET", "foo", "bar")
assert_equal result, "OK"
end
def test_call_integers
result = r.call("INCR", "foo")
assert_equal result, 1
end
def test_call_raise
assert_raises(Redis::CommandError) do
r.call("INCR")
end
end
def test_queue_commit
r.queue("SET", "foo", "bar")
r.queue("GET", "foo")
result = r.commit
assert_equal result, ["OK", "bar"]
end
def test_commit_raise
r.queue("SET", "foo", "bar")
r.queue("INCR")
assert_raises(Redis::CommandError) do
r.commit
end
end
def test_queue_after_error
r.queue("SET", "foo", "bar")
r.queue("INCR")
assert_raises(Redis::CommandError) do
r.commit
end
r.queue("SET", "foo", "bar")
r.queue("INCR", "baz")
result = r.commit
assert_equal result, ["OK", 1]
end
def test_client_with_custom_connector
custom_connector = Class.new(Redis::Client::Connector) do
def resolve
@options[:host] = '127.0.0.5'
@options[:port] = '999'
@options
end
end
error = assert_raises do
new_redis = _new_client(connector: custom_connector)
new_redis.ping
end
assert_equal 'Error connecting to Redis on 127.0.0.5:999 (Errno::ECONNREFUSED)', error.message
end
def test_mixed_encoding
r.call("MSET", "fée", "\x00\xFF".b, "じ案".encode(Encoding::SHIFT_JIS), "\t".encode(Encoding::ASCII))
assert_equal "\x00\xFF".b, r.call("GET", "fée")
assert_equal "\t", r.call("GET", "じ案".encode(Encoding::SHIFT_JIS))
r.call("SET", "\x00\xFF", "fée")
assert_equal "fée", r.call("GET", "\x00\xFF".b)
end
end