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
|
require_relative "spec_helper"
describe "server_logging extension" do
before do
@o = Object.new
def @o.logs; @logs || []; end
def @o.log; logs.length.must_equal 1; logs.first.length.must_equal 1; logs.shift.first; end
def @o.to_ary; [self]; end
def @o.method_missing(m, *args); (@logs ||= []) << args; end
@db = Sequel::mock(:test=>false, :servers=>{:read_only=>{}, :b=>{}}, :logger=>@o).extension(:server_logging)
end
it "should include shard when logging" do
@db[:a].all
@o.log.must_include "server: read_only) SELECT * FROM a"
@db[:a].insert
@o.log.must_include "server: default) INSERT INTO a DEFAULT VALUES"
@db[:a].server(:b).all
@o.log.must_include "server: b) SELECT * FROM a"
end
it "should not include shard when not logging connection info" do
@db.log_connection_info = false
@db[:a].all
log = @o.log
log.wont_include "server: read_only) SELECT * FROM a"
log.must_include "SELECT * FROM a"
end
it "should not turn on logging connction info if it was turned off" do
@db.log_connection_info = false
@db.extension :server_logging
@db[:a].all
log = @o.log
log.wont_include "server: read_only) SELECT * FROM a"
log.must_include "SELECT * FROM a"
end
it "should remove mapping when disconnecting" do
c = @db.synchronize{|c1| c1}
@db.disconnect
@db.send(:log_connection_execute, c, "SELECT * FROM a")
@o.log.must_include "server: ) SELECT * FROM a"
end
it "should not automatically enable logging connection info if explicitly disabled when extension is loaded" do
@db = Sequel::mock(:test=>false, :servers=>{:read_only=>{}, :b=>{}}, :logger=>@o)
@db.log_connection_info = false
@db.extension(:server_logging)
@db[:a].all
log = @o.log
log.wont_include "server: read_only) SELECT * FROM a"
log.must_include "SELECT * FROM a"
end
end
|