require 'helper' require 'oas/log_collector/manager' class TestManager < MiniTest::Unit::TestCase def setup OAS::LogCollector.options.merge!({ :source_logs_path => "/tmp", :files_to_copy => 90, :days_to_search => 10, :logs_path => "/tmp/logs" }) @result = ["adstream.log.223456789.bz2", "adstream.log.123456789.bz2", "adstream.log.323456789.bz2"] @manager = OAS::LogCollector::Manager.new @source = Minitest::Mock.new @source.expect :host, 'localhost' @source.expect :find, @result, ["/tmp", { :mtime => '-10', :type => 'f', :regex => '.*\.log\.[0-9]+\.bz2' }] OAS::LogCollector.redis = REDIS OAS::LogCollector.redis {|c| c.flushdb } end def test_set_last_run_to_the_last_downloaded_file @source.expect :copy, nil, [@result, "/tmp/logs"] @manager.collect(@source) @source.verify assert_equal "323456789", @manager.get_last_run('localhost') end def test_do_not_select_more_files_than_allowed @manager.set_last_run('localhost', '123456789') OAS::LogCollector.options.merge!({ :files_to_copy => 1, }) @source.expect :copy, nil, [["adstream.log.223456789.bz2"], "/tmp/logs"] @manager.collect(@source) @source.verify end def test_select_files_with_timestamp_greater_than_last_run @manager.set_last_run('localhost', '223456789') @source.expect :copy, nil, [["adstream.log.323456789.bz2"], "/tmp/logs"] @manager.collect(@source) @source.verify end end