spec/lib/delivery/sidekiq_spec.rb in gitlab-mail_room-0.0.24 vs spec/lib/delivery/sidekiq_spec.rb in gitlab-mail_room-0.0.25
- old
+ new
@@ -4,21 +4,13 @@
describe MailRoom::Delivery::Sidekiq do
subject { described_class.new(options) }
let(:redis) { subject.send(:client) }
let(:raw_client) { redis._client }
let(:options) { MailRoom::Delivery::Sidekiq::Options.new(mailbox) }
- let(:redis5) { Gem::Version.new(Redis::VERSION) >= Gem::Version.new('5.0') }
- let(:server_url) do
- if redis5
- raw_client.config.server_url
- else
- raw_client.options[:url]
- end
- end
describe '#options' do
- let(:redis_url) { 'redis://localhost' }
+ let(:redis_url) { 'redis://localhost:6379' }
let(:redis_options) { { redis_url: redis_url } }
context 'when only redis_url is specified' do
let(:mailbox) {
build_mailbox(
@@ -26,14 +18,12 @@
delivery_options: redis_options
)
}
context 'with simple redis url' do
- let(:expected_url) { redis5 ? "#{redis_url}:6379/0" : redis_url }
-
it 'client has same specified redis_url' do
- expect(raw_client.server_url).to eq(expected_url)
+ expect(raw_client.config.server_url).to eq(redis_url)
end
it 'client is a instance of RedisNamespace class' do
expect(redis).to be_a ::Redis
end
@@ -43,23 +33,21 @@
expect(redis.connection[:db]).to eq(0)
end
end
context 'with redis_db specified in options' do
- let(:expected_url) { redis5 ? "#{redis_url}:6379/4" : redis_url }
-
before do
redis_options[:redis_db] = 4
end
it 'client has correct redis_url' do
- expect(raw_client.server_url).to eq(expected_url)
+ expect(raw_client.config.server_url).to eq("#{redis_url}/4")
end
it 'connection has correct values' do
- expect(redis.connection[:host]).to eq('localhost')
- expect(redis.connection[:db]).to eq(4)
+ expect(raw_client.config.host).to eq('localhost')
+ expect(raw_client.config.db).to eq(4)
end
end
end
context 'when namespace is specified' do
@@ -94,20 +82,42 @@
sentinels: sentinels
}
)
}
+ before { ::RedisClient::SentinelConfig.any_instance.stubs(:resolve_master).returns(RedisClient::Config.new(**sentinels.first)) }
+
it 'client has same specified sentinel params' do
- if redis5
+ expect(raw_client.config).to be_a RedisClient::SentinelConfig
+ expect(raw_client.config.host).to eq('10.0.0.1')
+ expect(raw_client.config.name).to eq('sentinel-master')
+ expect(raw_client.config.password).to eq('mypassword')
+ expect(raw_client.config.sentinels.map(&:server_url)).to eq(["redis://10.0.0.1:26379"])
+ end
+
+ context 'with separate Sentinel username and password' do
+ let(:sentinel_username) { 'my-sentinel-user' }
+ let(:sentinel_password) { 'my-sentinel-pass' }
+ let(:mailbox) {
+ build_mailbox(
+ delivery_method: :sidekiq,
+ delivery_options: {
+ redis_url: redis_url,
+ sentinels: sentinels,
+ sentinel_username: sentinel_username,
+ sentinel_password: sentinel_password
+ }
+ )
+ }
+
+ it 'client uses Sentinel username and password' do
+ expect(raw_client.config).to be_a RedisClient::SentinelConfig
expect(raw_client.config.password).to eq('mypassword')
- client_sentinels = raw_client.config.sentinels
- expect(client_sentinels.length).to eq(sentinels.length)
- expect(client_sentinels[0].host).to eq('10.0.0.1')
- expect(client_sentinels[0].port).to eq(26379) # rubocop:disable Style/NumericLiterals
- else
- expect(raw_client.options[:host]).to eq('sentinel-master')
- expect(raw_client.options[:password]).to eq('mypassword')
- expect(raw_client.options[:sentinels]).to eq(sentinels)
+
+ sentinels = raw_client.config.sentinels
+
+ expect(sentinels.map(&:username).uniq).to eq([sentinel_username])
+ expect(sentinels.map(&:password).uniq).to eq([sentinel_password])
end
end
end
end
end