Skip to content

Commit 2c07679

Browse files
committed
Add test to prove that sentinel works with authentication.
1 parent 438814b commit 2c07679

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/sentinel_test.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,42 @@ def test_sentinel_failover_prioritize_healthy_sentinel
109109
assert_equal commands[:s1], [%w[get-master-addr-by-name master1]]
110110
assert_equal commands[:s2], [%w[get-master-addr-by-name master1], %w[get-master-addr-by-name master1]]
111111
end
112+
113+
def test_sentinel_with_auth
114+
sentinels = [{:host => "127.0.0.1", :port => 26381}]
115+
116+
commands = {
117+
:s1 => [],
118+
:m1 => []
119+
}
120+
121+
sentinel = {
122+
:sentinel => lambda do |command, *args|
123+
commands[:s1] << [command, *args]
124+
["127.0.0.1", "6382"]
125+
end
126+
}
127+
128+
master = {
129+
:auth => lambda do |pass|
130+
commands[:m1] << ["auth", pass]
131+
"+OK"
132+
end,
133+
:role => lambda do
134+
commands[:m1] << ["role"]
135+
["master"]
136+
end
137+
}
138+
139+
RedisMock.start(master, {}, 6382) do
140+
RedisMock.start(sentinel, {}, 26381) do
141+
redis = Redis.new(:url => "redis://:foo@master1", :sentinels => sentinels, :role => :master)
142+
143+
assert redis.ping
144+
end
145+
end
146+
147+
assert_equal commands[:s1], [%w[get-master-addr-by-name master1]]
148+
assert_equal commands[:m1], [%w[auth foo], %w[role]]
149+
end
112150
end

0 commit comments

Comments
 (0)