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
/
mongo_configurer_spec.rb
126 lines (116 loc) · 3.89 KB
/
mongo_configurer_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
File.join(File.dirname(__FILE__), '../../','spec_helper')
require 'mongo'
require 'cfautoconfig/document/mongodb_configurer'
describe 'AutoReconfiguration::Mongo' do
before(:each) do
ENV['VCAP_APPLICATION'] = '{"name":"test"}'
ENV['VCAP_SERVICES'] = '{"mongodb-1.8":[{"name": "mongo-1","label": "mongodb-1.8",' +
'"plan": "free", "credentials": {"hostname": "10.20.30.40","port": 12345, ' +
'"username": "8d93ae0a", "password": "7cf3c0e3","name": "m1", "db": "db"}}]}'
end
it 'auto-configures Mongo on initialize with host and port' do
mongo = Mongo::Connection.new('127.0.0.1', 27017, {:connect => false})
mongo.host_to_try.should == mongo.send(:format_pair, '10.20.30.40', 12345)
end
it 'auto-configures DB with CF authentication values on db call' do
module Mongo
module Support
def validate_db_name(db_name)
db_name.should == 'db'
db_name
end
end
class DB
def authenticate(username, password, save_auth=true)
username.should == '8d93ae0a'
password.should == '7cf3c0e3'
true
end
end
end
mongo = Mongo::Connection.new('127.0.0.1', 27017, {:connect => false})
db = mongo.db('test')
end
it 'auto-configures DB with CF authentication values on [] shortcut call' do
module Mongo
module Support
def validate_db_name(db_name)
db_name.should == 'db'
db_name
end
end
class DB
def authenticate(username, password, save_auth=true)
username.should == '8d93ae0a'
password.should == '7cf3c0e3'
true
end
end
end
mongo = Mongo::Connection.new('127.0.0.1', 27017, {:connect => false})
db = mongo['test']
end
it 'does not auto-configure DB on db call if db-name is admin' do
module Mongo
module Support
def validate_db_name(db_name)
db_name.should == 'admin'
db_name
end
end
class DB
def authenticate(username, password, save_auth=true)
raise(Mongo::AuthenticationError, "Authenticate should not have been called!")
end
end
end
mongo = Mongo::Connection.new('127.0.0.1', 27017, {:connect => false})
db = mongo.db('admin')
end
it 'does not auto-configure DB on [] shortcut call if db-name is admin' do
module Mongo
module Support
def validate_db_name(db_name)
db_name.should == 'admin'
db_name
end
end
class DB
def authenticate(username, password, save_auth=true)
raise(Mongo::AuthenticationError, "Authenticate should not have been called!")
end
end
end
mongo = Mongo::Connection.new('127.0.0.1', 27017, {:connect => false})
db = mongo['admin']
end
it 'does not auto-configure Mongo if VCAP_SERVICES not set' do
ENV['VCAP_SERVICES'] = nil
mongo = Mongo::Connection.new('127.0.0.1', 27017, {:connect => false})
mongo.host_to_try.should == mongo.send(:format_pair, '127.0.0.1', 27017)
end
it 'does not auto-configure DB if VCAP_SERVICES not set' do
ENV['VCAP_SERVICES'] = nil
module Mongo
module Support
def validate_db_name(db_name)
db_name.should == 'test'
db_name
end
end
class DB
def authenticate(username, password, save_auth=true)
raise(Mongo::AuthenticationError, "Authenticate should not have been called!")
end
end
end
mongo = Mongo::Connection.new('127.0.0.1', 27017, {:connect => false})
db = mongo.db('test')
end
it 'disables Mongo auto-reconfig if DISABLE_AUTO_CONFIG includes mongodb' do
ENV['DISABLE_AUTO_CONFIG'] = "redis:mongodb"
load 'cfautoconfig/document/mongodb_configurer.rb'
mongo = Mongo::Connection.new('127.0.0.1', 27017, {:connect => false})
mongo.host_to_try.should == mongo.send(:format_pair, '127.0.0.1', 27017)
end
end