require 'spec_helper' require 'mongo_request_logger/config' require 'mongo' include MongoRequestLogger describe MongoRequestLogger::Config do it "should namespace" do pending end it "should handle a simple case" do config = MongoRequestLogger::Config.new({ host: 'example.org', port: 1234, database: 'request_logger_test', collection: 'server_log', capsize: 10, }) config.hosts.should == ['example.org:1234'] config.moped_config.should == {database: 'request_logger_test'} end it "should default to localhost:27017" do config = MongoRequestLogger::Config.new({ database: 'request_logger_test', collection: 'server_log', capsize: 10, }) config.hosts.should == ['127.0.0.1:27017'] config.moped_config.should == {database: 'request_logger_test'} config.database.should == 'request_logger_test' config.collection.should == 'server_log' config.capsize.should == 10485760 end it "should configure with a host array" do config = MongoRequestLogger::Config.new({ hosts: [ 'node1.example.org:27017', 'node2.localhost:27017', ], database: 'request_logger_test', collection: 'server_log', capsize: 10, }) config.hosts.should == [ 'node1.example.org:27017', 'node2.localhost:27017', ] config.moped_config.should == {database: 'request_logger_test'} end it "should pass through options" do # This should work similarly for ssl: true. Unfortunately, we don't have a # ssl host to test against. config = MongoRequestLogger::Config.new({ consistency: 'strong', timeout: 30, ssl: true, database: 'request_logger_test', collection: 'server_log', capsize: 10, }) config.moped_config.should == { timeout: 30, ssl: true, consistency: :strong, database: 'request_logger_test' } end context "when configured with an URI" do it "should configure with a single host" do config = MongoRequestLogger::Config.new({ uri: 'mongodb://example.org:1234/request_logger_test', collection: 'server_log', capsize: 10 }) config.database.should == 'request_logger_test' config.collection.should == 'server_log' config.capsize.should == 10485760 config.hosts.should == ['example.org:1234'] config.moped_config.should == {database: 'request_logger_test'} end it "should configure with multiple hosts" do # We only have a single real host to connect to, so we add it multiple times config = MongoRequestLogger::Config.new({ uri: 'mongodb://node1.example.org:1234,node2.example.org:1234/request_logger_test', collection: 'server_log', capsize: 10 }) config.database.should == 'request_logger_test' config.collection.should == 'server_log' config.hosts.should == ['node1.example.org:1234', 'node2.example.org:1234'] config.moped_config.should == {database: 'request_logger_test'} end it "should configure with URI options" do config = MongoRequestLogger::Config.new({ uri: 'mongodb://example.org:1234/request_logger_test?consistency=strong&timeout=30&ssl=true', collection: 'server_log', capsize: 10 }) config.database.should == 'request_logger_test' config.collection.should == 'server_log' config.hosts.should == ['example.org:1234'] config.moped_config.should == { consistency: :strong, timeout: 30, ssl: true, database: 'request_logger_test' } end end end