Skip to content

Commit

Permalink
(#257) Fix unit test for config.ru and location of logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ngiger committed Mar 14, 2024
1 parent 3916eba commit 8e0bfe6
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/test_util/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'minitest/autorun'
require 'flexmock/minitest'
require 'util/config'
require 'logger'

module ODDB
class TestConfig <Minitest::Test
Expand Down Expand Up @@ -72,13 +73,31 @@ def test_log_pattern
end
def test_log_pattern_default_app
eval("::APPNAME= nil")
args1 = {:shift_age=>0, :shift_size=>1048576, :shift_period_suffix=>"%Y%m%d", :binmode=>false}
args2 = {:shift_age=>"daily", :shift_size=>1048576, :shift_period_suffix=>"%Y%m%d", :binmode=>false}
flexmock(Logger::LogDevice) do
|klass|
klass.should_receive(:new).once.with(
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', "log/#{Date.today.year}/oddb.log")), args2)
klass.should_receive(:new).at_most.once.with(STDERR, args1) # may be called here or in test_log_pattern_with_appname
end
load @config_ru
assert(ODDB.config.log_pattern.index('log/%Y/%m/%d/oddb_log'))
assert_equal('oddb', SBSM.logger.progname)
end
def test_log_pattern_with_appname
eval("::APPNAME='crawler'")
args1 = {:shift_age=>0, :shift_size=>1048576, :shift_period_suffix=>"%Y%m%d", :binmode=>false}
args2 = {:shift_age=>"daily", :shift_size=>1048576, :shift_period_suffix=>"%Y%m%d", :binmode=>false}
flexmock(Logger::LogDevice) do
|klass|
klass.should_receive(:new).once.with(
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', "log/#{Date.today.year}/crawler.log")), args2)
klass.should_receive(:new).at_most.once.with(STDERR, args1) # may be called here or in test_log_pattern_default_app
end
load @config_ru
assert(ODDB.config.log_pattern.index('log/%Y/%m/%d/crawler_log'))
assert_equal('crawler', SBSM.logger.progname)
end
end
end


0 comments on commit 8e0bfe6

Please sign in to comment.