This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
redis_spec.rb
73 lines (65 loc) · 2.83 KB
/
redis_spec.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
require File.join(File.dirname(__FILE__), 'spec_helper')
require 'cfruntime/redis'
describe 'CFRuntime::RedisClient' do
include CFRuntime::Test
it 'creates a client with a Redis service by type and no additional options' do
svcs = {
"redis-#{redis_version}"=>[create_redis_service('redis-test')]}
with_vcap_services(svcs) do
redis = CFRuntime::RedisClient.create
redis.client.host.should == SOME_SERVER
redis.client.port.should == SOME_SERVICE_PORT
redis.client.password.should_not == nil
end
end
it 'creates a client with a Redis service by type and additional options' do
svcs = {
"redis-#{redis_version}"=>[create_redis_service('redis-test')]}
with_vcap_services(svcs) do
redis = CFRuntime::RedisClient.create({:timeout=>1})
redis.client.host.should == SOME_SERVER
redis.client.port.should == SOME_SERVICE_PORT
redis.client.password.should_not == nil
redis.client.timeout.should == 1
end
end
it 'creates a client with a Redis service by name and no additional options' do
svcs = {
"redis-#{redis_version}"=>[create_redis_service('redis-test')]}
with_vcap_services(svcs) do
redis = CFRuntime::RedisClient.create_from_svc('redis-test')
redis.client.host.should == SOME_SERVER
redis.client.port.should == SOME_SERVICE_PORT
redis.client.password.should_not == nil
end
end
it 'creates a client with a Redis service by name and additional options' do
svcs = {
"redis-#{redis_version}"=>[create_redis_service('redis-test')]}
with_vcap_services(svcs) do
redis = CFRuntime::RedisClient.create_from_svc('redis-test',:timeout=>1)
redis.client.host.should == SOME_SERVER
redis.client.port.should == SOME_SERVICE_PORT
redis.client.password.should_not == nil
redis.client.timeout.should == 1
end
end
it 'raises an ArgumentError if no service of Redis type found' do
ENV['VCAP_SERVICES'] = nil
expect{CFRuntime::RedisClient.create}.to raise_error(ArgumentError,
'Expected 1 service of redis type, but found 0. Consider using create_from_svc(service_name) instead.')
end
it 'raises an ArgumentError if multiple services of Redis type found' do
svcs = {"redis-#{redis_version}"=>[create_redis_service('redis-test'),
create_redis_service('redis-test2')]}
with_vcap_services(svcs) do
expect{CFRuntime::RedisClient.create}.to raise_error(ArgumentError,
'Expected 1 service of redis type, but found 2. Consider using create_from_svc(service_name) instead.')
end
end
it 'raises an ArgumentError if Redis service of specified name is not found' do
ENV['VCAP_SERVICES'] = nil
expect{CFRuntime::RedisClient.create_from_svc('nonexistent-redis')}.to raise_error(ArgumentError,
'Service with name nonexistent-redis not found')
end
end